Skip to content

About

Wheel, analog clock and duration dial pickers for React Native, drawn with Skia, animated with Reanimated, with haptic ticks.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

rn-pickers

npm

Three pickers for React Native that share one gesture engine: a ruler-style wheel with momentum and snapping, an analog clock you set by dragging its hands or scrubbing a time strip, and a circular duration dial. Drawn with Skia, animated with Reanimated on the UI thread, with haptic ticks, controlled or uncontrolled values, and screen-reader adjustable actions.

rn-pickers demo

Demo recorded on the iOS Simulator from the example app, shown at 2x speed. Full video: docs/demo.mp4.

Install

npm install @asaddevworld/pickers @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-gesture-handler

With Expo:

npx expo install @asaddevworld/pickers @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-gesture-handler

Requires React Native 0.76 or newer, Skia 2, Reanimated 4, and Gesture Handler 3, with GestureHandlerRootView at the root of the app.

Usage

import { WheelPicker, ClockPicker, DurationDial } from '@asaddevworld/pickers';

<WheelPicker value={weight} min={30} max={200} step={1} majorEvery={10} unit="kg" onChangeEnd={setWeight} />

<ClockPicker value={{ hours: 9, minutes: 30 }} minuteStep={5} onChangeEnd={setTime} />

<DurationDial value={hours} min={1} max={12} unit="h" onChangeEnd={setHours} />

Hook up haptics with any library:

import * as Haptics from 'expo-haptics';

const haptics = (event: 'tick' | 'settle') =>
  event === 'tick' ? Haptics.selectionAsync() : Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);

<WheelPicker haptics={haptics} ... />

API

Shared props

prop type description
value number (or ClockTime) Controlled value.
defaultValue same Starting value when uncontrolled.
onChange (value) => void Fires on every step crossed while dragging.
onChangeEnd (value) => void Fires once the picker settles.
haptics (event: 'tick' | 'settle') => void Called per step and on settle.
theme { tint, track, text, background } Colours. Defaults suit a dark background.
accessibilityLabel string Label for the adjustable control.

WheelPicker

prop default description
min, max, step 0, 100, 1 Range and granularity.
majorEvery 10 Every n-th tick is taller and labelled.
unit Appended to the live value.
expanded false Wider tick spacing, animated when toggled.
formatLabel Worklet that formats the value and the major tick labels.
height 96 Ruler height.
hideValue false Hide the big live value above the ruler.

ClockPicker

prop default description
value / defaultValue { hours: 9, minutes: 0 } { hours, minutes } in 24-hour terms.
size 240 Diameter of the face.
use24Hour false Strip and label show 24-hour times.
minuteStep 5 Minute increments.
hideStrip false Hide the scrubbable time strip under the face.

Drag near the minute hand to set minutes (the hour hand rolls along); drag near the hour hand to set hours. formatClock, toMinutes and toTime are exported helpers.

DurationDial

prop default description
min, max, step 1, 12, 1 Range and granularity.
size 260 Diameter.
unit Appended to the centre value.
thickness 14 Ring thickness.
formatLabel Worklet that formats the centre value and tick labels.

Behaviour notes

  • The wheel follows the finger 1:1, rubber-bands at the ends, and on release projects the velocity to pick the tick it settles on.
  • The dial does not wrap: dragging past the top from the last value, or below the first, holds at the end.
  • Every picker has the adjustable accessibility role with increment and decrement actions.
  • Reduced motion shortens the settle animations.

Example app

yarn
yarn example ios

One screen with the three pickers, their settled values, and toggles for expanded ticks and 24-hour time.

Credits

Inspired by the wheel picker, clock time picker and duration slider demos by Enzo Mangano at reactiive.io. Implemented from scratch for this package.

License

MIT © Asad Ali

About

Wheel, analog clock and duration dial pickers for React Native, drawn with Skia, animated with Reanimated, with haptic ticks.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages