From 6515647d9456fb2781d0e50e810b1c4741b0ba4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 29 Jul 2026 06:37:09 -0700 Subject: [PATCH] Add inert Java plumbing for the Android pull model (#57580) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/react/react-native/pull/57580 Java side of the pull model — dead code until the C++ wiring lands: - `PullTransactionMountItem`: asks C++ (via `FabricUIManagerBinding.pullAndExecuteTransaction`) to pull the surface's pending transaction and apply it synchronously on the UI thread. - `FabricUIManager.onTransactionAvailable` (JNI entry): enqueues a `PullTransactionMountItem`. - `FabricUIManagerBinding.pullAndExecuteTransaction`: extern declaration. One item is enqueued per notification, mirroring iOS; redundant items no-op in C++. ## Changelog: [Android] [Added] - Add inert Java plumbing (`PullTransactionMountItem`, `FabricUIManager.onTransactionAvailable`) for the pull model Reviewed By: rubennorte Differential Revision: D112309050 fbshipit-source-id: 01a09018df9833c839687b66b289c67f9fc3b9d4 --- .../react/fabric/FabricUIManager.java | 22 +++++++++++++ .../react/fabric/FabricUIManagerBinding.kt | 2 ++ .../mountitems/PullTransactionMountItem.kt | 33 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PullTransactionMountItem.kt 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]" +}