Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -4805,6 +4805,8 @@ public abstract interface class com/facebook/react/uimanager/UIManagerModule$Cus

public class com/facebook/react/uimanager/UIManagerModuleConstantsHelper {
public fun <init> ()V
public static fun createConstants (Ljava/util/List;Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
public static fun createConstantsForViewManager (Lcom/facebook/react/uimanager/ViewManager;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
public static fun getDefaultExportableEventTypes ()Ljava/util/Map;
}

Expand Down Expand Up @@ -5167,11 +5169,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.debuggingoverlay.DebuggingOverlayManager;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +54,7 @@ public Map<String, ReactModuleInfo> getReactModuleInfos() {
}

/**
* @return a map of view managers that should be registered with {@link UIManagerModule}
* @return a map of view managers that should be registered with {@link UIManager}
*/
private Map<String, ModuleSpec> getViewManagersMap() {
if (mViewManagers == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ package com.facebook.react

import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UIManager
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture
import com.facebook.react.common.annotations.StableReactNativeAPI
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.uimanager.ViewManager

/**
Expand All @@ -37,7 +37,7 @@ public interface ReactPackage {
@DeprecatedInNewArchitecture(message = "Migrate to BaseReactPackage and implement getModule")
public fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule>

/** @return a list of view managers that should be registered with [UIManagerModule] */
/** @return a list of view managers that should be registered with [UIManager] */
public fun createViewManagers(
reactContext: ReactApplicationContext
): List<ViewManager<in Nothing, in Nothing>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

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;
Expand Down Expand Up @@ -114,7 +114,7 @@ public interface ReactRootViewEventListener {
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) {
Expand Down Expand Up @@ -817,7 +817,7 @@ public void handleException(final Throwable t) {
}

public void setIsFabric(boolean isFabric) {
mUIManagerType = isFabric ? FABRIC : DEFAULT;
mUIManagerType = isFabric ? FABRIC : LEGACY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.ReactChoreographer;
Expand Down Expand Up @@ -232,7 +233,7 @@ void executeBatch(long maxBatchNumber, NativeAnimatedNodesManager nodesManager)
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;

Expand Down Expand Up @@ -387,9 +388,13 @@ public void willDispatchViewUpdates(final UIManager uiManager) {
if (mOperations.isEmpty() && mPreOperations.isEmpty()) {
return;
}
if (mUIManagerType == UIManagerType.FABRIC) {
if (mUIManagerType == UIManagerType.FABRIC
|| ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE) {
return;
}
// The following code ONLY executes for non-fabric
// When ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE is true, the folowing code
// might be stripped out.

final long frameNo = mCurrentBatchNumber++;

Expand Down Expand Up @@ -542,8 +547,8 @@ private void decrementInFlightAnimationsForViewTag(final int viewTag) {
mUIManagerType = UIManagerType.FABRIC;
} else if (mNumFabricAnimations == 0
&& mNumNonFabricAnimations > 0
&& mUIManagerType != UIManagerType.DEFAULT) {
mUIManagerType = UIManagerType.DEFAULT;
&& mUIManagerType != UIManagerType.LEGACY) {
mUIManagerType = UIManagerType.LEGACY;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package com.facebook.react.bridge;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.systrace.Systrace;
import java.util.ArrayList;
Expand Down Expand Up @@ -113,6 +115,8 @@ public void onBatchComplete() {
// short-circuit
// the search, and simply call OnBatchComplete on the UI Manager.
// With Fabric, UIManager would no longer be a NativeModule, so this call would simply go away
LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled(
"NativeModuleRegistry.onBatchComplete()", LegacyArchitectureLogLevel.ERROR);
ModuleHolder moduleHolder = mModules.get("UIManager");
if (moduleHolder != null && moduleHolder.hasInstance()) {
((OnBatchCompleteListener) moduleHolder.getModule()).onBatchComplete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ReactChoreographer private constructor(choreographerProvider: Chore
public enum class CallbackType(internal val order: Int) {
/** For use by perf markers that need to happen immediately after draw */
PERF_MARKERS(0),
/** For use by [com.facebook.react.uimanager.UIManagerModule] */
/** For use by [com.facebook.react.bridge.UIManager] */
DISPATCH_UI(1),
/** For use by [com.facebook.react.animated.NativeAnimatedModule] */
NATIVE_ANIMATED_MODULE(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ FabricUIManager getUIManager() {
/* package */
@Nullable
<T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface) {
if (nativeModuleInterface == UIManagerModule.class) {
if (!ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE
&& nativeModuleInterface == UIManagerModule.class) {

ReactSoftExceptionLogger.logSoftExceptionVerbose(
TAG,
new ReactNoCrashBridgeNotAllowedSoftException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package com.facebook.react.runtime;

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 android.content.res.AssetManager;
import android.view.View;
import com.facebook.common.logging.FLog;
Expand All @@ -29,6 +32,7 @@
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.RuntimeExecutor;
Expand Down Expand Up @@ -60,14 +64,14 @@
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.UIConstantsProviderBinding;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.UIManagerModuleConstantsHelper;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.ViewManagerResolver;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.soloader.SoLoader;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -242,15 +246,13 @@ final class ReactInstance {
if (viewManager == null) {
return null;
}
return (NativeMap)
UIManagerModule.getConstantsForViewManager(viewManager, customDirectEvents);
return getConstantsForViewManager(viewManager, customDirectEvents);
},
() -> {
List<ViewManager> viewManagers =
new ArrayList<>(mViewManagerResolver.getEagerViewManagerMap().values());

Map<String, Object> constants =
UIManagerModule.createConstants(viewManagers, null, customDirectEvents);
Map<String, Object> constants = createConstants(viewManagers, null, customDirectEvents);

Collection<String> lazyViewManagers = mViewManagerResolver.getLazyViewManagerNames();
if (lazyViewManagers.size() > 0) {
Expand Down Expand Up @@ -287,6 +289,40 @@ final class ReactInstance {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}

private static Map<String, Object> createConstants(
List<ViewManager> viewManagers,
@Nullable Map<String, Object> customBubblingEvents,
@Nullable Map<String, Object> customDirectEvents) {
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants")
.arg("Lazy", false)
.flush();
try {
return UIManagerModuleConstantsHelper.createConstants(
viewManagers, customBubblingEvents, customDirectEvents);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
}
}

private static NativeMap getConstantsForViewManager(
ViewManager viewManager, Map<String, Object> customDirectEvents) {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstance.getConstantsForViewManager")
.arg("ViewManager", viewManager.getName())
.arg("Lazy", true)
.flush();
try {
Map<String, Object> viewManagerConstants =
UIManagerModuleConstantsHelper.createConstantsForViewManager(
viewManager, null, null, null, customDirectEvents);
return Arguments.makeNativeMap(viewManagerConstants);
} finally {
SystraceMessage.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE).flush();
}
}

void initializeEagerTurboModules() {
mQueueConfiguration
.getNativeModulesQueueThread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.view.ViewGroup
import android.view.ViewParent

/**
* This class coordinates JSResponder commands for [UIManagerModule]. It should be set as
* This class coordinates JSResponder commands for [UIManager]. It should be set as
* OnInterceptTouchEventListener for all newly created native views that implements [ ] and thanks
* to the information whether JSResponder is set and to which view it will correctly coordinate the
* return values of [OnInterceptTouchEventListener] such that touch events will be dispatched to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.EventDispatcherProvider;
Expand Down Expand Up @@ -69,6 +71,14 @@ private static UIManager getUIManager(
return uiManager;
}

// The following code is compiled-out when `context.isBridgeless() == true &&
// ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE == true ` because:
// - BridgelessReactContext.isBridgeless() is set to true statically
// - BridgeReactContext is compiled-out when UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE == true
//
// To detect a potential regression we add the following assertion ERROR
LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled(
"UIManagerHelper.getUIManager(context, uiManagerType)", LegacyArchitectureLogLevel.ERROR);
if (!context.hasCatalystInstance()) {
ReactSoftExceptionLogger.logSoftException(
TAG,
Expand Down Expand Up @@ -181,7 +191,7 @@ public static int getSurfaceId(View view) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

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;
Expand Down Expand Up @@ -185,7 +185,7 @@ public void initialize() {
getReactApplicationContext().registerComponentCallbacks(mMemoryTrimCallback);
getReactApplicationContext().registerComponentCallbacks(mViewManagerRegistry);
mEventDispatcher.registerEventEmitter(
DEFAULT, getReactApplicationContext().getJSModule(RCTEventEmitter.class));
LEGACY, getReactApplicationContext().getJSModule(RCTEventEmitter.class));
}

@Override
Expand Down Expand Up @@ -851,7 +851,7 @@ public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap e
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ private static void validateDirectEventNames(
* into the map of {@link UIManagerModule} base constants that is stored in {@link
* UIManagerModuleConstants}. TODO(6845124): Create a test for this
*/
/* package */ static Map<String, Object> createConstants(
// NOTE: When converted to Kotlin this method should be `internal` due to
// visibility restriction for `ReactInstance`
public static Map<String, Object> createConstants(
List<ViewManager> viewManagers,
@Nullable Map<String, Object> allBubblingEventTypes,
@Nullable Map<String, Object> allDirectEventTypes) {
Expand Down Expand Up @@ -124,7 +126,9 @@ private static void validateDirectEventNames(
return constants;
}

/* package */ static Map<String, Object> createConstantsForViewManager(
// NOTE: When converted to Kotlin this method should be `internal` due to
// visibility restriction for `ReactInstance`
public static Map<String, Object> createConstantsForViewManager(
ViewManager viewManager,
@Nullable Map defaultBubblingEvents,
@Nullable Map defaultDirectEvents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public object ViewUtil {
if (viewTag % 2 == 0) {
UIManagerType.FABRIC
} else {
UIManagerType.DEFAULT
UIManagerType.LEGACY
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
Loading