SwipeUI

Segmented control

Backwards-compatible tab segments with a draggable UI-thread indicator and shared selection motion.

npx @swipeui/cli add segmented-control
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.ts and 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 install so versions match your SDK.

Usage

app/stats.tsx
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

PropTypeDefaultDescription
optionsreadonly SegmentedControlOption<T>[]—

Segments in reading order.

value?T—

Controlled value.

defaultValue?Tfirst enabled option

Initial value.

onValueChange?((value: T) => void)—

Reports a selection.

onIntent?((value: T) => void)—

Prefetch intent before a selection.

sizing?"equal" | "fit"'equal'

Equal widths or natural content widths; overflow scrolls.

stretch?booleantrue

Stretch the held highlight.

grabAnywhere?booleantrue

Hold anywhere to pick along the strip.

holdDelay?number350

Hold delay in milliseconds.

swipeToCycle?booleanfalse

Swipe to step through enabled choices.

typeahead?booleantrue

Typed label navigation.

accessibilityRole?"radiogroup" | "tablist"'tablist'

Preserve 1.x tabs, or use choice-radio semantics.

accessibilityLabel?string—

Group name.

disabled?booleanfalse

Disable all options.

haptics?boolean | SelectionHapticstrue

Per-event feedback.

motion?MotionOverrideapp feel

Shared motion.

messages?Partial<SelectionMessages>English

Built-in hints.

className?string—

Root classes.

indicatorShape?"pill" | "preset"'preset'

Use a capsule for the selection highlight.

style?StyleProp<ViewStyle>—

Root style.

testID?string—

Identifier; options append their value.

Segmented control settings

PropDoesDefault
hapticsEnables selection or press feedbacktrue
motionOverrides the app's motion feelApp 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 press and select motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items