Elastic slider
A slider that stretches with resistance past its ends, grows its thumb, trails a leaning value tag and holds on detents; ★ the end icon swells with the pull.
npx @swipeui/cli add elastic-sliderWhen to use it
- Sliders that should feel physical, stretching a little when pushed past the end.
- Playful settings such as playback speed or a mood scale.
- Range sliders that should signal the limits clearly.
When not to use it
- Dense forms where a calm slider suits better. Use Slider.
- Precise values. Use Number field.
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 elastic-slider- Adds
components/swipeui/ui/elastic-slider.tsxand 14 shared helpers. - Installs clsx, tailwind-merge, react-native-reanimated, react-native-worklets, uniwind, expo-haptics, class-variance-authority, react-native-svg, react-native-gesture-handler. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ElasticSlider } from '@/components/swipeui/ui/elastic-slider';
<ElasticSlider label="Volume" defaultValue={60} startAdornment={QuietIcon} endAdornment={LoudIcon} />;Examples
Playback speed that holds at 1× and 1.5×:
<ElasticSlider
label="Playback speed"
min={0.5}
max={2}
step={0.05}
detents={[1, 1.5]}
formatValue={(v) => `${v}×`}
/>API reference
ElasticSliderProps
| Prop | Type | Default | Description |
|---|---|---|---|
value? | | — | The value (controlled): a number, or |
defaultValue? | | | The value it starts with (uncontrolled). |
onValueChange? | | — | Reports each new step while dragging, tapping or adjusting. |
onValueCommit? | | — | Reports once when a drag, fling, tap or adjustment settles. |
min? | | | Lowest value. |
max? | | | Highest value; must exceed |
step? | | | The step values snap to. |
range? | | | A range with two thumbs. |
label? | | | The visible and spoken name. |
formatValue? | | | Writes a value for the readout, the bubble and screen readers. |
momentum? | | | A fling carries the value on and snaps to a step. |
showValue? | | | The value beside the label, rolling its digits. |
marks? | | — | Marks on the track; labelled marks can be pressed to set the value. |
minGap? | | | A range's thumbs stay at least this far apart. |
trackPress? | | | A press on the track jumps there, takes one step toward it, or does nothing. |
fineScrub? | | | ★ Drag away from the track to slow the rate to ½, ¼ and ⅛, with a tick and an announcement per band. |
grow? | | | The thumb grows while held. |
startAdornment? | | — | An icon before the track. |
endAdornment? | | — | An icon after the track. |
size? | | | Track and thumb size. |
children? | | — | Content drawn above the track, such as a histogram. |
disabled? | | | No changes. |
haptics? | | | Haptics: a switch, or per part ( |
motion? | | | Thumb, bubble and fling motion (select, drag and number roles). |
messages? | | | Built-in strings. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | Root identifier; parts append |
overscroll? | | | Past an end, the thumb and fill stretch with resistance and spring back: on, off, or the most it can pull in points. |
tag? | | | The value tag over the thumb: while dragging, always, or never. |
tagTilt? | | | The tag trails the thumb on a softer spring and leans with the finger's speed (±8°). |
detents? | | — | Values the thumb holds on to for a few points of travel, with a pop and a tick. |
detentHold? | | | How sticky a detent is, in points. |
adornmentStretch? | | | ★ The end icon swells as the band pulls toward it, like a system volume control. |
Every Slider prop works too (momentum, marks, fine scrubbing, ranges, track presses).
Composition and behavior
- Past either end, the thumb and the fill stretch with growing resistance and spring back on release, with one limit tick.
- ★ Pulling past an end swells that end's icon, like a system volume control.
- The thumb grows while held. A value tag trails it on a softer spring and leans with the finger's speed, up to 8°.
- Detents hold the thumb for a few points of travel, with a pop and a tick.
- Reduce Motion removes the stretch, the lean and the pop; haptics stay.
<Slider elastic>keeps the 1.x rubber band.
Elastic slider settings
| Prop | Does | Default |
|---|---|---|
| overscroll | The rubber band past the ends (on, off, or points) | true (28pt) |
| tag | The value tag: drag, always or never | drag |
| tagTilt | The tag trails and leans with speed | true |
| detents / detentHold | Values the thumb holds on; how sticky (pt) | none, 6 |
| adornmentStretch | ★ The end icon swells with the pull | true |
| grow | The thumb grows while held | true |
| Slider props | min, max, step, marks, momentum, fineScrub, … | as Slider |
Behavior and gestures
- Drag past either end: the thumb and fill stretch with growing resistance (a rubber band) and spring back on release, with one limit tick (`overscroll`).
- ★ Pulling past an end swells that end's icon, like a system volume control (`adornmentStretch`).
- The thumb grows while held; a value tag trails it on a softer spring and leans with the finger's speed, up to 8° (`tag`, `tagTilt`).
- Detents hold the thumb for a few points of travel (`detentHold`) with a pop and a tick (`detents`).
- Everything else is Slider 2.0: momentum, marks, fine scrubbing, ranges, track presses and web keys.
Accessibility
- Thumbs are adjustable (sliders on the web) with increment and decrement; the tag is decorative and the value is spoken through `formatValue`.
- Detents and limits are felt as haptics and never carry meaning alone.
Motion
- Uses the
drag,select,layout,toggleandnumbermotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The band springs back on the select spring with the release velocity; the tag trails on the layout spring; the detent pop runs on the toggle role.
- Reduce Motion removes the stretch, the lean, the trail and the pop; haptics stay.
Performance
- The band, tag and pop run on the UI thread; React hears only new steps, detents and the release.
Notes for AI
- Use it where a physical feel helps (volume, speed, brightness); use Slider for plain form values.
- `overscroll` takes a number for a different pull; `Slider elastic` keeps the 1.x rubber band.
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.