diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index b9754033490..72bed4566bc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -27,6 +27,7 @@ import android.view.accessibility.AccessibilityEvent; import androidx.annotation.AnyThread; import androidx.annotation.Nullable; import androidx.annotation.UiThread; +import androidx.annotation.VisibleForTesting; import androidx.core.view.ViewCompat.FocusDirection; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; @@ -65,6 +66,7 @@ import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem; import com.facebook.react.fabric.mounting.mountitems.MountItem; import com.facebook.react.fabric.mounting.mountitems.MountItemFactory; import com.facebook.react.fabric.mounting.mountitems.PrefetchResourcesMountItem; +import com.facebook.react.fabric.mounting.mountitems.PullTransactionMountItem; import com.facebook.react.fabric.mounting.mountitems.SynchronousMountItem; import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags; import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags; @@ -1011,6 +1013,26 @@ public class FabricUIManager } } + /** + * Pull model: called from C++ via JNI (usually on the commit thread) to signal that a transaction + * is available for {@code surfaceId}. Enqueues a PullTransactionMountItem so the UI thread pulls + * and applies the transaction itself, preserving mount-item ordering. + */ + @SuppressWarnings("unused") + @AnyThread + @ThreadConfined(ANY) + @VisibleForTesting + void onTransactionAvailable(int surfaceId) { + FabricUIManagerBinding binding = mBinding; + if (binding == null) { + return; + } + mMountItemDispatcher.addMountItem(new PullTransactionMountItem(surfaceId, binding)); + if (UiThreadUtil.isOnUiThread()) { + mMountItemDispatcher.tryDispatchMountItems(); + } + } + @SuppressWarnings("unused") @AnyThread @ThreadConfined(ANY) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt index 84a6a17b208..b1b3f12f50c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt @@ -85,6 +85,8 @@ internal class FabricUIManagerBinding : HybridClassBase() { external fun reportMount(surfaceId: Int) + external fun pullAndExecuteTransaction(surfaceId: Int) + external fun mergeReactRevision(surfaceId: Int) fun register( diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PullTransactionMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PullTransactionMountItem.kt new file mode 100644 index 00000000000..68563cdf4ec --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PullTransactionMountItem.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric.mounting.mountitems + +import com.facebook.proguard.annotations.DoNotStripAny +import com.facebook.react.fabric.FabricUIManagerBinding +import com.facebook.react.fabric.mounting.MountingManager + +/** + * Pull model mount item. Enqueued (on the commit thread) when C++ notifies that a transaction is + * available for a surface. When it executes on the UI thread it asks C++ to pull the surface's + * pending transaction and apply it synchronously, so the diff + batch construction happens on the + * UI thread instead of the commit thread (matching iOS). + */ +@DoNotStripAny +internal class PullTransactionMountItem( + private val surfaceId: Int, + private val binding: FabricUIManagerBinding, +) : MountItem { + + override fun execute(mountingManager: MountingManager) { + binding.pullAndExecuteTransaction(surfaceId) + } + + override fun getSurfaceId(): Int = surfaceId + + override fun toString(): String = "PullTransactionMountItem [surfaceId: $surfaceId]" +}