Skip to content

Commit 8b5e3fc

Browse files
mdvaccafacebook-github-bot
authored andcommitted
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
1 parent 575f7d4 commit 8b5e3fc

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,10 @@ private void updateRootLayoutSpecs(final int widthMeasureSpec, final int heightM
408408
return;
409409
}
410410
final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext();
411+
411412
if (reactApplicationContext != null) {
412-
reactApplicationContext.runOnNativeModulesQueueThread(
413-
new GuardedRunnable(reactApplicationContext) {
414-
@Override
415-
public void runGuarded() {
416-
UIManagerHelper
417-
.getUIManager(reactApplicationContext, getUIManagerType())
418-
.updateRootLayoutSpecs(getRootViewTag(), widthMeasureSpec, heightMeasureSpec);
419-
}
420-
});
413+
UIManagerHelper.getUIManager(reactApplicationContext, getUIManagerType())
414+
.updateRootLayoutSpecs(getRootViewTag(), widthMeasureSpec, heightMeasureSpec);
421415
}
422416
}
423417

ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,21 @@ public void onSizeChanged(final int width, final int height, int oldW, int oldH)
512512

513513
@Override
514514
@DoNotStrip
515-
public synchronized void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) {
516-
ReactShadowNode rootNode = getRootNode(rootViewTag);
517-
if (rootNode == null) {
518-
FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag);
519-
return;
520-
}
521-
522-
ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle());
523-
updateRootView(newRootNode, widthMeasureSpec, heightMeasureSpec);
524-
mRootShadowNodeRegistry.replaceNode(newRootNode);
515+
public synchronized void updateRootLayoutSpecs(final int rootViewTag, final int widthMeasureSpec, final int heightMeasureSpec) {
516+
mReactApplicationContext.runOnNativeModulesQueueThread(new Runnable() {
517+
@Override
518+
public void run() {
519+
ReactShadowNode rootNode = getRootNode(rootViewTag);
520+
if (rootNode == null) {
521+
FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag);
522+
return;
523+
}
524+
525+
ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle());
526+
updateRootView(newRootNode, widthMeasureSpec, heightMeasureSpec);
527+
mRootShadowNodeRegistry.replaceNode(newRootNode);
528+
}
529+
});
525530
}
526531

527532
/**

ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java

+7
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ public static float toDIPFromPixel(float value) {
5555
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density;
5656
}
5757

58+
/**
59+
* @return {@link float} that represents the density of the display metrics for device screen.
60+
*/
61+
public static float getDisplayMetricDensity() {
62+
return DisplayMetricsHolder.getScreenDisplayMetrics().density;
63+
}
64+
5865
}

ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,15 @@ public void invalidateNodeLayout(int tag) {
784784
* Updates the styles of the {@link ReactShadowNode} based on the Measure specs received by
785785
* parameters.
786786
*/
787-
public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) {
788-
mUIImplementation.updateRootView(rootViewTag, widthMeasureSpec, heightMeasureSpec);
789-
mUIImplementation.dispatchViewUpdates(-1);
787+
public void updateRootLayoutSpecs(final int rootViewTag, final int widthMeasureSpec, final int heightMeasureSpec) {
788+
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
789+
reactApplicationContext.runOnNativeModulesQueueThread(
790+
new GuardedRunnable(reactApplicationContext) {
791+
@Override
792+
public void runGuarded() {
793+
mUIImplementation.updateRootView(rootViewTag, widthMeasureSpec, heightMeasureSpec);
794+
mUIImplementation.dispatchViewUpdates(-1);
795+
}});
790796
}
791797

792798
/** Listener that drops the CSSNode pool on low memory when the app is backgrounded. */

0 commit comments

Comments
 (0)