Skip to content

SegmentedControl onChange acts differently on iOS vs Android/Web #889

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

Open
VNDRN opened this issue Sep 6, 2024 · 1 comment
Open

SegmentedControl onChange acts differently on iOS vs Android/Web #889

VNDRN opened this issue Sep 6, 2024 · 1 comment

Comments

@VNDRN
Copy link

VNDRN commented Sep 6, 2024

Hi,
We noticed that pressing the selected item in the segmented control triggers the onChange and onValueChange every time on android or web but it doesn't on iOS. Only pressing an unselected item triggers the onChange.

This behaviour should be the same on both android & iOS.

Tapping an active segment should never call the onChange orValueChange handlers, since there is no change in the state. Perhaps an onPress can be added that triggers the event on every press?

Reproducible example

https://snack.expo.dev/gfEAxSb7j4Pd5uGSENPVw

Notice the difference when running the snack on iOS vs on android

@VNDRN
Copy link
Author

VNDRN commented Sep 6, 2024

diff --git a/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js b/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js
index 99bdc2e..488e1b4 100644
--- a/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js
+++ b/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js
@@ -44,6 +44,7 @@ const SegmentedControl = ({
   const animation = React.useRef(new Animated.Value(0)).current;

   const handleChange = (index: number) => {
+    if(index===selectedIndex) return;
     // mocks iOS's nativeEvent
     const event: any = {
       nativeEvent: {
``` /

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

No branches or pull requests

1 participant