Segmented control
Backwards-compatible tab segments with a draggable UI-thread indicator and shared selection motion.
npx @swipeui/cli add segmented-controlWhen to use it
- Switching between two to five views of the same content, such as Day, Week and Month.
- Toggling list and grid layouts.
- Short settings with named values, such as Units: Metric or Imperial.
- Filters at the top of a chart.
When not to use it
- Top-level navigation. Use a tab bar.
- More than five options or long labels. Use Top tabs or Select.
- Multiple selection. Use Chip group.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add segmented-control- Adds
components/swipeui/ui/use-segmented-control.ts,components/swipeui/ui/segmented-control.tsx,components/swipeui/ui/use-segment-drag.tsand 13 shared helpers. - Installs uniwind, react-native-reanimated, react-native-worklets, react-native-gesture-handler, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { SegmentedControl } from '@/components/swipeui/ui/segmented-control';
<SegmentedControl
accessibilityLabel="Time range"
options={[
{ value: 'day', label: 'Day' },
{ value: 'week', label: 'Week' },
]}
value={range}
onValueChange={setRange}
/>;The first option is selected by default. The indicator slides on the UI thread and jumps when Reduce Motion is on. Two to five segments work best.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | | — | Segments in reading order. |
value? | | — | Controlled value. |
defaultValue? | | | Initial value. |
onValueChange? | | — | Reports a selection. |
onIntent? | | — | Prefetch intent before a selection. |
sizing? | | | Equal widths or natural content widths; overflow scrolls. |
stretch? | | | Stretch the held highlight. |
grabAnywhere? | | | Hold anywhere to pick along the strip. |
holdDelay? | | | Hold delay in milliseconds. |
swipeToCycle? | | | Swipe to step through enabled choices. |
typeahead? | | | Typed label navigation. |
accessibilityRole? | | | Preserve 1.x tabs, or use choice-radio semantics. |
accessibilityLabel? | | — | Group name. |
disabled? | | | Disable all options. |
haptics? | | | Per-event feedback. |
motion? | | | Shared motion. |
messages? | | | Built-in hints. |
className? | | — | Root classes. |
indicatorShape? | | | Use a capsule for the selection highlight. |
style? | | — | Root style. |
testID? | | — | Identifier; options append their value. |
Segmented control settings
| Prop | Does | Default |
|---|---|---|
| haptics | Enables selection or press feedback | true |
| motion | Overrides the app's motion feel | App feel |
| sizing | Equal or natural widths; overflow scrolls | equal |
| onIntent | Prefetch before accepting a selection | — |
| grabAnywhere | Hold then slide to choose | true |
| stretch | Stretch while held | true |
| swipeToCycle | Swipe to step through choices | false |
| typeahead | Find options by typing | true |
The 1.x tablist/tab roles remain the default for existing compositions. Set accessibilityRole="radiogroup" for choice semantics. Labels stay on one line and scroll instead of shrinking.
Composition and behavior
- options in reading order, each with a value and label.
- Control with value and onValueChange, or defaultValue.
- accessibilityLabel names the whole control.
Behavior and gestures
- Tap a segment and the indicator slides to it.
- Drag the indicator and it follows your finger, landing on the nearest segment when you let go; a quick flick carries it further.
- A selection tick plays once per change.
- Disabled controls ignore taps and drags.
Accessibility
- Announced as a tab list, each segment a tab with selected state.
- Segments have extra touch area to reach 44 points.
- Name the control with accessibilityLabel, such as "Time range".
- Labels stay on one line, so keep them short; long labels truncate at large text sizes.
Motion
- Uses the
pressandselectmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The indicator moves with the select spring, carrying your drag speed.
- Reduce Motion makes it jump.
Performance
- Drag and indicator run on the UI thread.
Notes for AI
- Keep to two to five options with short labels.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.