Skip to content

Commit 9114ddc

Browse files
javachefacebook-github-bot
authored andcommitted
Deprecate ViewUtil.getUIManagerType and inline UIManagerType.Fabric
Differential Revision: D91222827
1 parent 4ff4836 commit 9114ddc

23 files changed

Lines changed: 183 additions & 736 deletions

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,6 @@ public final class com/facebook/react/runtime/ReactSurfaceView : com/facebook/re
30523052
public fun <init> (Landroid/content/Context;Lcom/facebook/react/runtime/ReactSurfaceImpl;)V
30533053
public fun getCurrentReactContext ()Lcom/facebook/react/bridge/ReactContext;
30543054
public fun getJSModuleName ()Ljava/lang/String;
3055-
public fun getUIManagerType ()I
30563055
public fun handleException (Ljava/lang/Throwable;)V
30573056
public fun hasActiveReactContext ()Z
30583057
public fun hasActiveReactInstance ()Z
@@ -3061,7 +3060,6 @@ public final class com/facebook/react/runtime/ReactSurfaceView : com/facebook/re
30613060
public fun onChildStartedNativeGesture (Landroid/view/View;Landroid/view/MotionEvent;)V
30623061
public fun requestChildFocus (Landroid/view/View;Landroid/view/View;)V
30633062
public fun requestDisallowInterceptTouchEvent (Z)V
3064-
public fun setIsFabric (Z)V
30653063
}
30663064

