From 05ce2cf2590e772973eca8aa73e55154554c1bd5 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 22 Dec 2021 02:56:24 -0800 Subject: [PATCH] Refactor duplicated code in ReactRootView Summary: Quick refactor of ReactRootView where I extract 'Fabric' check into a method changelog: [internal] internal Reviewed By: fkgozali Differential Revision: D33269025 fbshipit-source-id: 2647d5870f3b5fcc5a940a5924a39ca43b5bebac --- .../main/java/com/facebook/react/ReactRootView.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 6b528916857..eaa39a69f1f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -335,11 +335,15 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { // No-op in non-Fabric since UIManagerModule handles actually laying out children. // In Fabric, update LayoutSpecs just so we update the offsetX and offsetY. - if (mWasMeasured && getUIManagerType() == FABRIC) { + if (mWasMeasured && isFabric()) { updateRootLayoutSpecs(false, mWidthMeasureSpec, mHeightMeasureSpec); } } + private boolean isFabric() { + return getUIManagerType() == FABRIC; + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -509,7 +513,8 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { } // In Fabric we cannot call `updateRootLayoutSpecs` until a SurfaceId has been set. // Sometimes, - if (getUIManagerType() == FABRIC && !isRootViewTagSet()) { + boolean isFabricEnabled = isFabric(); + if (isFabricEnabled && !isRootViewTagSet()) { ReactMarker.logMarker(ReactMarkerConstants.ROOT_VIEW_UPDATE_LAYOUT_SPECS_END); FLog.e(TAG, "Unable to update root layout specs for ReactRootView: no rootViewTag set yet"); return; @@ -526,7 +531,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { // In Fabric only, get position of view within screen int offsetX = 0; int offsetY = 0; - if (getUIManagerType() == FABRIC) { + if (isFabricEnabled) { Point viewportOffset = RootViewUtil.getViewportOffset(this); offsetX = viewportOffset.x; offsetY = viewportOffset.y; @@ -561,7 +566,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { // all the views in the hierarchy. if (mReactInstanceManager != null) { final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext(); - if (reactApplicationContext != null && getUIManagerType() == FABRIC) { + if (reactApplicationContext != null && isFabric()) { @Nullable UIManager uiManager = UIManagerHelper.getUIManager(reactApplicationContext, getUIManagerType());