Skip to content

Commit a919d7d

Browse files
Bartlomiej Bloniarzmeta-codesync[bot]
authored andcommitted
Add inert Java plumbing for the Android pull model
Summary: 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 Differential Revision: D112309050
1 parent 2079c22 commit a919d7d

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import androidx.annotation.AnyThread;
2828
import androidx.annotation.Nullable;
2929
import androidx.annotation.UiThread;
30+
import androidx.annotation.VisibleForTesting;
3031
import androidx.core.view.ViewCompat.FocusDirection;
3132
import com.facebook.common.logging.FLog;
3233
import com.facebook.infer.annotation.Assertions;
@@ -65,6 +66,7 @@
6566
import com.facebook.react.fabric.mounting.mountitems.MountItem;
6667
import com.facebook.react.fabric.mounting.mountitems.MountItemFactory;
6768
import com.facebook.react.fabric.mounting.mountitems.PrefetchResourcesMountItem;
69+
import com.facebook.react.fabric.mounting.mountitems.PullTransactionMountItem;
6870
import com.facebook.react.fabric.mounting.mountitems.SynchronousMountItem;
6971
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
7072
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
@@ -1009,6 +1011,26 @@ public void runGuarded() {
10091011
}
10101012
}
10111013

1014+
/**
1015+
* Pull model: called from C++ via JNI (usually on the commit thread) to signal that a transaction
1016+
* is available for {@code surfaceId}. Enqueues a PullTransactionMountItem so the UI thread pulls
1017+
* and applies the transaction itself, preserving mount-item ordering.
1018+
*/
1019+
@SuppressWarnings("unused")
1020+
@AnyThread
1021+
@ThreadConfined(ANY)
1022+
@VisibleForTesting
1023+
void onTransactionAvailable(int surfaceId) {
1024+
FabricUIManagerBinding binding = mBinding;
1025+
if (binding == null) {
1026+
return;
1027+
}
1028+
mMountItemDispatcher.addMountItem(new PullTransactionMountItem(surfaceId, binding));
1029+
if (UiThreadUtil.isOnUiThread()) {
1030+
mMountItemDispatcher.tryDispatchMountItems();
1031+
}
1032+
}
1033+
10121034
@SuppressWarnings("unused")
10131035
@AnyThread
10141036
@ThreadConfined(ANY)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ internal class FabricUIManagerBinding : HybridClassBase() {
8585

8686
external fun reportMount(surfaceId: Int)
8787

88+
external fun pullAndExecuteTransaction(surfaceId: Int)
89+
8890
external fun mergeReactRevision(surfaceId: Int)
8991

9092
fun register(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.fabric.mounting.mountitems
9+
10+
import com.facebook.proguard.annotations.DoNotStripAny
11+
import com.facebook.react.fabric.FabricUIManagerBinding
12+
import com.facebook.react.fabric.mounting.MountingManager
13+
14+
/**
15+
* Pull model mount item. Enqueued (on the commit thread) when C++ notifies that a transaction is
16+
* available for a surface. When it executes on the UI thread it asks C++ to pull the surface's
17+
* pending transaction and apply it synchronously, so the diff + batch construction happens on the
18+
* UI thread instead of the commit thread (matching iOS).
19+
*/
20+
@DoNotStripAny
21+
internal class PullTransactionMountItem(
22+
private val surfaceId: Int,
23+
private val binding: FabricUIManagerBinding,
24+
) : MountItem {
25+
26+
override fun execute(mountingManager: MountingManager) {
27+
binding.pullAndExecuteTransaction(surfaceId)
28+
}
29+
30+
override fun getSurfaceId(): Int = surfaceId
31+
32+
override fun toString(): String = "PullTransactionMountItem [surfaceId: $surfaceId]"
33+
}

0 commit comments

Comments
 (0)