30673065
public abstract class com/facebook/react/runtime/cxxreactpackage/CxxReactPackage {
@@ -5506,7 +5504,6 @@ public final class com/facebook/react/views/scroll/ReactHorizontalScrollContaine
55065504
public static final field Companion Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager$Companion;
55075505
public static final field REACT_CLASS Ljava/lang/String;
55085506
public fun <init> ()V
5509-
public synthetic fun createViewInstance (ILcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Landroid/view/View;
55105507
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
55115508
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/view/ReactViewGroup;
55125509
public fun getName ()Ljava/lang/String;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import com.facebook.react.internal.ChoreographerProvider;
7878
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
7979
import com.facebook.react.modules.appearance.AppearanceModule;
80-
import com.facebook.react.modules.appregistry.AppRegistry;
8180
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
8281
import com.facebook.react.modules.core.DeviceEventManagerModule;
8382
import com.facebook.react.modules.core.ReactChoreographer;
@@ -767,10 +766,7 @@ public void destroy() {
767766
synchronized (mReactContextLock) {
768767
if (mCurrentReactContext != null) {
769768
for (ReactRoot reactRoot : mAttachedReactRoots) {
770-
// Fabric surfaces must be cleaned up when React Native is destroyed.
771-
if (reactRoot.getUIManagerType() == UIManagerType.FABRIC) {
772-
detachRootViewFromInstance(reactRoot, mCurrentReactContext);
773-
}
769+
detachRootViewFromInstance(reactRoot, mCurrentReactContext);
774770
}
775771

776772
mCurrentReactContext.destroy();
@@ -1271,9 +1267,7 @@ private void attachRootViewToInstance(final ReactRoot reactRoot) {
12711267

12721268
Systrace.beginSection(TRACE_TAG_REACT, "attachRootViewToInstance");
12731269

1274-
@Nullable
1275-
UIManager uiManager =
1276-
UIManagerHelper.getUIManager(mCurrentReactContext, reactRoot.getUIManagerType());
1270+
@Nullable UIManager uiManager = UIManagerHelper.getUIManager(mCurrentReactContext, FABRIC);
12771271

12781272
// If we can't get a UIManager something has probably gone horribly wrong
12791273
if (uiManager == null) {
@@ -1284,28 +1278,16 @@ private void attachRootViewToInstance(final ReactRoot reactRoot) {
12841278

12851279
@Nullable Bundle initialProperties = reactRoot.getAppProperties();
12861280

1287-
final int rootTag;
1288-
if (reactRoot.getUIManagerType() == FABRIC) {
1289-
rootTag =
1290-
uiManager.startSurface(
1291-
reactRoot.getRootViewGroup(),
1292-
reactRoot.getJSModuleName(),
1293-
initialProperties == null
1294-
? new WritableNativeMap()
1295-
: Arguments.fromBundle(initialProperties),
1296-
reactRoot.getWidthMeasureSpec(),
1297-
reactRoot.getHeightMeasureSpec());
1298-
reactRoot.setShouldLogContentAppeared(true);
1299-
} else {
1300-
rootTag =
1301-
uiManager.addRootView(
1302-
reactRoot.getRootViewGroup(),
1303-
initialProperties == null
1304-
? new WritableNativeMap()
1305-
: Arguments.fromBundle(initialProperties));
1306-
reactRoot.setRootViewTag(rootTag);
1307-
reactRoot.runApplication();
1308-
}
1281+
final int rootTag =
1282+
uiManager.startSurface(
1283+
reactRoot.getRootViewGroup(),
1284+
reactRoot.getJSModuleName(),
1285+
initialProperties == null
1286+
? new WritableNativeMap()
1287+
: Arguments.fromBundle(initialProperties),
1288+
reactRoot.getWidthMeasureSpec(),
1289+
reactRoot.getHeightMeasureSpec());
1290+
reactRoot.setShouldLogContentAppeared(true);
13091291

13101292
Systrace.beginAsyncSection(TRACE_TAG_REACT, "pre_rootView.onAttachedToReactInstance", rootTag);
13111293
UiThreadUtil.runOnUiThread(
@@ -1326,36 +1308,29 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
13261308
return;
13271309
}
13281310

1329-
@UIManagerType int uiManagerType = reactRoot.getUIManagerType();
1330-
if (uiManagerType == UIManagerType.FABRIC) {
1331-
// Stop surface in Fabric.
1332-
// Calling FabricUIManager.stopSurface causes the C++ Binding.stopSurface
1333-
// to be called synchronously over the JNI, which causes an empty tree
1334-
// to be committed via the Scheduler, which will cause mounting instructions
1335-
// to be queued up and synchronously executed to delete and remove
1336-
// all the views in the hierarchy.
1337-
final int surfaceId = reactRoot.getRootViewTag();
1338-
if (surfaceId != View.NO_ID) {
1339-
UIManager uiManager = UIManagerHelper.getUIManager(reactContext, uiManagerType);
1340-
if (uiManager != null) {
1341-
uiManager.stopSurface(surfaceId);
1342-
} else {
1343-
FLog.w(ReactConstants.TAG, "Failed to stop surface, UIManager has already gone away");
1344-
}
1311+
@UIManagerType int uiManagerType = FABRIC;
1312+
// Stop surface in Fabric.
1313+
// Calling FabricUIManager.stopSurface causes the C++ Binding.stopSurface
1314+
// to be called synchronously over the JNI, which causes an empty tree
1315+
// to be committed via the Scheduler, which will cause mounting instructions
1316+
// to be queued up and synchronously executed to delete and remove
1317+
// all the views in the hierarchy.
1318+
final int surfaceId = reactRoot.getRootViewTag();
1319+
if (surfaceId != View.NO_ID) {
1320+
UIManager uiManager = UIManagerHelper.getUIManager(reactContext, uiManagerType);
1321+
if (uiManager != null) {
1322+
uiManager.stopSurface(surfaceId);
13451323
} else {
1346-
ReactSoftExceptionLogger.logSoftException(
1347-
TAG,
1348-
new RuntimeException(
1349-
"detachRootViewFromInstance called with ReactRootView with invalid id"));
1324+
FLog.w(ReactConstants.TAG, "Failed to stop surface, UIManager has already gone away");
13501325
}
1351-
1352-
clearReactRoot(reactRoot);
13531326
} else {
1354-
reactContext
1355-
.getCatalystInstance()
1356-
.getJSModule(AppRegistry.class)
1357-
.unmountApplicationComponentAtRootTag(reactRoot.getRootViewTag());
1327+
ReactSoftExceptionLogger.logSoftException(
1328+
TAG,
1329+
new RuntimeException(
1330+
"detachRootViewFromInstance called with ReactRootView with invalid id"));
13581331
}
1332+
1333+
clearReactRoot(reactRoot);
13591334
}
13601335

13611336
@ThreadConfined(UI)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static com.facebook.infer.annotation.ThreadConfined.UI;
1111
import static com.facebook.react.uimanager.BlendModeHelper.needsIsolatedLayer;
1212
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
13-
import static com.facebook.react.uimanager.common.UIManagerType.LEGACY;
1413
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT;
1514

1615
import android.annotation.SuppressLint;
@@ -52,6 +51,7 @@
5251
import com.facebook.react.bridge.WritableMap;
5352
import com.facebook.react.bridge.WritableNativeMap;
5453
import com.facebook.react.common.annotations.VisibleForTesting;
54+
import com.facebook.react.common.annotations.internal.LegacyArchitecture;
5555
import com.facebook.react.config.ReactFeatureFlags;
5656
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
5757
import com.facebook.react.modules.appregistry.AppRegistry;
@@ -70,7 +70,6 @@
7070
import com.facebook.react.uimanager.RootViewUtil;
7171
import com.facebook.react.uimanager.UIManagerHelper;
7272
import com.facebook.react.uimanager.common.UIManagerType;
73-
import com.facebook.react.uimanager.common.ViewUtil;
7473
import com.facebook.react.uimanager.events.EventDispatcher;
7574
import com.facebook.systrace.Systrace;
7675
import java.util.concurrent.atomic.AtomicInteger;
@@ -117,7 +116,6 @@ public interface ReactRootViewEventListener {
117116
private int mLastHeight = 0;
118117
private int mLastOffsetX = Integer.MIN_VALUE;
119118
private int mLastOffsetY = Integer.MIN_VALUE;
120-
private @UIManagerType int mUIManagerType = LEGACY;
121119
private final AtomicInteger mState = new AtomicInteger(STATE_STOPPED);
122120

123121
public ReactRootView(Context context) {
@@ -308,9 +306,7 @@ protected void dispatchDraw(Canvas canvas) {
308306
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
309307

310308
BlendMode mixBlendMode = null;
311-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
312-
&& ViewUtil.getUIManagerType(this) == UIManagerType.FABRIC
313-
&& needsIsolatedLayer(this)) {
309+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && needsIsolatedLayer(this)) {
314310
mixBlendMode = (BlendMode) child.getTag(R.id.mix_blend_mode);
315311
if (mixBlendMode != null) {
316312
Paint p = new Paint();
@@ -475,7 +471,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
475471
}
476472

477473
private boolean isFabric() {
478-
return getUIManagerType() == FABRIC;
474+
return true;
479475
}
480476

481477
@Override
@@ -647,9 +643,7 @@ private void updateRootLayoutSpecs(
647643
final ReactContext reactApplicationContext = getCurrentReactContext();
648644

649645
if (reactApplicationContext != null) {
650-
@Nullable
651-
UIManager uiManager =
652-
UIManagerHelper.getUIManager(reactApplicationContext, getUIManagerType());
646+
@Nullable UIManager uiManager = UIManagerHelper.getUIManager(reactApplicationContext, FABRIC);
653647
// Ignore calling updateRootLayoutSpecs if UIManager is not properly initialized.
654648
if (uiManager != null) {
655649
// In Fabric only, get position of view within screen
@@ -892,15 +886,18 @@ public void handleException(final Throwable t) {
892886
getCurrentReactContext().handleException(e);
893887
}
894888

889+
@LegacyArchitecture
890+
@Deprecated
895891
public void setIsFabric(boolean isFabric) {
896-
mUIManagerType = isFabric ? FABRIC : LEGACY;
892+
/* noop */
897893
}
898894

899895
@Override
900896
public @UIManagerType int getUIManagerType() {
901-
return mUIManagerType;
897+
return FABRIC;
902898
}
903899

900+
@LegacyArchitecture
904901
@Nullable
905902
public ReactInstanceManager getReactInstanceManager() {
906903
return mReactInstanceManager;

0 commit comments

Comments
 (0)