Skip to content

Commit f6fe427

Browse files
authored
Wire up createViewTransitionInstance and suspendOnActiveViewTransition in Fabric (#36196)
## Summary - Wires up the native `fabricCreateViewTransitionInstance` call in `createViewTransitionInstance` which will create a ShadowNode for old pseudo element - Extracts tag allocation logic into a shared `allocateTag()` function exported from `ReactFiberConfigFabric` - Imports `allocateTag` in `ReactFiberConfigFabricWithViewTransition` - Reuses `allocateTag()` in `createInstance` and `createTextInstance` instead of inline tag incrementing - Wires up native `fabricSuspendOnActiveViewTransition` call in `suspendOnActiveViewTransition` which suspends another view transition when the previous one is not yet finished ## Test plan - Existing Fabric renderer tests should continue to pass - ViewTransition instance creation now properly allocates a tag and calls the native module
1 parent fe51601 commit f6fe427

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const {
6060
unstable_ContinuousEventPriority: FabricContinuousPriority,
6161
unstable_IdleEventPriority: FabricIdlePriority,
6262
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
63+
suspendOnActiveViewTransition: fabricSuspendOnActiveViewTransition,
6364
} = nativeFabricUIManager;
6465

6566
import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
@@ -88,6 +89,11 @@ const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
8889
// % 2 === 0 means it is a Fabric tag.
8990
// This means that they never overlap.
9091
let nextReactTag = 2;
92+
export function allocateTag(): number {
93+
const tag = nextReactTag;
94+
nextReactTag += 2;
95+
return tag;
96+
}
9197

9298
type InternalInstanceHandle = Object;
9399

@@ -180,8 +186,7 @@ export function createInstance(
180186
hostContext: HostContext,
181187
internalInstanceHandle: InternalInstanceHandle,
182188
): Instance {
183-
const tag = nextReactTag;
184-
nextReactTag += 2;
189+
const tag = allocateTag();
185190

186191
const viewConfig = getViewConfigForType(type);
187192

@@ -231,8 +236,7 @@ export function createTextInstance(
231236
}
232237
}
233238

234-
const tag = nextReactTag;
235-
nextReactTag += 2;
239+
const tag = allocateTag();
236240

237241
const node = createNode(
238242
tag, // reactTag
@@ -652,7 +656,9 @@ export function suspendInstance(
652656
export function suspendOnActiveViewTransition(
653657
state: SuspendedState,
654658
container: Container,
655-
): void {}
659+
): void {
660+
fabricSuspendOnActiveViewTransition();
661+
}
656662

657663
export function waitForCommitToBeReady(
658664
state: SuspendedState,

packages/react-native-renderer/src/ReactFiberConfigFabricWithViewTransition.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ import type {
1616
GestureTimeline,
1717
} from './ReactFiberConfigFabric';
1818

19+
import {allocateTag} from './ReactFiberConfigFabric';
20+
1921
const {
2022
applyViewTransitionName: fabricApplyViewTransitionName,
23+
createViewTransitionInstance: fabricCreateViewTransitionInstance,
2124
startViewTransition: fabricStartViewTransition,
2225
startViewTransitionReadyFinished: fabricStartViewTransitionReadyFinished,
2326
} = nativeFabricUIManager;
@@ -197,6 +200,8 @@ export function addViewTransitionFinishedListener(
197200
export function createViewTransitionInstance(
198201
name: string,
199202
): ViewTransitionInstance {
203+
const tag = allocateTag();
204+
fabricCreateViewTransitionInstance(name, tag);
200205
return {
201206
name,
202207
old: new (ViewTransitionPseudoElement: any)('old', name),

scripts/flow/react-native-host-hooks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ declare const nativeFabricUIManager: {
213213
name: string,
214214
className: ?string,
215215
) => void,
216+
createViewTransitionInstance: (name: string, tag: number) => void,
216217
startViewTransition: (mutationCallback: () => void) => {
217218
finished: Promise<void>,
218219
ready: Promise<void>,
219220
},
220221
startViewTransitionReadyFinished: () => void,
222+
suspendOnActiveViewTransition: () => void,
221223
...
222224
};

0 commit comments

Comments
 (0)