Skip to content

Commit 178e8c9

Browse files
authored
fix(iOS): Distinguish horizontal and vertical scroll in gesture failure requirements (#3420)
Fixes #3302 Supersedes #3304 ## Description This PR fixes the failure requirements for content pop gesture. The changes introduced in #3265 fixed the immediate dismissing of screen when scrolling on horizontal ScrollView, but at the same time introduced a regression for vertical scrolling. Here, we apply the failure requirement only if the ScrollView has horizontal scrolling. ## Changes Updated `RNSScreenStack`'s `gestureRecognizer:shouldRequireFailureOf:otherGestureRecognizer` to check if ScrollView has horizontal scrolling. ### After changes https://github.com/user-attachments/assets/de8bfdaa-aa9b-4c25-917e-2d631bc590df ## Testing Use `Test1072`. Make sure to check custom animations with `animation` and `animationMatchesGesture`.
1 parent 386854f commit 178e8c9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ios/RNSScreenStack.mm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,14 @@ - (BOOL)isScrollViewPanGestureRecognizer:(UIGestureRecognizer *)gestureRecognize
11521152
return scrollView.panGestureRecognizer == gestureRecognizer;
11531153
}
11541154

1155+
// Check if ScrollView has horizontal scrolling.
1156+
// This is the same logic as in RCTScrollView:
1157+
// https://github.com/facebook/react-native/blob/69b131c2b1627f64f34a534dac4cf48a542e6ea6/packages/react-native/React/Views/ScrollView/RCTScrollView.m#L557
1158+
- (BOOL)scrollViewHasHorizontalPart:(UIScrollView *)scrollView
1159+
{
1160+
return scrollView.contentSize.width > scrollView.frame.size.width;
1161+
}
1162+
11551163
// Custom method for compatibility with iOS < 13.4
11561164
// RNSScreenStackView is a UIGestureRecognizerDelegate for three types of gesture recognizers:
11571165
// RNSPanGestureRecognizer, RNSScreenEdgeGestureRecognizer, _UIParallaxTransitionPanGestureRecognizer
@@ -1253,7 +1261,10 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
12531261
if (@available(iOS 26, *)) {
12541262
if (gestureRecognizer == _controller.interactiveContentPopGestureRecognizer &&
12551263
[self isScrollViewPanGestureRecognizer:otherGestureRecognizer]) {
1256-
return YES;
1264+
// ScrollView should take precedence when scrolling horizontally (it should be required to fail).
1265+
// However, if it does not allow for horizontal scrolling, there should be no such restriction,
1266+
// and swiping horizontally should dismiss the screen.
1267+
return [self scrollViewHasHorizontalPart:static_cast<UIScrollView *>(otherGestureRecognizer.view)];
12571268
}
12581269
}
12591270

@@ -1276,6 +1287,7 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
12761287
}
12771288
#endif // check for iOS >= 26
12781289

1290+
// edge swipe to dismiss should take precedence over scrolling (both horizontally and vertically)
12791291
return isEdgeSwipeGestureRecognizer && [self isScrollViewPanGestureRecognizer:otherGestureRecognizer];
12801292
}
12811293

0 commit comments

Comments
 (0)