@@ -19,6 +19,9 @@ export type ScheduledGesture = {
19
19
provider : GestureTimeline ,
20
20
count : number , // The number of times this same provider has been started.
21
21
direction : boolean , // false = previous, true = next
22
+ rangePrevious : number , // The end along the timeline where the previous state is reached.
23
+ rangeCurrent : number , // The starting offset along the timeline.
24
+ rangeNext : number , // The end along the timeline where the next state is reached.
22
25
cancel : ( ) => void , // Cancel the subscription to direction change.
23
26
prev : null | ScheduledGesture , // The previous scheduled gesture in the queue for this root.
24
27
next : null | ScheduledGesture , // The next scheduled gesture in the queue for this root.
@@ -28,6 +31,9 @@ export function scheduleGesture(
28
31
root : FiberRoot ,
29
32
provider : GestureTimeline ,
30
33
initialDirection : boolean ,
34
+ rangePrevious : number ,
35
+ rangeCurrent : number ,
36
+ rangeNext : number ,
31
37
) : ScheduledGesture {
32
38
let prev = root . gestures ;
33
39
while ( prev !== null ) {
@@ -42,32 +48,43 @@ export function scheduleGesture(
42
48
}
43
49
prev = next ;
44
50
}
51
+ const isFlippedDirection = rangePrevious > rangeNext ;
45
52
// Add new instance to the end of the queue.
46
- const cancel = subscribeToGestureDirection ( provider , ( direction : boolean ) => {
47
- if ( gesture . direction !== direction ) {
48
- gesture . direction = direction ;
49
- if ( gesture . prev === null && root . gestures !== gesture ) {
50
- // This gesture is not in the schedule, meaning it was already rendered.
51
- // We need to rerender in the new direction. Insert it into the first slot
52
- // in case other gestures are queued after the on-going one.
53
- const existing = root . gestures ;
54
- gesture . next = existing ;
55
- if ( existing !== null ) {
56
- existing . prev = gesture ;
53
+ const cancel = subscribeToGestureDirection (
54
+ provider ,
55
+ rangeCurrent ,
56
+ ( direction : boolean ) => {
57
+ if ( isFlippedDirection ) {
58
+ direction = ! direction ;
59
+ }
60
+ if ( gesture . direction !== direction ) {
61
+ gesture . direction = direction ;
62
+ if ( gesture . prev === null && root . gestures !== gesture ) {
63
+ // This gesture is not in the schedule, meaning it was already rendered.
64
+ // We need to rerender in the new direction. Insert it into the first slot
65
+ // in case other gestures are queued after the on-going one.
66
+ const existing = root . gestures ;
67
+ gesture . next = existing ;
68
+ if ( existing !== null ) {
69
+ existing . prev = gesture ;
70
+ }
71
+ root . gestures = gesture ;
72
+ // Schedule the lane on the root. The Fibers will already be marked as
73
+ // long as the gesture is active on that Hook.
74
+ root . pendingLanes |= GestureLane ;
75
+ ensureRootIsScheduled ( root ) ;
57
76
}
58
- root . gestures = gesture ;
59
- // Schedule the lane on the root. The Fibers will already be marked as
60
- // long as the gesture is active on that Hook.
61
- root . pendingLanes |= GestureLane ;
62
- ensureRootIsScheduled ( root ) ;
77
+ // TODO: If we're currently rendering this gesture, we need to restart it.
63
78
}
64
- // TODO: If we're currently rendering this gesture, we need to restart it.
65
- }
66
- } ) ;
79
+ } ,
80
+ ) ;
67
81
const gesture : ScheduledGesture = {
68
82
provider : provider ,
69
83
count : 1 ,
70
84
direction : initialDirection ,
85
+ rangePrevious : rangePrevious ,
86
+ rangeCurrent : rangeCurrent ,
87
+ rangeNext : rangeNext ,
71
88
cancel : cancel ,
72
89
prev : prev ,
73
90
next : null ,
0 commit comments