-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix drawer swipe #7007
Merged
Merged
Fix drawer swipe #7007
+941
−38
Conversation
This file contains 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
|
gaearon
force-pushed
the
fix-drawer-fr
branch
from
December 8, 2024 20:25
ca4b911
to
ce331fb
Compare
gaearon
force-pushed
the
fix-drawer-fr
branch
from
December 9, 2024 22:10
ce331fb
to
fb5391e
Compare
This is already pretty error-prone. And with tracking whether we're idle it's going to get more complicated. Let's pause and think.
It feels super arbitrary and breaks muscle memory. If the gesture is reliable, we shouldn't need it.
arcalinea
temporarily deployed
to
fix-drawer-fr - social-app PR #7007
December 10, 2024 03:30 — with
Render
Destroyed
arcalinea
temporarily deployed
to
fix-drawer-fr - social-app PR #7007
December 10, 2024 03:43 — with
Render
Destroyed
gaearon
requested review from
pfrazee,
estrattonbailey,
mozzius and
haileyok
December 10, 2024 04:01
haileyok
approved these changes
Dec 10, 2024
satya164
pushed a commit
to react-navigation/react-navigation
that referenced
this pull request
Dec 11, 2024
**Motivation** The drawer gesture can conflict with other gestures in the app. To coordinate multiple gestures, the app code can use APIs like `requireExternalGestureToFail`. However, since the gesture is hidden in the library, this is not currently possible without patching. This exposes the gesture to the app code so you can use `requireExternalGestureToFail` with it. ```js import { DrawerGestureContext } from 'react-native-drawer-layout'; // ... const drawerGesture = useContext(DrawerGestureContext) const nativeGesture = Gesture.Native() .requireExternalGestureToFail(drawerGesture) // ... <GestureDetector gesture={nativeGesture}> <PagerView // ... /> </GestureDetector> ``` Note that the existing `configureGestureHandler` is not enough because we need it in the other direction: *other* gestures (deeper in the app) need access to it. It would not be possible to capture it in a closure because by the point `configureGestureHandler` runs, the owner component has already executed and passed the data down. <s>I opted to use a render prop instead of actually creating a context in order to keep this addition zero-cost. If this was a context exposed by the library, we'd have to either memoize the `pan` gesture (to avoid it getting redefined on drawer re-renders) or we'd have to pay the price of React doing a context search traversal every time it changes. Seems unfortunate if the majority of this library's users don't care about the gesture. Render prop lets the app decide whether it cares.</s> Re-done as context as requested in review. Added some memoization to avoid it changing on every render. **Test plan** Verify you're able to access `gesture` on mobile. On web, it should be `undefined`. Verify you can use it with RNGH APIs as usual. For example, bluesky-social/social-app#7007 fixes a longstanding problem with the Bluesky app — the drawer swipe barely worked on iOS. The reason it has been broken for the last two years is because this library did not expose the gesture, and we did not know that it needs to be coordinated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See main insight in software-mansion/react-native-gesture-handler#3266 (comment).
New approach relies on react-navigation/react-navigation#12326 which I expect to get merged soon.
Test Plan