diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 13ed88113ae..a07720cf884 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -408,16 +408,10 @@ public class ReactRootView extends SizeMonitoringFrameLayout return; } final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext(); + if (reactApplicationContext != null) { - reactApplicationContext.runOnNativeModulesQueueThread( - new GuardedRunnable(reactApplicationContext) { - @Override - public void runGuarded() { - UIManagerHelper - .getUIManager(reactApplicationContext, getUIManagerType()) - .updateRootLayoutSpecs(getRootViewTag(), widthMeasureSpec, heightMeasureSpec); - } - }); + UIManagerHelper.getUIManager(reactApplicationContext, getUIManagerType()) + .updateRootLayoutSpecs(getRootViewTag(), widthMeasureSpec, heightMeasureSpec); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 76c2ea8aa7c..2be6b50bf4e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -512,16 +512,21 @@ public class FabricUIManager implements UIManager, JSHandler, FabricBinder { @Override @DoNotStrip - public synchronized void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) { - ReactShadowNode rootNode = getRootNode(rootViewTag); - if (rootNode == null) { - FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag); - return; - } + public synchronized void updateRootLayoutSpecs(final int rootViewTag, final int widthMeasureSpec, final int heightMeasureSpec) { + mReactApplicationContext.runOnNativeModulesQueueThread(new Runnable() { + @Override + public void run() { + ReactShadowNode rootNode = getRootNode(rootViewTag); + if (rootNode == null) { + FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag); + return; + } - ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle()); - updateRootView(newRootNode, widthMeasureSpec, heightMeasureSpec); - mRootShadowNodeRegistry.replaceNode(newRootNode); + ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle()); + updateRootView(newRootNode, widthMeasureSpec, heightMeasureSpec); + mRootShadowNodeRegistry.replaceNode(newRootNode); + } + }); } /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java index 4f69c62e500..b8e4b093885 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java @@ -55,4 +55,11 @@ public class PixelUtil { return value / DisplayMetricsHolder.getWindowDisplayMetrics().density; } + /** + * @return {@link float} that represents the density of the display metrics for device screen. + */ + public static float getDisplayMetricDensity() { + return DisplayMetricsHolder.getScreenDisplayMetrics().density; + } + } 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 43befc9bad1..f20d8db1d03 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -784,9 +784,15 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements * Updates the styles of the {@link ReactShadowNode} based on the Measure specs received by * parameters. */ - public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) { - mUIImplementation.updateRootView(rootViewTag, widthMeasureSpec, heightMeasureSpec); - mUIImplementation.dispatchViewUpdates(-1); + public void updateRootLayoutSpecs(final int rootViewTag, final int widthMeasureSpec, final int heightMeasureSpec) { + ReactApplicationContext reactApplicationContext = getReactApplicationContext(); + reactApplicationContext.runOnNativeModulesQueueThread( + new GuardedRunnable(reactApplicationContext) { + @Override + public void runGuarded() { + mUIImplementation.updateRootView(rootViewTag, widthMeasureSpec, heightMeasureSpec); + mUIImplementation.dispatchViewUpdates(-1); + }}); } /** Listener that drops the CSSNode pool on low memory when the app is backgrounded. */