From bc06d1cc9c8683115a85207c7f461c5ff82b5ef1 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 28 Feb 2019 17:21:59 -0800 Subject: [PATCH] Use a surface switch Summary: Flesh out how surface will be used with a flag in ReactRootView Reviewed By: mdvacca Differential Revision: D14112897 fbshipit-source-id: adf6078048dbf83452d3523f0530a4d6dca7b3e8 --- .../facebook/react/ReactInstanceManager.java | 2 +- .../com/facebook/react/ReactRootView.java | 67 ++++++++++++++----- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index b88326e6c..e8ff4ab6d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -1045,7 +1045,7 @@ public class ReactInstanceManager { @Nullable Bundle initialProperties = rootView.getAppProperties(); final int rootTag = uiManagerModule.addRootView( - rootView, + rootView.getView(), initialProperties == null ? new WritableNativeMap() : Arguments.fromBundle(initialProperties), rootView.getInitialUITemplate()); diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 3f8d29aff..2cde3cbc2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -94,19 +94,29 @@ public class ReactRootView extends FrameLayout implements RootView { private int mLastWidth = 0; private int mLastHeight = 0; private @UIManagerType int mUIManagerType = DEFAULT; + private final boolean mUseSurface; public ReactRootView(Context context) { super(context); + mUseSurface = false; + init(); + } + + public ReactRootView(Context context, boolean useSurface) { + super(context); + mUseSurface = useSurface; init(); } public ReactRootView(Context context, AttributeSet attrs) { super(context, attrs); + mUseSurface = false; init(); } public ReactRootView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + mUseSurface = false; init(); } @@ -114,8 +124,18 @@ public class ReactRootView extends FrameLayout implements RootView { setClipChildren(false); } + public View getView() { + // TODO add mUseSurface to return surface here + return this; + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (mUseSurface) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; + } + Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.onMeasure"); try { boolean measureSpecsUpdated = widthMeasureSpec != mWidthMeasureSpec || @@ -287,6 +307,9 @@ public class ReactRootView extends FrameLayout implements RootView { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (mUseSurface) { + super.onLayout(changed, left, top, right, bottom); + } // No-op since UIManagerModule handles actually laying out children. } @@ -365,6 +388,10 @@ public class ReactRootView extends FrameLayout implements RootView { mAppProperties = initialProperties; mInitialUITemplate = initialUITemplate; + if (mUseSurface) { + // TODO initialize surface here + } + if (!mReactInstanceManager.hasStartedCreatingInitialContext()) { mReactInstanceManager.createReactContextInBackground(); } @@ -457,25 +484,31 @@ public class ReactRootView extends FrameLayout implements RootView { return; } - if (mWasMeasured) { - updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec); - } CatalystInstance catalystInstance = reactContext.getCatalystInstance(); - - WritableNativeMap appParams = new WritableNativeMap(); - appParams.putDouble("rootTag", getRootViewTag()); - @Nullable Bundle appProperties = getAppProperties(); - if (appProperties != null) { - appParams.putMap("initialProps", Arguments.fromBundle(appProperties)); - } - if (getUIManagerType() == FABRIC) { - appParams.putBoolean("fabric", true); - } - - mShouldLogContentAppeared = true; - String jsAppModuleName = getJSModuleName(); - catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams); + + if (mUseSurface) { + // TODO call surface's runApplication + } else { + + if (mWasMeasured) { + updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec); + } + + WritableNativeMap appParams = new WritableNativeMap(); + appParams.putDouble("rootTag", getRootViewTag()); + @Nullable Bundle appProperties = getAppProperties(); + if (appProperties != null) { + appParams.putMap("initialProps", Arguments.fromBundle(appProperties)); + } + if (getUIManagerType() == FABRIC) { + appParams.putBoolean("fabric", true); + } + + mShouldLogContentAppeared = true; + + catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams); + } } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); }