Migration from CustomMark to StepMarker
masterCustomMark prop was replaced with StepMarker to align with the @callstack/slider API. If you are upgrading from an older version, you must update your component prop name.repository·master·Indexed 41 days ago
https://github.com/sharcoux/sliderA lightweight slider library for React Native and React Native Web, version 11.0.12. It serves as a drop-in replacement for @react-native-community/slider and provides both single-thumb Slider and two-thumb RangeSlider components. It supports custom rendering for thumbs, tracks, and step markers via the CustomThumb, CustomTrack, and StepMarker props.
CustomMark prop was replaced with StepMarker to align with the @callstack/slider API. If you are upgrading from an older version, you must update your component prop name.Install the slider package using npm to use it in your React Native or React Native Web project.
npm i -S @react-native-assets/sliderYou can pass custom React components to the Slider and RangeSlider to completely change their visual appearance.
Receives the current value as a prop. Use this to render text, icons, or custom shapes as the slider handle.
Receives thickness, vertical, color, and style as props. This allows you to define how the track line is drawn (e.g., dashed, solid, or specific widths).
For Slider, it receives currentValue and markValue.
For RangeSlider, it receives currentValue (as [number, number]) and markValue.
Use this to render visual indicators at specific intervals along the track.
// Example Custom Thumb
const CustomThumb = ({ value }) => {
return <Text>{value}</Text>;
};
// Example Custom Step Marker for RangeSlider
const CustomRangeMark = ({ currentValue, markValue }: { currentValue: [number, number], markValue: number }) => {
const backgroundColor = currentValue[0] > markValue ? 'red' : currentValue[1] < markValue ? 'blue' : 'orange';
return <View style={{ backgroundColor, width: 2, height: 8, position: 'absolute', alignSelf: 'center' }} />;
};The RangeSlider component provides a slider with two thumbs, allowing users to select a range between a minimum and maximum value.
import { RangeSlider } from '@react-native-assets/slider'
<RangeSlider
range={[0, 0]} // set the current slider's value
step={0} // The step for the slider
minimumRange={0} // Minimum range between the two thumbs (defaults as "step")
minimumValue={0} // Minimum value (defaults as 0)
maximumValue={0} // Maximum value (defaults as minimumValue + minimumRange)
crossingAllowed={false} // If true, thumbs can cross over each other
outboundColor='grey' // The track color outside the current range value
inboundColor='grey' // The track color inside the current range value
thumbTintColor='darkcyan' // The color of the slider's thumb
thumbStyle={undefined} // Override the thumb's style
trackStyle={undefined} // Override the tracks' style
minTrackStyle={undefined} // Override the tracks' style for the minimum range
midTrackStyle={undefined} // Override the tracks' style for the middle range
maxTrackStyle={undefined} // Override the tracks' style for the maximum range
vertical={false} // If true, the slider will be drawn vertically
inverted={false} // If true, min value will be on the right, and max on the left
enabled={true} // If false, the slider won't respond to touches anymore
trackHeight={4} // The track's height in pixel
thumbSize={15} // The thumb's size in pixel
thumbImage={undefined} // An image that would represent the thumb
slideOnTap={true} // If true, touching the slider will update its value
onValueChange={undefined} // (range: [number, number]) => boolean | void. Return false to prevent update.
onSlidingStart={undefined} // (range: [number, number]) => void
onSlidingComplete={undefined} // (range: [number, number]) => void
CustomThumb={undefined} // ({ value: number, thumb: 'min' | 'max' }) => JSX.Element
StepMarker={undefined} // Component for marks (replaces CustomMark)
CustomTrack={undefined} // ({ length: number; thickness: number; vertical: boolean; track: 'min' | 'max' ; style: RN.StyleProp<RN.ViewStyle>; color: RN.ColorValue }) => JSX.Element
{...props} // Standard View Props
/>The Slider component provides a single-thumb slider. It is compatible with React Native and React Native Web and follows the same API as @react-native-community/slider.
import { Slider } from '@react-native-assets/slider'
<Slider
value={0} // set the current slider's value
minimumValue={0} // Minimum value (defaults as 0)
maximumValue={0} // Maximum value (defaults as minimumValue + step)
step={0} // The step for the slider (0 means any decimal value within [min, max])
minimumTrackTintColor='grey' // The track color before the current value
maximumTrackTintColor='grey' // The track color after the current value
thumbTintColor='darkcyan' // The color of the slider's thumb
thumbStyle={undefined} // Override the thumb's style
trackStyle={undefined} // Override the tracks' style
minTrackStyle={undefined} // Override the tracks' style for the minimum range
maxTrackStyle={undefined} // Override the tracks' style for the maximum range
vertical={false} // If true, the slider will be drawn vertically
inverted={false} // If true, min value will be on the right, and max on the left
enabled={true} // If false, the slider won't respond to touches anymore
trackHeight={4} // The track's height in pixel
thumbSize={15} // The thumb's size in pixel
thumbImage={undefined} // An image that would represent the thumb
slideOnTap={true} // If true, touching the slider will update its value
onValueChange={undefined} // (value: number) => boolean | void. Return false to prevent update.
onSlidingStart={undefined} // (value: number) => void
onSlidingComplete={undefined} // (value: number) => void
CustomThumb={undefined} // ({ value: number }) => JSX.Element
StepMarker={undefined} // Component for marks (replaces CustomMark)
CustomTrack={undefined} // ({ length: number; thickness: number; vertical: boolean; track: 'min' | 'max' ; style: RN.StyleProp<RN.ViewStyle>; color: RN.ColorValue }) => JSX.Element
{...props} // Standard View Props
/>To customize the visual appearance of marks (ticks/labels) on the slider, you can provide a custom component via the StepMarker prop. This component receives several props to help it determine its state and position relative to the slider's current value.
CustomMarkType PropsWhen implementing a StepMarker, your component will receive the following props:
| Prop | Type | Description |
|---|---|---|
stepMarked | boolean | true if the current slider value matches this specific mark's value. |
currentValue | number or [number, number] | The current active value(s) of the slider (single number for 'slider', array for 'range'). |
index | number | The zero-based index of the mark. |
min | number | The minimum value of the slider. |
max | number | The maximum value of the slider. |
markValue | number | The specific value associated with this mark. |
Note: The currentValue type depends on whether you are using a standard 'slider' or a 'range' slider.
import React from 'react';
import { CustomMarkType } from '@react-native-assets/slider';
// Example of a custom mark component
const MyCustomMark: CustomMarkType<'slider'> = ({
stepMarked,
markValue,
currentValue
}) => {
return (
<View style={{
backgroundColor: stepMarked ? 'blue' : 'gray',
width: 10,
height: 10
}} />
);
};The RangeSlider component is a React Native component used to select a range of values between a minimum and maximum bound. It supports two thumbs (min and max), custom styling for tracks and thumbs, and custom component injection for thumbs, tracks, and step markers.
range: A tuple [number, number] representing the current selection.minimumValue: The lower bound of the slider (defaults to 0).maximumValue: The upper bound of the slider.step: The granularity of the slider movement.minimumRange: The minimum allowed distance between the two thumbs.crossingAllowed: Boolean indicating if the thumbs can cross each other (defaults to false).trackHeight: The thickness of the slider track.thumbSize: The size of the thumbs.outboundColor: Color for the track segments outside the selected range.inboundColor: Color for the track segment inside the selected range.thumbTintColor: Color for the thumbs.trackStyle: Base style for all track segments.minTrackStyle, midTrackStyle, maxTrackStyle: Specific styles for the three track segments (min, mid, and max).thumbStyle: Style for the thumbs.enabled: Whether the slider is interactive.slideOnTap: If true, tapping the track moves the nearest thumb to that position.onValueChange: Callback triggered when the range changes: (range: [number, number]) => boolean | void.onSlidingStart: Callback triggered when the user starts dragging a thumb.onSlidingComplete: Callback triggered when the user releases a thumb.CustomThumb: A component to replace the default thumb. Receives value and thumb ('min' | 'max') as props.CustomTrack: A component to replace the default track. Receives length, thickness, vertical, track ('min' | 'mid' | 'max'), style, and color as props.StepMarker: A component to render marks/steps along the track.import RangeSlider from '@react-native-assets/slider';
<RangeSlider
range={[20, 80]}
minimumValue={0}
maximumValue={100}
step={5}
inboundColor="blue"
outboundColor="grey"
onValueChange={(range) => {
console.log('New range:', range);
}}
/>The Slider component is a React Native component used to select a value from a range. It supports customization of the thumb, track, and marks, and provides callbacks for value changes and sliding lifecycle events.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | minimumValue | The current value of the slider |
minimumValue | number | 0 | The lower bound of the slider range |
maximumValue | number | minimumValue + step | The upper bound of the slider range |
step | number | 0 | The granularity of the slider increments |
onValueChange | (value: number) => boolean | void | - | Callback triggered when the value changes |
onSlidingStart | (value: number) => void | - | Callback triggered when the user starts dragging |
onSlidingComplete | (value: number) => void | - | Callback triggered when the user releases the thumb |
enabled | boolean | true | Whether the slider is interactive |
vertical | boolean | false | Whether the slider is oriented vertically |
inverted | boolean | false | Whether the slider direction is inverted |
slideOnTap | boolean | true | Whether tapping the track moves the thumb to that position |
| Prop | Type | Default | Description |
|---|---|---|---|
thumbTintColor | RN.ColorValue | 'darkcyan' | Color of the thumb |
thumbSize | number | 15 | Diameter/size of the thumb |
thumbStyle | RN.StyleProp<RN.ViewStyle> | - | Custom styles for the thumb |
thumbImage | RN.ImageURISource | - | An image to use instead of a colored thumb |
minimumTrackTintColor | RN.ColorValue | 'grey' | Color of the track from minimumValue to value |
maximumTrackTintColor | RN.ColorValue | 'grey' | Color of the track from value to maximumValue |
trackHeight | number | 4 | Thickness of the track |
trackStyle | RN.StyleProp<RN.ViewStyle> | - | Base styles for the track |
minTrackStyle | RN.StyleProp<RN.ViewStyle> | - | Styles specifically for the minimum track segment |
maxTrackStyle | RN.StyleProp<RN.ViewStyle> | - | Styles specifically for the maximum track segment |
style | RN.StyleProp<RN.ViewStyle> | - | Styles for the slider container (ViewProps) |
import Slider from './Slider';
<Slider
minimumValue={0}
maximumValue={100}
step={1}
value={50}
onValueChange={(value) => console.log(value)}
thumbTintColor="red"
trackHeight={10}
/>You can import the default Slider component directly from the package or as a named export Slider.
import Slider from '@react-native-assets/slider';
// or
import { Slider } from '@react-native-assets/slider';You can extend the RangeSlider by providing custom components via the following props:
Pass a component to CustomThumb to change the look of the handles.
Props received by your component:
value: The current numeric value of the thumb.thumb: Either 'min' or 'max'.Pass a component to CustomTrack to change the track rendering.
Props received by your component:
length: The percentage length of the segment.thickness: The height/width of the track.vertical: Boolean indicating if the slider is vertical.track: The segment type: 'min', 'mid', or 'max'.style: The applied style.color: The applied color.Pass a component to StepMarker to render custom marks at specific intervals along the slider.
const MyCustomThumb = ({ value, thumb }: { value: number; thumb: 'min' | 'max' }) => (
<View style={{ width: 20, height: 20, backgroundColor: 'red', borderRadius: 10 }} />
);
<RangeSlider
range={[20, 80]}
CustomThumb={MyCustomThumb}
/>To use a slider that supports multiple handles (a range), import the RangeSlider component as a named export.
import { RangeSlider } from '@react-native-assets/slider';