This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
滑块
一个用于从范围中选择值的 Jetpack Compose 滑块组件。
信息 有关跨平台用法,请参见通用的
Slider—— 它会根据平台渲染相应的原生组件。
Expo UI Slider 与官方的 Jetpack Compose Slider API 保持一致,并允许从有界范围中选择数值。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础滑块
带自定义范围的滑块
使用 min 和 max 属性来定义滑块的数值范围。
带步进的滑块
使用 steps 属性来定义离散增量。将 steps 设为 0 可表示连续值。
自定义颜色
使用 colors 属性覆盖滑块拇指、轨道和刻度标记的默认 Material3 颜色。
自定义拇指和轨道
同时使用 Slider.Thumb 和 Slider.Track 插槽即可实现完全自定义的滑块外观。
垂直滑块
使用 VerticalSlider 沿垂直轨道选择单个数值。设置 reverseDirection 可使数值从下往上递增,而不是从上往下递增。
API
import { Slider, VerticalSlider } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<SliderProps>
A slider component that wraps Material3's Slider.
SliderColorsColors for slider elements. Maps to Material3's SliderDefaults.colors().
boolean • Default: trueWhether the slider is enabled for user interaction.
numberLower limit the user can drag the thumb to. The visible track still
spans min..max, but the thumb stops at lowerLimit during drag.
number • Default: 1The maximum value of the slider. Updating this value does not trigger callbacks if the current value is above max.
number • Default: 0The minimum value of the slider. Updating this value does not trigger callbacks if the current value is below min.
(value: number) => voidCallback triggered on dragging along the slider.
() => voidCallback triggered when the user finishes changing the value (for example, lifts a finger).
Maps to Material3's onValueChangeFinished.
number • Default: 0The number of steps between the minimum and maximum values, 0 signifies infinite steps.
numberUpper limit the user can drag the thumb to. The visible track still
spans min..max, but the thumb stops at upperLimit during drag.
Type: React.Element<VerticalSliderProps>
A vertical slider component that wraps Material3's VerticalSlider.