Skip to content

Commit db5f538

Browse files
committed
Entangle revert
1 parent 155adb4 commit db5f538

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/react-reconciler/src/ReactFiberGestureScheduler.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ import type {FiberRoot} from './ReactInternalTypes';
1111
import type {GestureOptions} from 'shared/ReactTypes';
1212
import type {GestureTimeline, RunningViewTransition} from './ReactFiberConfig';
1313
import type {TransitionTypes} from 'react/src/ReactTransitionType';
14+
import type {Lane} from './ReactFiberLane';
1415

15-
import {GestureLane, markRootFinished, NoLane, NoLanes} from './ReactFiberLane';
16-
import {ensureRootIsScheduled} from './ReactFiberRootScheduler';
16+
import {
17+
GestureLane,
18+
markRootEntangled,
19+
markRootFinished,
20+
NoLane,
21+
NoLanes,
22+
} from './ReactFiberLane';
23+
import {
24+
ensureRootIsScheduled,
25+
requestTransitionLane,
26+
} from './ReactFiberRootScheduler';
1727
import {getCurrentGestureOffset, stopViewTransition} from './ReactFiberConfig';
1828
import {pingGestureRoot, restartGestureRoot} from './ReactFiberWorkLoop';
1929

@@ -26,6 +36,7 @@ export type ScheduledGesture = {
2636
types: null | TransitionTypes, // Any addTransitionType call made during startGestureTransition.
2737
running: null | RunningViewTransition, // Used to cancel the running transition after we're done.
2838
committing: boolean, // If the gesture was released in a committed state and should actually commit.
39+
revertLane: Lane, // The Lane that we'll use to schedule the revert.
2940
prev: null | ScheduledGesture, // The previous scheduled gesture in the queue for this root.
3041
next: null | ScheduledGesture, // The next scheduled gesture in the queue for this root.
3142
};
@@ -54,6 +65,7 @@ export function scheduleGesture(
5465
types: null,
5566
running: null,
5667
committing: false,
68+
revertLane: NoLane, // Starts uninitialized.
5769
prev: prev,
5870
next: null,
5971
};
@@ -119,6 +131,13 @@ export function cancelScheduledGesture(
119131
root: FiberRoot,
120132
gesture: ScheduledGesture,
121133
): void {
134+
// Entangle any Transitions started in this event with the revertLane of the gesture
135+
// so that we commit them all together.
136+
if (gesture.revertLane !== NoLane) {
137+
const entangledLanes = gesture.revertLane | requestTransitionLane(null);
138+
markRootEntangled(root, entangledLanes);
139+
}
140+
122141
gesture.count--;
123142
if (gesture.count === 0) {
124143
// If the end state is closer to the end than the beginning then we commit into the

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,14 @@ function dispatchOptimisticSetState<S, A>(
37923792
if (provider !== null) {
37933793
// If this was a gesture, ensure we have a scheduled gesture and that
37943794
// we associate this update with this specific gesture instance.
3795-
update.gesture = scheduleGesture(root, provider);
3795+
const gesture = (update.gesture = scheduleGesture(root, provider));
3796+
// Ensure the gesture always uses the same revert lane. This can happen for
3797+
// two startGestureTransition calls to the same provider in different events.
3798+
if (gesture.revertLane === NoLane) {
3799+
gesture.revertLane = update.revertLane;
3800+
} else {
3801+
update.revertLane = gesture.revertLane;
3802+
}
37963803
}
37973804
}
37983805
}

0 commit comments

Comments
 (0)