SegmentedControl

SegmentedControl is an animated segmented control component for React Native and React, from the dissolve library. iOS segmented control whose pill breaks into grains, flows to the new segment and reassembles. Drag across to follow the finger.

An iOS style segmented control whose selection pill is made of grains. At rest it is a clean solid capsule with the soft iOS shadow, on a translucent track that sits on any background. Pick another segment and the pill breaks into grains, leading edge first: they flow to the new segment on a slight arc, shrinking mid flight, and reassemble into the pill there, in about 400 ms. The labels cross fade between their selected and unselected styles along the way. Drag the finger across the control and the selection follows it, the grains re-aiming from wherever they are, with a selection tick on every change. On iOS the pill and every grain are Animated views moved by transform and opacity only, so it keeps animating inside a scroll view that is being dragged. Reduced motion: the pill simply slides.

Install

React Native

Install the engine once per app and wrap the root layout in <DissolveProvider> (see Installation), then copy the component into components/dissolve:

npx expo install dissolve-ui @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-gesture-handler expo-haptics
npx dissolve-ui add segmented-control --native
npx shadcn@latest add https://dissolve.rselmi.com/r/native/segmented-control.json

React

Needs React 19 and react-dom, nothing else: no engine, no provider, no Tailwind. Works in the Next.js App Router.

npx dissolve-ui add segmented-control --web
npx shadcn@latest add https://dissolve.rselmi.com/r/segmented-control.json

Usage

SegmentedControl.tsx (React Native)
import { SegmentedControl } from '@/components/dissolve/segmented-control';

const [period, setPeriod] = useState('Week');
<SegmentedControl segments={['Day', 'Week', 'Month', 'Year']} value={period} onChange={setPeriod} />

// Smaller, uncontrolled, a fixed width.
<SegmentedControl segments={['Inbox', 'Archive']} defaultValue="Inbox" size="sm" className="w-56 self-center" />

// Items with icons.
<SegmentedControl
  segments={[
    { value: 'list', label: 'List', icon: ({ color, size }) => <ListIcon color={color} size={size} /> },
    { value: 'grid', label: 'Grid', icon: ({ color, size }) => <GridIcon color={color} size={size} /> },
  ]}
  value={layout}
  onChange={setLayout}
/>
SegmentedControl.tsx (React)
import { SegmentedControl } from '@/components/dissolve/segmented-control';

const [period, setPeriod] = useState('Week');
<SegmentedControl segments={['Day', 'Week', 'Month', 'Year']} value={period} onChange={setPeriod} />

// Smaller, uncontrolled, a fixed width.
<SegmentedControl segments={['Inbox', 'Archive']} defaultValue="Inbox" size="sm" className="w-56 self-center" />

// Items with icons.
<SegmentedControl
  segments={[
    { value: 'list', label: 'List', icon: ({ color, size }) => <ListIcon color={color} size={size} /> },
    { value: 'grid', label: 'Grid', icon: ({ color, size }) => <GridIcon color={color} size={size} /> },
  ]}
  value={layout}
  onChange={setLayout}
/>

Props

PropTypeDefaultDescription
segments(string | SegmentItem)[]requiredThe segments: plain strings, or { value, label?, icon? } items. icon is a node or a function of { color, size, selected }.
valuestringSelected value (controlled).
defaultValuestringfirst segmentInitial value when uncontrolled.
onChange(value: string, index: number) => voidCalled on every selection change, also while dragging across the segments.
size'sm' | 'md' | 'lg''md'Height, inset and type size: 30, 36 or 44 pt.
hapticsbooleantrueSelection tick on every change.
disabledbooleanfalseNo selection, the control shows at half opacity.
trackColorstringforeground at low alphaTrack fill.
indicatorColorstringbackground / lifted grayPill and grain color. Default: the background token in light mode, a gray lifted off the track in dark mode.
className / labelClassNamestringTrack classes (width, margins, self alignment...) and label classes. It stretches to its parent by default.

Source

Previous: Skeleton · Next: Toggle · All components

dissolve is MIT licensed. Source on GitHub, package on npm. This page as markdown. For AI agents: llms.txt.