-
Notifications
You must be signed in to change notification settings - Fork 47.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing range option to useSwipeTransition #32412
Conversation
14a2d6c
to
a225489
Compare
a225489
to
9551248
Compare
…t is Also, let you specify this as options. This lets you model more than three states along a timeline by clamping them. It also allows specifying the "current" offset as something different than what it was when the gesture started such as if it has to start scroll has already happened.
This avoids a case where we'd switch to previous when returning to 0 where 0 was also the starting point.
f40fe8d
to
a9526df
Compare
currentOffset < rangeCurrent | ||
? isFlippedDirection | ||
: currentOffset > rangeCurrent | ||
? !isFlippedDirection | ||
: // Otherwise, look for an explicit option. | ||
gestureOptions && gestureOptions.direction === 'next' | ||
? true | ||
: gestureOptions && gestureOptions.direction === 'previous' | ||
? false | ||
: // If no option is specified, imply from the values specified. | ||
queue.initialDirection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nested ternaries are tough to reason about here. Might be more readable in if blocks.
Took some stepping through to realize we only look for the gestureOptions.direction
or queue.initialDirection
if the currentOffset is the rangeCurrent. I had expected an explicit direction object to override when available. But I guess it makes sense to base off movement because even a one-way gesture needs to be able to reset if its pulled back the other way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see from the next PR that the movement may have started before the scroll event. Which the currentOffset can represent here.
Stacked on #32379 Track the range offsets along the timeline where previous/current/next is. This can also be specified as an option. This lets you model more than three states along a timeline by clamping them and then updating the "current" as you go. It also allows specifying the "current" offset as something different than what it was when the gesture started such as if it has to start after scroll has already happened (such as what happens if you listen to the "scroll" event). DiffTrain build for [662957c](662957c)
Stacked on #32412. To effectively `useSwipeTransition` you need something to start and stop the gesture as well as triggering an Action. This adds an example Gesture Recognizer to the fixture. Instead of having this built-in to React itself, instead the idea is to leave this to various user space Component libraries. It can be done in different ways for different use cases. It could use JS driven or native ScrollTimeline or both. This example uses a native scroll with scroll snapping to two edges. If you swipe far enough to snap to the other edge, it triggers an Action at the end. This particular example uses a `position: sticky` to wrap the content of the Gesture Recognizer. This means that it's inert by itself. It doesn't scroll its content just like a plain JS recognizer using pointer events would. This is useful because it means that scrolling doesn't affect content before we start (the "scroll" event fires after scrolling has already started) so we don't have to both trying to start it earlier. It also means that scrolling doesn't affect the live content which can lead to unexpected effects on the View Transition. I find the inert recognizer the most useful pairing with `useSwipeTransition` but it's not the only way to do it. E.g. you can also have a scrollable surface that uses plain scrolling with snapping and then just progressively enhances swiping between steps.
Stacked on #32379
Track the range offsets along the timeline where previous/current/next is. This can also be specified as an option. This lets you model more than three states along a timeline by clamping them and then updating the "current" as you go.
It also allows specifying the "current" offset as something different than what it was when the gesture started such as if it has to start after scroll has already happened (such as what happens if you listen to the "scroll" event).