From 6a96a9f65546cbe7e5c57a6005f6fa9b15f72b94 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sat, 16 May 2020 01:03:32 -0700 Subject: [PATCH] Use MC to Start Fabric surfaces using layoutMetrics or not Summary: This diff uses a new MC to Start Fabric surfaces using layoutMetrics or not. The motivation is to verify if the new initialization of fabric surfaces is regressing in production changelog: [Internal] Internal change in fabric Reviewed By: JoshuaGross Differential Revision: D21606971 fbshipit-source-id: ed1f6937ffd0f1e6c54e3ebc34595d75b6c5f6e1 --- .../facebook/react/ReactInstanceManager.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 83a0750f464..63ac2ec11df 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -1152,18 +1152,30 @@ public class ReactInstanceManager { final int rootTag; - if (reactRoot.getUIManagerType() == FABRIC) { - rootTag = - uiManager.startSurface( - reactRoot.getRootViewGroup(), - reactRoot.getJSModuleName(), - initialProperties == null - ? new WritableNativeMap() - : Arguments.fromBundle(initialProperties), - reactRoot.getWidthMeasureSpec(), - reactRoot.getHeightMeasureSpec()); - reactRoot.setRootViewTag(rootTag); - reactRoot.setShouldLogContentAppeared(true); + if (ReactFeatureFlags.enableFabricStartSurfaceWithLayoutMetrics) { + if (reactRoot.getUIManagerType() == FABRIC) { + rootTag = + uiManager.startSurface( + reactRoot.getRootViewGroup(), + reactRoot.getJSModuleName(), + initialProperties == null + ? new WritableNativeMap() + : Arguments.fromBundle(initialProperties), + reactRoot.getWidthMeasureSpec(), + reactRoot.getHeightMeasureSpec()); + reactRoot.setRootViewTag(rootTag); + reactRoot.setShouldLogContentAppeared(true); + } else { + rootTag = + uiManager.addRootView( + reactRoot.getRootViewGroup(), + initialProperties == null + ? new WritableNativeMap() + : Arguments.fromBundle(initialProperties), + reactRoot.getInitialUITemplate()); + reactRoot.setRootViewTag(rootTag); + reactRoot.runApplication(); + } } else { rootTag = uiManager.addRootView( @@ -1173,8 +1185,17 @@ public class ReactInstanceManager { : Arguments.fromBundle(initialProperties), reactRoot.getInitialUITemplate()); reactRoot.setRootViewTag(rootTag); - reactRoot.runApplication(); + if (reactRoot.getUIManagerType() == FABRIC) { + // Fabric requires to call updateRootLayoutSpecs before starting JS Application, + // this ensures the root will hace the correct pointScaleFactor. + uiManager.updateRootLayoutSpecs( + rootTag, reactRoot.getWidthMeasureSpec(), reactRoot.getHeightMeasureSpec()); + reactRoot.setShouldLogContentAppeared(true); + } else { + reactRoot.runApplication(); + } } + Systrace.beginAsyncSection( TRACE_TAG_REACT_JAVA_BRIDGE, "pre_rootView.onAttachedToReactInstance", rootTag); UiThreadUtil.runOnUiThread(