This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

滑块

一个与 @react-native-community/slider 兼容的滑块。

Android
iOS
Web
Included in Expo Go
Recommended version:
~57.0.3

一个 Slider 组件,其 API 与 @react-native-community/slider 兼容。它在 Android 上使用 Material 3 Slider,在 iOS 上使用 SwiftUI Slider,在 web 上使用原生 <input type="range"> 元素。

🌐 A Slider component with an API compatible with @react-native-community/slider. It uses a Material 3 Slider on Android, a SwiftUI Slider on iOS, and a native <input type="range"> element on web.

在内部,这个组件封装了平台特定的 @expo/ui 原语:

🌐 Under the hood this component wraps the platform-specific @expo/ui primitives:

如果你需要更底层的控制,请直接使用那些原语。

🌐 If you need lower-level control, use those primitives directly.

安装

🌐 Installation

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

@react-native-community/slider 迁移

🌐 Migrating from @react-native-community/slider

  • 将导入从 import Slider from '@react-native-community/slider' 更新为 import Slider from '@expo/ui/community/slider'
  • onSlidingStartonSlidingCompletetapToSeekStepMarkerrenderStepNumberthumbImageminimumTrackImagemaximumTrackImagetrackImageaccessibilityUnitsaccessibilityIncrementstestIDref.updateValue 尚不支持。
  • 在 iOS 上,maximumTrackTintColorthumbTintColor 没有视觉效果——SwiftUI 的 Slider 只暴露最小(活动)轨迹颜色。minimumTrackTintColor 在两个平台上都有效。

基本用法

🌐 Basic usage

SliderExample.tsx
import { useState } from 'react'; import { Text, View } from 'react-native'; import Slider from '@expo/ui/community/slider'; export default function SliderExample() { const [value, setValue] = useState(0.5); return ( <View> <Slider value={value} onValueChange={setValue} /> <Text>Value: {value.toFixed(3)}</Text> </View> ); }

应用接口

🌐 API

import Slider from '@expo/ui/community/slider';

Component

Slider

Type: React.Element<SliderProps>

A drop-in replacement for @react-native-community/slider. Renders a SwiftUI Slider on iOS, a Material 3 Slider on Android, and a native HTML <input type="range"> on web.

Props for the Slider community drop-in component. Compatible with @react-native-community/slider.

SliderProps

disabled

Optional • Type: boolean • Default: false

If true the user won't be able to move the slider.

inverted

Optional • Type: boolean • Default: false

Reverses the direction of the slider so the maximum value is on the left and the minimum value is on the right.

lowerLimit

Optional • Type: number

The lower limit value of the slider. The user won't be able to slide below this limit.

maximumTrackTintColor

Only for:
Android

Optional • Type: ColorValue

Color of the track to the right of the thumb.

maximumValue

Optional • Type: number • Default: 1

Initial maximum value of the slider.

minimumTrackTintColor

Optional • Type: ColorValue

Color of the track to the left of the thumb.

minimumValue

Optional • Type: number • Default: 0

Initial minimum value of the slider.

onValueChange

Optional • Type: (value: number) => void

Callback continuously called while the user is dragging the slider.

step

Optional • Type: number • Default: 0

Step value of the slider. The value should be between 0 and (maximumValue - minimumValue). A value of 0 means continuous (no snapping).

style

Optional • Type: StyleProp<ViewStyle>

Used to style and layout the Slider.

thumbTintColor

Only for:
Android

Optional • Type: ColorValue

Color of the thumb.

upperLimit

Optional • Type: number

The upper limit value of the slider. The user won't be able to slide above this limit.

value

Optional • Type: number • Default: 0

Initial / current value of the slider. Behaves like the community lib: passing a new value updates the thumb, but live drag emits via onValueChange without needing external state.