Skip to content

Commit 0a7cf20

Browse files
authored
Remove useSwipeTransition (#32786)
Stacked on #32785. This is now replaced by `startGestureTransition` added in #32785. I also renamed the flag from `enableSwipeTransition` to `enableGestureTransition` to correspond to the new name.
1 parent b286430 commit 0a7cf20

34 files changed

+66
-618
lines changed

packages/react-art/src/ReactFiberConfigART.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,7 @@ export function createViewTransitionInstance(
560560
export type GestureTimeline = null;
561561

562562
export function getCurrentGestureOffset(provider: GestureTimeline): number {
563-
throw new Error('useSwipeTransition is not yet supported in react-art.');
564-
}
565-
566-
export function subscribeToGestureDirection(
567-
provider: GestureTimeline,
568-
currentOffset: number,
569-
directionCallback: (direction: boolean) => void,
570-
): () => void {
571-
throw new Error('useSwipeTransition is not yet supported in react-art.');
563+
throw new Error('startGestureTransition is not yet supported in react-art.');
572564
}
573565

574566
export function clearContainer(container) {

packages/react-debug-tools/src/ReactDebugHooks.js

-22
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
Usable,
1515
Thenable,
1616
ReactDebugInfo,
17-
StartGesture,
1817
} from 'shared/ReactTypes';
1918
import type {
2019
ContextDependency,
@@ -132,9 +131,6 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
132131
if (typeof Dispatcher.useEffectEvent === 'function') {
133132
Dispatcher.useEffectEvent((args: empty) => {});
134133
}
135-
if (typeof Dispatcher.useSwipeTransition === 'function') {
136-
Dispatcher.useSwipeTransition(null, null, null);
137-
}
138134
} finally {
139135
readHookLog = hookLog;
140136
hookLog = [];
@@ -753,23 +749,6 @@ function useEffectEvent<Args, F: (...Array<Args>) => mixed>(callback: F): F {
753749
return callback;
754750
}
755751

756-
function useSwipeTransition<T>(
757-
previous: T,
758-
current: T,
759-
next: T,
760-
): [T, StartGesture] {
761-
nextHook();
762-
hookLog.push({
763-
displayName: null,
764-
primitive: 'SwipeTransition',
765-
stackError: new Error(),
766-
value: current,
767-
debugInfo: null,
768-
dispatcherHookName: 'SwipeTransition',
769-
});
770-
return [current, () => () => {}];
771-
}
772-
773752
const Dispatcher: DispatcherType = {
774753
readContext,
775754

@@ -796,7 +775,6 @@ const Dispatcher: DispatcherType = {
796775
useMemoCache,
797776
useCacheRefresh,
798777
useEffectEvent,
799-
useSwipeTransition,
800778
};
801779

802780
// create a proxy to throw a custom error

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

+6-46
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,9 @@ export function cloneRootViewTransitionContainer(
13581358

13591359
const containerParent = containerInstance.parentNode;
13601360
if (containerParent === null) {
1361-
throw new Error('Cannot use a useSwipeTransition() in a detached root.');
1361+
throw new Error(
1362+
'Cannot use a startGestureTransition() on a detached root.',
1363+
);
13621364
}
13631365

13641366
const clone: HTMLElement = containerInstance.cloneNode(false);
@@ -1464,7 +1466,9 @@ export function removeRootViewTransitionClone(
14641466
}
14651467
const containerParent = containerInstance.parentNode;
14661468
if (containerParent === null) {
1467-
throw new Error('Cannot use a useSwipeTransition() in a detached root.');
1469+
throw new Error(
1470+
'Cannot use a startGestureTransition() on a detached root.',
1471+
);
14681472
}
14691473
// We assume that the clone is still within the same parent.
14701474
containerParent.removeChild(clone);
@@ -2172,50 +2176,6 @@ export function getCurrentGestureOffset(provider: GestureTimeline): number {
21722176
return typeof time === 'number' ? time : time.value;
21732177
}
21742178

2175-
export function subscribeToGestureDirection(
2176-
provider: GestureTimeline,
2177-
currentOffset: number,
2178-
directionCallback: (direction: boolean) => void,
2179-
): () => void {
2180-
if (
2181-
typeof ScrollTimeline === 'function' &&
2182-
provider instanceof ScrollTimeline
2183-
) {
2184-
// For ScrollTimeline we optimize to only update the current time on scroll events.
2185-
const element = provider.source;
2186-
const scrollCallback = () => {
2187-
const newTime = provider.currentTime;
2188-
if (newTime !== null) {
2189-
const newValue = typeof newTime === 'number' ? newTime : newTime.value;
2190-
if (newValue !== currentOffset) {
2191-
directionCallback(newValue > currentOffset);
2192-
}
2193-
}
2194-
};
2195-
element.addEventListener('scroll', scrollCallback, false);
2196-
return () => {
2197-
element.removeEventListener('scroll', scrollCallback, false);
2198-
};
2199-
} else {
2200-
// For other AnimationTimelines, such as DocumentTimeline, we just update every rAF.
2201-
// TODO: Optimize ViewTimeline using an IntersectionObserver if it becomes common.
2202-
const rafCallback = () => {
2203-
const newTime = provider.currentTime;
2204-
if (newTime !== null) {
2205-
const newValue = typeof newTime === 'number' ? newTime : newTime.value;
2206-
if (newValue !== currentOffset) {
2207-
directionCallback(newValue > currentOffset);
2208-
}
2209-
}
2210-
callbackID = requestAnimationFrame(rafCallback);
2211-
};
2212-
let callbackID = requestAnimationFrame(rafCallback);
2213-
return () => {
2214-
cancelAnimationFrame(callbackID);
2215-
};
2216-
}
2217-
}
2218-
22192179
type EventListenerOptionsOrUseCapture =
22202180
| boolean
22212181
| {

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,9 @@ export function createViewTransitionInstance(
692692
export type GestureTimeline = null;
693693

694694
export function getCurrentGestureOffset(provider: GestureTimeline): number {
695-
throw new Error('useSwipeTransition is not yet supported in React Native.');
696-
}
697-
698-
export function subscribeToGestureDirection(
699-
provider: GestureTimeline,
700-
currentOffset: number,
701-
directionCallback: (direction: boolean) => void,
702-
): () => void {
703-
throw new Error('useSwipeTransition is not yet supported in React Native.');
695+
throw new Error(
696+
'startGestureTransition is not yet supported in React Native.',
697+
);
704698
}
705699

706700
export function clearContainer(container: Container): void {

packages/react-noop-renderer/src/createReactNoop.js

-8
Original file line numberDiff line numberDiff line change
@@ -865,14 +865,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
865865
return 0;
866866
},
867867

868-
subscribeToGestureDirection(
869-
provider: GestureTimeline,
870-
currentOffset: number,
871-
directionCallback: (direction: boolean) => void,
872-
): () => void {
873-
return () => {};
874-
},
875-
876868
resetTextContent(instance: Instance): void {
877869
instance.text = null;
878870
},

packages/react-reconciler/src/ReactFiberApplyGesture.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function recursivelyInsertNewFiber(
412412
// had any effect.
413413
if (finishedWork.flags & Update) {
414414
console.error(
415-
'useSwipeTransition() caused something to render a new <%s>. ' +
415+
'startGestureTransition() caused something to render a new <%s>. ' +
416416
'This is not possible in the current implementation. ' +
417417
"Make sure that the swipe doesn't mount any new <%s> elements.",
418418
finishedWork.type,
@@ -789,7 +789,7 @@ function insertDestinationClonesOfFiber(
789789
commitUpdate(instance, type, oldProps, newProps, finishedWork);
790790
if (viewTransitionMutationContext) {
791791
console.error(
792-
'useSwipeTransition() caused something to mutate <%s>. ' +
792+
'startGestureTransition() caused something to mutate <%s>. ' +
793793
'This is not possible in the current implementation. ' +
794794
"Make sure that the swipe doesn't update any state which " +
795795
'causes <%s> to change.',
@@ -977,10 +977,10 @@ export function insertDestinationClones(
977977
if (!didWarnForRootClone) {
978978
didWarnForRootClone = true;
979979
console.warn(
980-
'useSwipeTransition() caused something to mutate or relayout the root. ' +
980+
'startGestureTransition() caused something to mutate or relayout the root. ' +
981981
'This currently requires a clone of the whole document. Make sure to ' +
982982
'add a <ViewTransition> directly around an absolutely positioned DOM node ' +
983-
'to minimize the impact of any changes caused by the Swipe Transition.',
983+
'to minimize the impact of any changes caused by the Gesture Transition.',
984984
);
985985
}
986986
}

packages/react-reconciler/src/ReactFiberConcurrentUpdates.js

+1-27
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ import {
2424
throwIfInfiniteUpdateLoopDetected,
2525
getWorkInProgressRoot,
2626
} from './ReactFiberWorkLoop';
27-
import {
28-
NoLane,
29-
NoLanes,
30-
mergeLanes,
31-
markHiddenUpdate,
32-
markRootUpdated,
33-
GestureLane,
34-
} from './ReactFiberLane';
27+
import {NoLane, NoLanes, mergeLanes, markHiddenUpdate} from './ReactFiberLane';
3528
import {NoFlags, Placement, Hydrating} from './ReactFiberFlags';
3629
import {HostRoot, OffscreenComponent} from './ReactWorkTags';
3730
import {OffscreenVisible} from './ReactFiberActivityComponent';
@@ -176,25 +169,6 @@ export function enqueueConcurrentRenderForLane(
176169
return getRootForUpdatedFiber(fiber);
177170
}
178171

179-
export function enqueueGestureRender(fiber: Fiber): FiberRoot | null {
180-
// We can't use the concurrent queuing for these so this is basically just a
181-
// short cut for marking the lane on the parent path. It is possible for a
182-
// gesture render to suspend and then in the gap get another gesture starting.
183-
// However, marking the lane doesn't make much different in this case because
184-
// it would have to call startGesture with the same exact provider as was
185-
// already rendering. Because otherwise it has no effect on the Hook itself.
186-
// TODO: We could potentially solve this case by popping a ScheduledGesture
187-
// off the root's queue while we're rendering it so that it can't dedupe
188-
// and so new startGesture with the same provider would create a new
189-
// ScheduledGesture which goes into a separate render pass anyway.
190-
// This is such an edge case it probably doesn't matter much.
191-
const root = markUpdateLaneFromFiberToRoot(fiber, null, GestureLane);
192-
if (root !== null) {
193-
markRootUpdated(root, GestureLane);
194-
}
195-
return root;
196-
}
197-
198172
// Calling this function outside this module should only be done for backwards
199173
// compatibility and should always be accompanied by a warning.
200174
export function unsafe_markUpdateLaneFromFiberToRoot(

packages/react-reconciler/src/ReactFiberConfigWithNoMutation.js

-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@ export type ViewTransitionInstance = null | {name: string, ...};
5858
export const createViewTransitionInstance = shim;
5959
export type GestureTimeline = any;
6060
export const getCurrentGestureOffset = shim;
61-
export const subscribeToGestureDirection = shim;

packages/react-reconciler/src/ReactFiberGestureScheduler.js

+1-82
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ import {
1717
includesTransitionLane,
1818
} from './ReactFiberLane';
1919
import {ensureRootIsScheduled} from './ReactFiberRootScheduler';
20-
import {
21-
subscribeToGestureDirection,
22-
getCurrentGestureOffset,
23-
stopViewTransition,
24-
} from './ReactFiberConfig';
20+
import {getCurrentGestureOffset, stopViewTransition} from './ReactFiberConfig';
2521

2622
// This type keeps track of any scheduled or active gestures.
2723
export type ScheduledGesture = {
@@ -31,85 +27,11 @@ export type ScheduledGesture = {
3127
rangePrevious: number, // The end along the timeline where the previous state is reached.
3228
rangeCurrent: number, // The starting offset along the timeline.
3329
rangeNext: number, // The end along the timeline where the next state is reached.
34-
cancel: () => void, // Cancel the subscription to direction change. // TODO: Delete this.
3530
running: null | RunningViewTransition, // Used to cancel the running transition after we're done.
3631
prev: null | ScheduledGesture, // The previous scheduled gesture in the queue for this root.
3732
next: null | ScheduledGesture, // The next scheduled gesture in the queue for this root.
3833
};
3934

40-
// TODO: Delete this when deleting useSwipeTransition.
41-
export function scheduleGestureLegacy(
42-
root: FiberRoot,
43-
provider: GestureTimeline,
44-
initialDirection: boolean,
45-
rangePrevious: number,
46-
rangeCurrent: number,
47-
rangeNext: number,
48-
): ScheduledGesture {
49-
let prev = root.pendingGestures;
50-
while (prev !== null) {
51-
if (prev.provider === provider) {
52-
// Existing instance found.
53-
prev.count++;
54-
return prev;
55-
}
56-
const next = prev.next;
57-
if (next === null) {
58-
break;
59-
}
60-
prev = next;
61-
}
62-
const isFlippedDirection = rangePrevious > rangeNext;
63-
// Add new instance to the end of the queue.
64-
const cancel = subscribeToGestureDirection(
65-
provider,
66-
rangeCurrent,
67-
(direction: boolean) => {
68-
if (isFlippedDirection) {
69-
direction = !direction;
70-
}
71-
if (gesture.direction !== direction) {
72-
gesture.direction = direction;
73-
if (gesture.prev === null && root.pendingGestures !== gesture) {
74-
// This gesture is not in the schedule, meaning it was already rendered.
75-
// We need to rerender in the new direction. Insert it into the first slot
76-
// in case other gestures are queued after the on-going one.
77-
const existing = root.pendingGestures;
78-
gesture.next = existing;
79-
if (existing !== null) {
80-
existing.prev = gesture;
81-
}
82-
root.pendingGestures = gesture;
83-
// Schedule the lane on the root. The Fibers will already be marked as
84-
// long as the gesture is active on that Hook.
85-
root.pendingLanes |= GestureLane;
86-
ensureRootIsScheduled(root);
87-
}
88-
// TODO: If we're currently rendering this gesture, we need to restart it.
89-
}
90-
},
91-
);
92-
const gesture: ScheduledGesture = {
93-
provider: provider,
94-
count: 1,
95-
direction: initialDirection,
96-
rangePrevious: rangePrevious,
97-
rangeCurrent: rangeCurrent,
98-
rangeNext: rangeNext,
99-
cancel: cancel,
100-
running: null,
101-
prev: prev,
102-
next: null,
103-
};
104-
if (prev === null) {
105-
root.pendingGestures = gesture;
106-
} else {
107-
prev.next = gesture;
108-
}
109-
ensureRootIsScheduled(root);
110-
return gesture;
111-
}
112-
11335
export function scheduleGesture(
11436
root: FiberRoot,
11537
provider: GestureTimeline,
@@ -133,7 +55,6 @@ export function scheduleGesture(
13355
rangePrevious: -1,
13456
rangeCurrent: -1,
13557
rangeNext: -1,
136-
cancel: () => {}, // TODO: Delete this with useSwipeTransition.
13758
running: null,
13859
prev: prev,
13960
next: null,
@@ -210,8 +131,6 @@ export function cancelScheduledGesture(
210131
): void {
211132
gesture.count--;
212133
if (gesture.count === 0) {
213-
const cancelDirectionSubscription = gesture.cancel;
214-
cancelDirectionSubscription();
215134
// Delete the scheduled gesture from the pending queue.
216135
deleteScheduledGesture(root, gesture);
217136
// TODO: If we're currently rendering this gesture, we need to restart the render

0 commit comments

Comments
 (0)