Skip to content

feat: support the momentary prop on Android and web - #963

Merged
Naturalclar merged 1 commit into
react-native-segmented-control:masterfrom
officialasishkumar:feat/android-web-momentary
Nov 29, 2026
Merged

Naturalclar merged 1 commit into
react-native-segmented-control:masterfrom
officialasishkumar:feat/android-web-momentary

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Overview

momentary only worked on iOS. On Android and web the prop was ignored: the slider and the bold active label stayed on the selected segment, and tapping that segment again did nothing. Fixes #868.

<SegmentedControl values={['One', 'Two']} momentary onValueChange={...} />

With momentary set, the JS control (Android and web) now behaves like iOS's momentary UISegmentedControl:

  • selectedIndex is not shown: the slider isn't rendered, all separators stay visible, and no segment gets the active label style or accessibilityState.selected.
  • Every tap calls onChange / onValueChange, including repeated taps on the same segment. Tabs still give the usual press feedback.

The README now lists momentary for iOS, Android and Web.

Test Plan

  • Added jest tests for a momentary control: no segment is marked selected, no slider is rendered after layout (and it does render once momentary is turned off), and repeated taps on the same segment each fire both callbacks. The new tests fail without the change.
  • pnpm exec jest --runInBand, pnpm lint and pnpm flow check pass locally. The example app already has a momentary control, which now also applies on Android.

`momentary` was only honoured on iOS, where UISegmentedControl's
`isMomentary` stops a tapped segment from staying selected. The
JavaScript implementation used on Android and web ignored it, so the
control kept showing the slider and the bold active label, and tapping
the selected segment again did nothing.

When `momentary` is set, the JavaScript control now ignores
`selectedIndex` for display purposes:

- the slider is not rendered and every separator stays visible;
- no segment gets the active label style or `accessibilityState.selected`;
- every tap calls `onChange`/`onValueChange`, including repeated taps on
  the same segment, matching the native iOS behaviour.

The README now lists the prop for iOS, Android and Web, and unit tests
cover the rendering and callback behaviour.

Fixes react-native-segmented-control#868

@Naturalclar Naturalclar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! I also checked it on web and on an Android emulator.

@Naturalclar
Naturalclar merged commit 6e4ede6 into react-native-segmented-control:master Nov 29, 2026
6 checks passed
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.

Support for momentaryin Android

2 participants