Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ import com.facebook.react.uimanager.events.EventDispatcher

@OptIn(UnstableReactNativeAPI::class)
public interface UIManager : PerformanceCounter {
/** Registers a new root view. @Deprecated call startSurface instead */
/**
* Registers a new root view.
*
* @deprecated Use `ReactHost.createSurface(...)` and `ReactSurface.start()` instead.
*/
@UiThread
@ThreadConfined(ThreadConfined.UI)
@Deprecated("")
@Deprecated(
"This legacy surface API will be removed in a future release. " +
"Use ReactHost.createSurface(...) and ReactSurface.start() instead."
)
public fun <T : View> addRootView(rootView: T, initialProps: WritableMap?): Int

/** Registers a new root view with width and height. */
/**
* Registers a new root view with width and height.
*
* @deprecated Use `ReactHost.createSurface(...)` and `ReactSurface.start()` instead.
*/
@AnyThread
@Deprecated(
"This legacy surface API will be removed in a future release. " +
"Use ReactHost.createSurface(...) and ReactSurface.start() instead."
)
public fun <T : View?> startSurface(
rootView: T,
moduleName: String,
Expand All @@ -35,8 +50,14 @@ public interface UIManager : PerformanceCounter {
/**
* Stop a surface from running in JS and clears up native memory usage. Assumes that the native
* View hierarchy has already been cleaned up. Fabric-only.
*
* @deprecated Use `ReactSurface.stop()` instead.
*/
@AnyThread public fun stopSurface(surfaceId: Int)
@AnyThread
@Deprecated(
"This legacy surface API will be removed in a future release. Use ReactSurface.stop() instead."
)
public fun stopSurface(surfaceId: Int)

/**
* Updates the layout specs of the RootShadowNode based on the Measure specs received by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import static com.facebook.infer.annotation.ThreadConfined.ANY;
import static com.facebook.infer.annotation.ThreadConfined.UI;
import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMaxSize;
import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMinSize;
import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getYogaMeasureMode;
import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getYogaSize;
import static com.facebook.react.uimanager.UIManagerHelper.PADDING_BOTTOM_INDEX;
Expand All @@ -20,7 +18,6 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.os.SystemClock;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
Expand All @@ -38,7 +35,6 @@
import com.facebook.react.bridge.GuardedRunnable;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
Expand Down Expand Up @@ -73,14 +69,11 @@
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
import com.facebook.react.internal.interop.InteropEventEmitter;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.GuardedFrameCallback;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ReactRoot;
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
import com.facebook.react.uimanager.RootViewUtil;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerHelper;
Expand Down Expand Up @@ -262,31 +255,16 @@ public FabricUIManager(
mReactApplicationContext.registerComponentCallbacks(viewManagerRegistry);
}

/**
* @deprecated Use {@code ReactHost.createSurface(...)} and {@code ReactSurface.start()} instead.
*/
@Override
@UiThread
@ThreadConfined(UI)
@Deprecated
public <T extends View> int addRootView(
final T rootView, final @Nullable WritableMap initialProps) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Do not call addRootView in Fabric; it is unsupported. Call startSurface instead."));

ReactRoot reactRootView = (ReactRoot) rootView;
final int rootTag = reactRootView.getRootViewTag();

ThemedReactContext reactContext =
new ThemedReactContext(
mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID(), rootTag);
mMountingManager.startSurface(rootTag, reactContext, rootView);
String moduleName = reactRootView.getJSModuleName();
if (ReactNativeFeatureFlags.enableFabricLogs()) {
FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag);
}
Assertions.assertNotNull(mBinding, "Binding in FabricUIManager is null");
mBinding.startSurface(rootTag, moduleName, (NativeMap) initialProps);
return rootTag;
throw new UnsupportedOperationException("FabricUIManager.addRootView is unsupported.");
}

/**
Expand Down Expand Up @@ -341,6 +319,10 @@ public <T extends View> int addRootView(
return mBinding != null ? mBinding.getRelativeAncestorList(rootTag, childTag) : null;
}

/**
* @deprecated Use {@code ReactHost.createSurface(...)} and {@code ReactSurface.start()} instead.
*/
@Deprecated
@Override
@AnyThread
@ThreadConfined(ANY)
Expand All @@ -350,36 +332,8 @@ public <T extends View> int startSurface(
final @Nullable WritableMap initialProps,
int widthMeasureSpec,
int heightMeasureSpec) {
final int rootTag = ((ReactRoot) rootView).getRootViewTag();
Context context = rootView.getContext();
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, context, moduleName, rootTag);
if (ReactNativeFeatureFlags.enableFabricLogs()) {
FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag);
}
mMountingManager.startSurface(rootTag, reactContext, rootView);

// If startSurface is executed in the UIThread then, it uses the ViewportOffset from the View,
// Otherwise Fabric relies on calling {@link Binding#setConstraints} method to update the
// ViewportOffset during measurement or onLayout.
@SuppressLint("WrongThread")
Point viewportOffset =
UiThreadUtil.isOnUiThread() ? RootViewUtil.getViewportOffset(rootView) : new Point(0, 0);

