From a99f6f51a959717a124d7fe61beab43b146518bb Mon Sep 17 00:00:00 2001 From: Andy Street Date: Thu, 9 Feb 2017 11:29:02 -0800 Subject: [PATCH] Add GuardedRunnable in more places Summary: Depends on D4537287 Use new GuardedRunnable abstraction Reviewed By: achen1 Differential Revision: D4537370 fbshipit-source-id: ad56eaa23c21624008d8ed48837a2d1020cfd2d9 --- .../react/modules/statusbar/StatusBarModule.java | 9 +++++---- .../com/facebook/react/uimanager/UIManagerModule.java | 10 ++++++---- .../facebook/react/views/modal/ReactModalHostView.java | 8 +++++--- 3 files changed, 16 insertions(+), 11 deletions(-) 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); }