Skip to content

fix: Prevent SegmentedControl from interfering with scrolling in ScrollViews#919

Open
sandeepsengupta wants to merge 1 commit intoreact-native-segmented-control:masterfrom
sandeepsengupta:scroll-fix
Open

fix: Prevent SegmentedControl from interfering with scrolling in ScrollViews#919
sandeepsengupta wants to merge 1 commit intoreact-native-segmented-control:masterfrom
sandeepsengupta:scroll-fix

Conversation

@sandeepsengupta
Copy link

Overview

If a SegmentedControl is placed inside a ScrollView on iOS, scroll gestures starting inside the SegmentedControl will not scroll the ScrollView:

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 ScrollView with a regular (non-scrolling) View. In the non-scrolling View, drag gestures on the SegmentedControl could freely move vertically without being overridden, which is reasonable behavior.

I also tried testing this with a horizontal ScrollView containing just the SegmentedControl, as described in the StackOverflow thread. In that case, with this fix applied, swiping on the SegmentedControl is 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.)

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant