fix: Prevent SegmentedControl from interfering with scrolling in ScrollViews#919
Open
sandeepsengupta wants to merge 1 commit intoreact-native-segmented-control:masterfrom
Open
Conversation
…llViews If a SegmentedControl is placed inside a ScrollView on iOS, scroll gestures starting inside the SegmentedControl will not scroll the ScrollView. This commit fixes this issue with a solution from: https://stackoverflow.com/a/58193949
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
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.
Overview
If a
SegmentedControlis placed inside aScrollViewon iOS, scroll gestures starting inside theSegmentedControlwill not scroll theScrollView:Screen.Recording.1.mp4
This PR fixes that issue using a solution from https://stackoverflow.com/a/58193949 that involves the gestureRecognizerShouldBegin method. The new behavior looks like this:
Screen.Recording.2.mp4
Test Plan
I tried the tests in the above videos (on iOS 18.5 and iOS 26.2). I also did a basic test in iOS 15.2 with the fix applied - iOS 15.2 behaved the same as iOS 18.5.
Additionally, I tried replacing the
ScrollViewwith a regular (non-scrolling)View. In the non-scrollingView, drag gestures on theSegmentedControlcould freely move vertically without being overridden, which is reasonable behavior.I also tried testing this with a horizontal
ScrollViewcontaining just theSegmentedControl, as described in the StackOverflow thread. In that case, with this fix applied, swiping on theSegmentedControlis disabled entirely, and swiping simply scrolls horizontally. That is reasonable behavior in this situation.(I did most of my testing before adding comments to the code, but this should not matter.)