-
Notifications
You must be signed in to change notification settings - Fork 581
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
feat(DIA-1015): allow FancySwipe to prevent left and/or right swiping #11357
base: main
Are you sure you want to change the base?
Conversation
const onSwipeHandler = (swipeDirection: "right" | "left", toValueY?: number) => { | ||
const sign = swipeDirection === "left" ? -1 : 1 | ||
// Move the card off the screen | ||
const handleLeftSwipe = (toValueY?: number) => { |
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.
This refactor duplicates the handler method for left and right swipes, and in return, I think it makes the component easier to read and extend in the future.
swipeRight() | ||
await waitFor(() => expect(mockOnSwipeRight).toHaveBeenCalledOnce()) | ||
}) | ||
}) |
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.
I wanted to add a test to assert that omitting the onSwipeLeft
and onSwipeRight
handler does not cause the top card to be removed when a user performs that action. However, I realized that FancySwiper is not responsible for removing the top card, so that test belongs to the parent components that use this component.
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.
Impressive work and nice UX. I like the bounciness there 💟
duration: 300, | ||
useNativeDriver: true, | ||
}).start(() => { | ||
removeCardFromTop(swipeDirection) | ||
// revert the pan responder to its initial position |
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.
nitpick: I see you are not using the friction as in from line 42 to 46.
Animated.spring(swiper, { toValue: { x: 0, y: 0 }, friction: 5, useNativeDriver: true, }).start()
It might a nice idea to consolidate both into one method
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.
also line 75
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.
impressive
This PR updates the FancySwiper component to make right swiping optional since Infinite Discovery will only allow users to swipe in one direction. (I also added the option to make left swiping optional for the sake of symmetry.)
Simulator.Screen.Recording.-.iPhone.16.Plus.-.2025-01-09.at.13.34.18.mp4
PR Checklist
To the reviewers 👀
Changelog updates
Changelog updates
Cross-platform user-facing changes
iOS user-facing changes
Android user-facing changes
Dev changes
Need help with something? Have a look at our docs, or get in touch with us.