From 8b5e3fc16b1e58441318b6ada629dcff572dd120 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 28 Aug 2018 22:49:26 -0700 Subject: [PATCH] Update size of Root ShadowNode when RootView changes its size Summary: This diff updates the size of RootShadowNode and re-render RN views when the Size of the Android React View changes Reviewed By: achen1 Differential Revision: D9173758 fbshipit-source-id: 7cc6bbfb646025c3ec1773ab041eb9207623af71 --- .../com/facebook/react/ReactRootView.java | 12 +++------- .../react/fabric/FabricUIManager.java | 23 +++++++++++-------- .../facebook/react/uimanager/PixelUtil.java | 7 ++++++ .../react/uimanager/UIManagerModule.java | 12 +++++++--- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 13ed88113..a07720cf8 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 76c2ea8aa..2be6b50bf 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 4f69c62e5..b8e4b0938 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 43befc9ba..f20d8db1d 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. */