Created
September 15, 2023 16:51
-
-
Save RaphBlanchet/d260376370b39ee5c9ba7e4c45bcd939 to your computer and use it in GitHub Desktop.
react-native-screens iOS Gestures
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
diff --git a/node_modules/react-native-screens/ios/RNSScreenStack.mm b/node_modules/react-native-screens/ios/RNSScreenStack.mm | |
index b06ffbd..f0b1858 100644 | |
--- a/node_modules/react-native-screens/ios/RNSScreenStack.mm | |
+++ b/node_modules/react-native-screens/ios/RNSScreenStack.mm | |
@@ -896,6 +897,19 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer | |
BOOL isBackGesture = [panGestureRecognizer translationInView:panGestureRecognizer.view].x > 0 && | |
_controller.viewControllers.count > 1; | |
+ // Detects if we are currently at the top of the ScrollView and if the gesture is a swipe down. | |
+ // We consider this only if the scroll is more vertical than horizontal | |
+ UIScrollView *scrollView = (UIScrollView *)otherGestureRecognizer.view; | |
+ CGPoint translation = [panGestureRecognizer translationInView:panGestureRecognizer.view]; | |
+ BOOL shouldDismissWithScrollDown = abs(translation.y) > abs(translation.x) && translation.y > 0 && scrollView.contentOffset.y <= 0; | |
+ if (shouldDismissWithScrollDown) { | |
+ // If we detect a dismiss swipe, we cancel the other gesture recognizer and consider only the screen's one | |
+ // (To cancel a gesture on iOS, we need to disable and re-enable it) | |
+ [otherGestureRecognizer setEnabled:NO]; | |
+ [otherGestureRecognizer setEnabled:YES]; | |
+ return YES; | |
+ } | |
+ | |
if (gestureRecognizer.state == UIGestureRecognizerStateBegan || isBackGesture) { | |
return NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment