Skip to content

fix: skip callbacks for the selected segment - #922

Open
huytdps13400 wants to merge 1 commit into
react-native-segmented-control:masterfrom
huytdps13400:fix/skip-selected-segment-callbacks
Open

huytdps13400 wants to merge 1 commit into
react-native-segmented-control:masterfrom
huytdps13400:fix/skip-selected-segment-callbacks

Conversation

@huytdps13400

Copy link
Copy Markdown

Overview

Pressing the already selected segment currently invokes onChange and onValueChange on Android and web, even though the selection has not changed. Skip those callbacks when the pressed index matches the current selectedIndex, matching the normal iOS behavior.

The comparison uses the index, so two different segments with the same label still notify correctly. The new regression suite exercises the rendered touchables, including controlled prop updates and an initially absent selection, and runs in the existing CI lint job.

Fixes #889.

Test Plan

  • Before the fix: 3 regression tests fail, 6 control tests pass. After the fix: all 9 Jest tests pass using the existing React Native Jest preset and React test renderer.
  • TypeScript check passes. Full ESLint passes with the same 7 existing warnings. Changed-file ESLint and Prettier (--bracket-same-line, matching the repository's legacy jsxBracketSameLine setting) pass.
  • Flow was attempted on the baseline, but flow-bin 0.237.2 ships an x86_64 macOS binary that cannot start on this host (spawn error -86). Flow validation is therefore unverified locally.
  • These are component-level callback tests; no Android device, iOS device, or browser UI run is claimed.

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.

SegmentedControl onChange acts differently on iOS vs Android/Web

1 participant