mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add UI thread assertions and annotations to ReactRootView
Summary: Add UI thread assertions and annotations to ReactRootView. Shouldn't have any immediate effect since these methods already call other methods that assert they're on the UI thread. Doing this to hoist assumptions higher up. Doing some very simple refactoring to the way cleanup happens to ensure aggressive cleanup in more instances. Reviewed By: shergin Differential Revision: D17860291 fbshipit-source-id: c87e0336594fa2327271b648eb8340e250235250
This commit is contained in:
committed by
Facebook Github Bot
parent
a494227d6c
commit
c82e27030c
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
package com.facebook.react;
|
||||
|
||||
import static com.facebook.infer.annotation.ThreadConfined.UI;
|
||||
import static com.facebook.react.uimanager.common.UIManagerType.DEFAULT;
|
||||
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
@@ -28,6 +29,7 @@ import android.widget.FrameLayout;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.infer.annotation.ThreadConfined;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
@@ -369,6 +371,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
* context of that manager. Extra parameter {@param launchOptions} can be used to pass initial
|
||||
* properties for the react component.
|
||||
*/
|
||||
@ThreadConfined(UI)
|
||||
public void startReactApplication(
|
||||
ReactInstanceManager reactInstanceManager,
|
||||
String moduleName,
|
||||
@@ -439,12 +442,15 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
* ReactRootView is garbage collected (typically in your Activity's onDestroy, or in your
|
||||
* Fragment's onDestroyView).
|
||||
*/
|
||||
@ThreadConfined(UI)
|
||||
public void unmountReactApplication() {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
if (mReactInstanceManager != null && mIsAttachedToInstance) {
|
||||
mReactInstanceManager.detachRootView(this);
|
||||
mReactInstanceManager = null;
|
||||
mIsAttachedToInstance = false;
|
||||
}
|
||||
mReactInstanceManager = null;
|
||||
mShouldLogContentAppeared = false;
|
||||
}
|
||||
|
||||
@@ -489,6 +495,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
return mInitialUITemplate;
|
||||
}
|
||||
|
||||
@ThreadConfined(UI)
|
||||
public void setAppProperties(@Nullable Bundle appProperties) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
mAppProperties = appProperties;
|
||||
@@ -559,11 +566,12 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
|
||||
private void attachToReactInstanceManager() {
|
||||
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager");
|
||||
try {
|
||||
if (mIsAttachedToInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsAttachedToInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mIsAttachedToInstance = true;
|
||||
Assertions.assertNotNull(mReactInstanceManager).attachRootView(this);
|
||||
getViewTreeObserver().addOnGlobalLayoutListener(getCustomGlobalLayoutListener());
|
||||
|
||||
Reference in New Issue
Block a user