-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Use ReanimatedModal in Search Router Modal #65250
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
Merged
mountiny
merged 12 commits into
Expensify:main
from
software-mansion-labs:feat/use-reanimated-modal-in-search-router-modal
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
037b3c5
fix PR comments
jmusial 470e4b9
add swipability to reanimated modal, use reanimated modal in search r…
jmusial 65a6105
only enable ReanimatedModal on small screens
jmusial bbd5c04
use animation utils for web backdrop
jmusial 8000941
Merge remote-tracking branch 'origin/main' into feat/use-reanimated-m…
jmusial daf3b2d
Merge branch 'main' into feat/use-reanimated-modal-in-search-router-m…
jmusial 30e17af
was crashing otherwise
jmusial 8b4cc7e
Merge branch 'main' into feat/use-reanimated-modal-in-search-router-m…
jmusial ad2647b
Merge branch 'main' into feat/use-reanimated-modal-in-search-router-m…
jmusial 0ec5424
Merge branch 'main' into feat/use-reanimated-modal-in-search-router-m…
jmusial c7fa33e
fix PR comments
jmusial cff2bd9
remove typo
jmusial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/components/Modal/ReanimatedModal/Container/GestureHandler.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type {PropsWithChildren} from 'react'; | ||
| import React, {useMemo} from 'react'; | ||
| import type {GestureStateChangeEvent, GestureType, PanGestureHandlerEventPayload} from 'react-native-gesture-handler'; | ||
| import {Gesture, GestureDetector} from 'react-native-gesture-handler'; | ||
| import {runOnJS, useSharedValue} from 'react-native-reanimated'; | ||
| import type {GestureHandlerProps, SwipeDirection} from '@components/Modal/ReanimatedModal/types'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| function hasSwipeEnded( | ||
| e: GestureStateChangeEvent<PanGestureHandlerEventPayload>, | ||
| initialPosition: {x: number; y: number}, | ||
| swipeThreshold: number, | ||
| swipeDirection?: SwipeDirection | SwipeDirection[], | ||
| onSwipeComplete?: () => void, | ||
| ) { | ||
| 'worklet'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/prefer-optional-chain | ||
| if (!swipeDirection || !swipeDirection?.length || !onSwipeComplete) { | ||
| return; | ||
| } | ||
| const directions = Array.isArray(swipeDirection) ? swipeDirection : [swipeDirection]; | ||
|
|
||
| for (const direction of directions) { | ||
| switch (direction) { | ||
| case CONST.SWIPE_DIRECTION.RIGHT: | ||
| if (e.translationX - initialPosition.x > swipeThreshold) { | ||
| runOnJS(onSwipeComplete)(); | ||
| } | ||
| break; | ||
| case CONST.SWIPE_DIRECTION.LEFT: | ||
| if (initialPosition.x - e.translationX > swipeThreshold) { | ||
| runOnJS(onSwipeComplete)(); | ||
| } | ||
| break; | ||
| case CONST.SWIPE_DIRECTION.UP: | ||
| if (initialPosition.y - e.translationY > swipeThreshold) { | ||
| runOnJS(onSwipeComplete)(); | ||
| } | ||
| break; | ||
| case CONST.SWIPE_DIRECTION.DOWN: | ||
| if (e.translationY - initialPosition.y > swipeThreshold) { | ||
| runOnJS(onSwipeComplete)(); | ||
| } | ||
| break; | ||
| default: | ||
| throw new Error('Unknown swipe direction'); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function GestureHandler({swipeDirection, onSwipeComplete, swipeThreshold = 100, children}: PropsWithChildren<GestureHandlerProps>) { | ||
| const initialTranslationX = useSharedValue(0); | ||
| const initialTranslationY = useSharedValue(0); | ||
| const panGesture: GestureType = useMemo( | ||
| () => | ||
| Gesture.Pan() | ||
| .onStart((e) => { | ||
| initialTranslationX.set(e.translationX); | ||
| initialTranslationY.set(e.translationY); | ||
| }) | ||
| .onEnd((e) => { | ||
| hasSwipeEnded(e, {x: initialTranslationX.get(), y: initialTranslationY.get()}, swipeThreshold, swipeDirection, onSwipeComplete); | ||
| }), | ||
| [initialTranslationX, initialTranslationY, onSwipeComplete, swipeDirection, swipeThreshold], | ||
| ); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/prefer-optional-chain | ||
| if (!swipeDirection || !swipeDirection?.length || !onSwipeComplete) { | ||
| return children; | ||
| } | ||
|
|
||
| return <GestureDetector gesture={panGesture}>{children}</GestureDetector>; | ||
| } | ||
|
|
||
| GestureHandler.displayName = 'GestureHandler'; | ||
|
|
||
| export default GestureHandler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Coming from the #66065 checklist, this option doesn’t work on mWeb, so we have temporarily disabled it on mobile web.