UIPackage React Native
Search

Slider

Themed system slider with the Expo-compatible native implementation.

Install

First install? Set up the registry in your app.

npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add slider

Source files

Expand a file to read the source the installer copies into your app.

components/ui/slider/Slider.tsx
import * as React from 'react'
import NativeSlider from '@react-native-community/slider'
import { cssInterop } from 'react-native-css-interop'
import { useThemeColors } from '@/lib/theme'
import { cn } from '@/lib/utils'

export type SliderProps = Omit<React.ComponentPropsWithoutRef<typeof NativeSlider>, 'ref'> & { className?: string }
const SliderControl = cssInterop(NativeSlider, { className: 'style' })

export const Slider = React.forwardRef<React.ComponentRef<typeof NativeSlider>, SliderProps>(
  ({ className, minimumTrackTintColor, maximumTrackTintColor, thumbTintColor, ...props }, ref) => {
    const colors = useThemeColors()
    return (
      <SliderControl
        {...props}
        ref={ref}
        minimumTrackTintColor={minimumTrackTintColor ?? colors.primary}
        maximumTrackTintColor={maximumTrackTintColor ?? colors.input}
        thumbTintColor={thumbTintColor ?? colors.primary}
        className={cn('min-h-[48px] w-full', className)}
      />
    )
  },
)
Slider.displayName = 'Slider'
components/ui/slider/index.ts
export * from './Slider'

Dependencies

npm packages

  • @react-native-community/slider
  • react-native-css-interop
Browse controls and interactions