Deprecate UIManagerType.DEFAULT and introduce UIManagerType.LEGACY (#50157)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50157

UIManagerType.DEFAULT is becoming confusings As we are expanding the usage of the New architecture everywhere.

That's why I'm depreacting this constant and introducing UIManagerType.LEGACY.

changelog: [Android][Deprecated] Deprecate UIManagerType.DEFAULT, replaced by UIManagerType.LEGACY

Reviewed By: alanleedev

Differential Revision: D70738948

fbshipit-source-id: 9793a6cce3b931f9c0de4e0c2026852119f392b2
This commit is contained in:
David Vacca
2025-03-20 13:08:29 -07:00
committed by Facebook GitHub Bot
parent a8c675d460
commit a8668319ad
10 changed files with 27 additions and 21 deletions
@@ -5167,11 +5167,13 @@ public abstract interface annotation class com/facebook/react/uimanager/common/U
public static final field Companion Lcom/facebook/react/uimanager/common/UIManagerType$Companion;
public static final field DEFAULT I
public static final field FABRIC I
public static final field LEGACY I
}
public final class com/facebook/react/uimanager/common/UIManagerType$Companion {
public static final field DEFAULT I
public static final field FABRIC I
public static final field LEGACY I
}
public final class com/facebook/react/uimanager/common/ViewUtil {
@@ -9,8 +9,8 @@ package com.facebook.react;
import static com.facebook.infer.annotation.ThreadConfined.UI;
import static com.facebook.react.uimanager.BlendModeHelper.needsIsolatedLayer;
import static com.facebook.react.uimanager.common.UIManagerType.DEFAULT;
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
import static com.facebook.react.uimanager.common.UIManagerType.LEGACY;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
import android.content.Context;
@@ -114,7 +114,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
private int mLastHeight = 0;
private int mLastOffsetX = Integer.MIN_VALUE;
private int mLastOffsetY = Integer.MIN_VALUE;
private @UIManagerType int mUIManagerType = DEFAULT;
private @UIManagerType int mUIManagerType = LEGACY;
private final AtomicInteger mState = new AtomicInteger(STATE_STOPPED);
public ReactRootView(Context context) {
@@ -817,7 +817,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
}
public void setIsFabric(boolean isFabric) {
mUIManagerType = isFabric ? FABRIC : DEFAULT;
mUIManagerType = isFabric ? FABRIC : LEGACY;
}
@Override
@@ -232,7 +232,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
private boolean mInitializedForFabric = false;
private boolean mInitializedForNonFabric = false;
private boolean mEnqueuedAnimationOnFrame = false;
private @UIManagerType int mUIManagerType = UIManagerType.DEFAULT;
private @UIManagerType int mUIManagerType = UIManagerType.LEGACY;
private int mNumFabricAnimations = 0;
private int mNumNonFabricAnimations = 0;
@@ -542,8 +542,8 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
mUIManagerType = UIManagerType.FABRIC;
} else if (mNumFabricAnimations == 0
&& mNumNonFabricAnimations > 0
&& mUIManagerType != UIManagerType.DEFAULT) {
mUIManagerType = UIManagerType.DEFAULT;
&& mUIManagerType != UIManagerType.LEGACY) {
mUIManagerType = UIManagerType.LEGACY;
}
}
@@ -181,7 +181,7 @@ public class UIManagerHelper {
int reactTag = view.getId();
// In non-Fabric we don't have (or use) SurfaceId
if (getUIManagerType(reactTag) == UIManagerType.DEFAULT) {
if (getUIManagerType(reactTag) == UIManagerType.LEGACY) {
return -1;
}
@@ -9,8 +9,8 @@ package com.facebook.react.uimanager;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_END;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_START;
import static com.facebook.react.uimanager.common.UIManagerType.DEFAULT;
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
import static com.facebook.react.uimanager.common.UIManagerType.LEGACY;
import android.content.ComponentCallbacks2;
import android.content.res.Configuration;
@@ -185,7 +185,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule
getReactApplicationContext().registerComponentCallbacks(mMemoryTrimCallback);
getReactApplicationContext().registerComponentCallbacks(mViewManagerRegistry);
mEventDispatcher.registerEventEmitter(
DEFAULT, getReactApplicationContext().getJSModule(RCTEventEmitter.class));
LEGACY, getReactApplicationContext().getJSModule(RCTEventEmitter.class));
}
@Override
@@ -851,7 +851,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule
@Override
public void receiveEvent(
int surfaceId, int reactTag, String eventName, @Nullable WritableMap event) {
assert ViewUtil.getUIManagerType(reactTag) == DEFAULT;
assert ViewUtil.getUIManagerType(reactTag) == LEGACY;
getReactApplicationContext()
.getJSModule(RCTEventEmitter.class)
.receiveEvent(reactTag, eventName, event);
@@ -11,11 +11,15 @@ import androidx.annotation.IntDef
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture
@Retention(AnnotationRetention.SOURCE)
@IntDef(UIManagerType.DEFAULT, UIManagerType.FABRIC)
@Suppress("DEPRECATION")
@IntDef(UIManagerType.DEFAULT, UIManagerType.LEGACY, UIManagerType.FABRIC)
@DeprecatedInNewArchitecture
public annotation class UIManagerType {
public companion object {
@Deprecated(
"UIManagerType.DEFAULT will be deleted in the next release of React Native. Use [LEGACY] instead.")
public const val DEFAULT: Int = 1
public const val LEGACY: Int = 1
public const val FABRIC: Int = 2
}
}
@@ -25,7 +25,7 @@ public object ViewUtil {
if (viewTag % 2 == 0) {
UIManagerType.FABRIC
} else {
UIManagerType.DEFAULT
UIManagerType.LEGACY
}
/**
@@ -55,8 +55,8 @@ public object ViewUtil {
// by RN and is essentially a random number.
// At some point it would be great to pass the SurfaceContext here instead.
@UIManagerType
val uiManagerType = if (surfaceId == -1) UIManagerType.DEFAULT else UIManagerType.FABRIC
if (uiManagerType == UIManagerType.DEFAULT && !isRootTag(viewTag)) {
val uiManagerType = if (surfaceId == -1) UIManagerType.LEGACY else UIManagerType.FABRIC
if (uiManagerType == UIManagerType.LEGACY && !isRootTag(viewTag)) {
// TODO (T123064648): Some events for Fabric still didn't have the surfaceId set, so if it's
// not a React RootView, double check if the tag belongs to Fabric.
if (viewTag % 2 == 0) {
@@ -32,12 +32,12 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte
}
fun register(@UIManagerType uiManagerType: Int, eventEmitter: RCTEventEmitter?) {
check(uiManagerType == UIManagerType.DEFAULT)
check(uiManagerType == UIManagerType.LEGACY)
defaultEventEmitter = eventEmitter
}
fun unregister(@UIManagerType uiManagerType: Int) {
if (uiManagerType == UIManagerType.DEFAULT) {
if (uiManagerType == UIManagerType.LEGACY) {
defaultEventEmitter = null
} else {
fabricEventEmitter = null
@@ -73,7 +73,7 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte
val reactTag = touches.getMap(0)?.getInt(TouchesHelper.TARGET_KEY) ?: 0
@UIManagerType val uiManagerType = getUIManagerType(reactTag)
if (uiManagerType == UIManagerType.DEFAULT) {
if (uiManagerType == UIManagerType.LEGACY) {
ensureDefaultEventEmitter()?.receiveTouches(eventName, touches, changedIndices)
}
}
@@ -83,7 +83,7 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte
@UIManagerType val uiManagerType = getUIManagerType(event.viewTag, event.surfaceId)
if (uiManagerType == UIManagerType.FABRIC) {
fabricEventEmitter?.let { TouchesHelper.sendTouchEvent(it, event) }
} else if (uiManagerType == UIManagerType.DEFAULT) {
} else if (uiManagerType == UIManagerType.LEGACY) {
ensureDefaultEventEmitter()?.let { TouchesHelper.sendTouchesLegacy(it, event) }
}
}
@@ -119,7 +119,7 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte
if (uiManagerType == UIManagerType.FABRIC) {
fabricEventEmitter?.receiveEvent(
surfaceId, targetTag, eventName, canCoalesceEvent, customCoalesceKey, params, category)
} else if (uiManagerType == UIManagerType.DEFAULT) {
} else if (uiManagerType == UIManagerType.LEGACY) {
ensureDefaultEventEmitter()?.receiveEvent(targetTag, eventName, params)
}
}
@@ -312,7 +312,7 @@ public object ReactScrollViewHelper {
FLog.i(
TAG, "updateFabricScrollState[%d] scrollX %d scrollY %d", scrollView.id, scrollX, scrollY)
}
if (ViewUtil.getUIManagerType(scrollView.id) == UIManagerType.DEFAULT) {
if (ViewUtil.getUIManagerType(scrollView.id) == UIManagerType.LEGACY) {
return
}
// NOTE: if the state wrapper is null, we shouldn't even update
@@ -217,7 +217,7 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
ReactContext reactContext = getReactContext();
UIManager uiManager =
Assertions.assertNotNull(UIManagerHelper.getUIManager(reactContext, UIManagerType.DEFAULT));
Assertions.assertNotNull(UIManagerHelper.getUIManager(reactContext, UIManagerType.LEGACY));
Spanned text = (Spanned) getText();
Layout layout = getLayout();