segmented-control
segmented-control copied to clipboard
SegmentedControl onChange acts differently on iOS vs Android/Web
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
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: {
``` /