diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java index 70b60be3b..0c3ebef19 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java @@ -21,6 +21,7 @@ import android.view.WindowInsets; import android.view.WindowManager; import com.facebook.common.logging.FLog; +import com.facebook.react.bridge.GuardedRunnable; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; @@ -75,10 +76,10 @@ public class StatusBarModule extends ReactContextBaseJavaModule { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UiThreadUtil.runOnUiThread( - new Runnable() { + new GuardedRunnable(getReactApplicationContext()) { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override - public void run() { + public void runGuarded() { if (animated) { int curColor = activity.getWindow().getStatusBarColor(); ValueAnimator colorAnimation = ValueAnimator.ofObject( @@ -112,10 +113,10 @@ public class StatusBarModule extends ReactContextBaseJavaModule { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UiThreadUtil.runOnUiThread( - new Runnable() { + new GuardedRunnable(getReactApplicationContext()) { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override - public void run() { + public void runGuarded() { // If the status bar is translucent hook into the window insets calculations // and consume all the top insets so no padding will be added under the status bar. View decorView = activity.getWindow().getDecorView(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index cd004430e..ffccabcc6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -21,6 +21,7 @@ import android.content.res.Configuration; import com.facebook.common.logging.FLog; import com.facebook.react.animation.Animation; import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.GuardedRunnable; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.NativeModuleLogger; import com.facebook.react.bridge.OnBatchCompleteListener; @@ -202,8 +203,9 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements height = rootView.getHeight(); } + final ReactApplicationContext reactApplicationContext = getReactApplicationContext(); final ThemedReactContext themedRootContext = - new ThemedReactContext(getReactApplicationContext(), rootView.getContext()); + new ThemedReactContext(reactApplicationContext, rootView.getContext()); mUIImplementation.registerRootView(rootView, tag, width, height, themedRootContext); @@ -211,10 +213,10 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements new SizeMonitoringFrameLayout.OnSizeChangedListener() { @Override public void onSizeChanged(final int width, final int height, int oldW, int oldH) { - getReactApplicationContext().runOnNativeModulesQueueThread( - new Runnable() { + reactApplicationContext.runOnNativeModulesQueueThread( + new GuardedRunnable(reactApplicationContext) { @Override - public void run() { + public void runGuarded() { updateNodeSize(tag, width, height); } }); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index 98ad5e0d6..50a00923b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -27,6 +27,7 @@ import android.widget.FrameLayout; import com.facebook.infer.annotation.Assertions; import com.facebook.react.R; +import com.facebook.react.bridge.GuardedRunnable; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactContext; import com.facebook.react.common.annotations.VisibleForTesting; @@ -303,10 +304,11 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (getChildCount() > 0) { - ((ReactContext) getContext()).runOnNativeModulesQueueThread( - new Runnable() { + ReactContext reactContext = (ReactContext) getContext(); + reactContext.runOnNativeModulesQueueThread( + new GuardedRunnable(reactContext) { @Override - public void run() { + public void runGuarded() { ((ReactContext) getContext()).getNativeModule(UIManagerModule.class) .updateNodeSize(getChildAt(0).getId(), w, h); }