Slider

Forms

A range slider with a draggable thumb. Supports min, max, step, and controlled value with a smooth Reanimated gesture.

GitHub

Installation

bash
1
npx native-mate add slider

Examples

#FAFAFA
Radius100%

Usage

tsx
1
2
3
4
5
6
7
8
9
10
11
12
import { Slider } from '~/components/ui/slider'
import { useState } from 'react'

const [volume, setVolume] = useState(50)

<Slider
  value={volume}
  onValueChange={setVolume}
  min={0}
  max={100}
  step={5}
/>

Props

PropTypeDefaultDescription
valuenumberControlled current value.
onValueChange(value: number) => voidCalled continuously as the thumb is dragged.
minnumber0Minimum value of the range.
maxnumber100Maximum value of the range.
stepnumber1Snap increment between selectable values.
disabledbooleanfalsePrevents dragging and reduces opacity.

Example

tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useState } from 'react'
import { Slider } from '~/components/ui/slider'
import { Text } from '@native-mate/core'
import { View } from 'react-native'

export function SliderExample() {
  const [brightness, setBrightness] = useState(70)
  const [fontSize, setFontSize] = useState(16)

  return (
    <View style={{ gap: 24, padding: 16 }}>
      <View style={{ gap: 8 }}>
        <Text weight="medium">Brightness: {brightness}%</Text>
        <Slider value={brightness} onValueChange={setBrightness} min={0} max={100} />
      </View>
      <View style={{ gap: 8 }}>
        <Text weight="medium">Font size: {fontSize}px</Text>
        <Slider value={fontSize} onValueChange={setFontSize} min={12} max={24} step={2} />
      </View>
    </View>
  )
}