Assertions.assertNotNull(mBinding, "Binding in FabricUIManager is null");
mBinding.startSurfaceWithConstraints(
rootTag,
moduleName,
(NativeMap) initialProps,
getMinSize(widthMeasureSpec),
getMaxSize(widthMeasureSpec),
getMinSize(heightMeasureSpec),
getMaxSize(heightMeasureSpec),
viewportOffset.x,
viewportOffset.y,
I18nUtil.getInstance().isRTL(context),
I18nUtil.getInstance().doLeftAndRightSwapInRTL(context));
return rootTag;
throw new UnsupportedOperationException(
"FabricUIManager.startSurface(View, ...) is unsupported.");
}

public void startSurface(
Expand Down Expand Up @@ -430,18 +384,15 @@ public void onRequestEventBeat() {
mEventDispatcher.dispatchAllEvents();
}

/**
* @deprecated Use {@code ReactSurface.stop()} instead.
*/
@Deprecated
@AnyThread
@ThreadConfined(ANY)
@Override
public void stopSurface(final int surfaceID) {
// Mark surfaceId as dead, stop executing mounting instructions
mMountingManager.stopSurface(surfaceID);

// Communicate stopSurface to Cxx - causes an empty ShadowTree to be committed,
// but all mounting instructions will be ignored because stopSurface was called
// on the MountingManager
Assertions.assertNotNull(mBinding, "Binding in FabricUIManager is null");
mBinding.stopSurface(surfaceID);
throw new UnsupportedOperationException("FabricUIManager.stopSurface(int) is unsupported.");
}

@Override
Expand Down Expand Up @@ -1118,43 +1069,7 @@ public void updateRootLayoutSpecs(
final int widthMeasureSpec,
final int heightMeasureSpec,
final int offsetX,
final int offsetY) {

if (ReactNativeFeatureFlags.enableFabricLogs()) {
FLog.d(TAG, "Updating Root Layout Specs for [%d]", surfaceId);
}

SurfaceMountingManager surfaceMountingManager = mMountingManager.getSurfaceManager(surfaceId);

// TODO T83615646: make this a hard-crash in the future.
if (surfaceMountingManager == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Cannot updateRootLayoutSpecs on surfaceId that does not exist: " + surfaceId));
return;
}

Context context = surfaceMountingManager.getContext();
boolean isRTL = false;
boolean doLeftAndRightSwapInRTL = false;
if (context != null) {
isRTL = I18nUtil.getInstance().isRTL(context);
doLeftAndRightSwapInRTL = I18nUtil.getInstance().doLeftAndRightSwapInRTL(context);
}

Assertions.assertNotNull(mBinding, "Binding in FabricUIManager is null");
mBinding.setConstraints(
surfaceId,
getMinSize(widthMeasureSpec),
getMaxSize(widthMeasureSpec),
getMinSize(heightMeasureSpec),
getMaxSize(heightMeasureSpec),
offsetX,
offsetY,
isRTL,
doLeftAndRightSwapInRTL);
}
final int offsetY) {}

@Override
public @Nullable View resolveView(int reactTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ package com.facebook.react.fabric
import android.annotation.SuppressLint
import com.facebook.jni.HybridClassBase
import com.facebook.proguard.annotations.DoNotStripAny
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.RuntimeExecutor
import com.facebook.react.bridge.RuntimeScheduler
import com.facebook.react.fabric.events.EventBeatManager
import com.facebook.react.uimanager.PixelUtil.getDisplayMetricDensity

@DoNotStripAny
@SuppressLint("MissingNativeLoadLibrary")
Expand All @@ -33,22 +31,6 @@ internal class FabricUIManagerBinding : HybridClassBase() {
componentsRegistry: ComponentFactory,
)

external fun startSurface(surfaceId: Int, moduleName: String, initialProps: NativeMap?)

external fun startSurfaceWithConstraints(
surfaceId: Int,
moduleName: String,
initialProps: NativeMap?,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean,
)

external fun startSurfaceWithSurfaceHandler(
surfaceId: Int,
surfaceHandler: SurfaceHandlerBinding,
Expand All @@ -59,24 +41,8 @@ internal class FabricUIManagerBinding : HybridClassBase() {

external fun getRelativeAncestorList(rootTag: Int, childTag: Int): IntArray

external fun stopSurface(surfaceId: Int)

external fun stopSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding)

external fun setPixelDensity(pointScaleFactor: Float)

external fun setConstraints(
surfaceId: Int,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean,
)

external fun driveCxxAnimations()

external fun driveAnimationBackend(frameTimeNanos: Long)
Expand Down Expand Up @@ -105,7 +71,6 @@ internal class FabricUIManagerBinding : HybridClassBase() {
eventBeatManager,
componentFactory,
)
setPixelDensity(getDisplayMetricDensity())
}

private external fun uninstallFabricUIManager()
Expand Down
Loading
Loading