### Run Example App Manually Source: https://github.com/callstack/react-native-slider/blob/main/README.md Manually run the example app by first installing its node modules, then installing pods for iOS, and finally running the app. ```sh npx react-native run- ``` -------------------------------- ### Build and Run Web Example Source: https://github.com/callstack/react-native-slider/blob/main/example-web/README.md Follow these steps to build the library and run the development server for the web example. Remember to rebuild the library and restart the server after making changes to the underlying code. ```sh # go to the `package` folder cd ../package # build the library npm run prepare # go back to the example cd ../example-web ``` ```sh npm start ``` -------------------------------- ### Install Dependencies Source: https://github.com/callstack/react-native-slider/blob/main/README.md Install all project dependencies by running this command in the root directory of the repository. ```sh npm install ``` -------------------------------- ### Run Example App Source: https://github.com/callstack/react-native-slider/blob/main/README.md Execute the example application on a specific platform using this command. Replace '' with 'ios', 'android', or 'windows'. ```sh npm run example- ``` -------------------------------- ### Install @react-native-community/slider Source: https://context7.com/callstack/react-native-slider/llms.txt Install the package using npm or yarn. For iOS, ensure CocoaPods are linked. ```bash # npm npm install @react-native-community/slider --save ``` ```bash # yarn yarn add @react-native-community/slider ``` ```bash # iOS – install CocoaPods npx pod-install ``` -------------------------------- ### Install React Native Slider with Yarn Source: https://github.com/callstack/react-native-slider/blob/main/README.md Use this command to add the slider component to your project using Yarn. ```bash yarn add @react-native-community/slider ``` -------------------------------- ### Install React Native Slider with NPM Source: https://github.com/callstack/react-native-slider/blob/main/README.md Use this command to add the slider component to your project using NPM. ```bash npm install @react-native-community/slider --save ``` -------------------------------- ### Basic React Native Slider Usage Source: https://github.com/callstack/react-native-slider/blob/main/README.md This snippet demonstrates the fundamental implementation of the Slider component. Ensure you have installed the library and run `npx pod-install` for iOS. ```javascript import Slider from '@react-native-community/slider'; ``` -------------------------------- ### Continuous Drag Callback with `onValueChange` Source: https://context7.com/callstack/react-native-slider/llms.txt Use `onValueChange` to get real-time updates as the user drags the slider thumb. This is useful for live feedback. ```tsx import React, {useState} from 'react'; import {Text, View} from 'react-native'; import Slider from '@react-native-community/slider'; export default function LiveFeedback() { const [live, setLive] = useState(0); return ( Live value: {live.toFixed(3)} setLive(v)} /> ); } ``` -------------------------------- ### Lint and Test Package Source: https://github.com/callstack/react-native-slider/blob/main/README.md Run these commands to ensure your code adheres to linting rules and passes all tests before contributing. Ensure you are in the package directory. ```sh cd package/ npm run lint npm run test ``` -------------------------------- ### Gesture Lifecycle Callbacks: `onSlidingStart` and `onSlidingComplete` Source: https://context7.com/callstack/react-native-slider/llms.txt Utilize `onSlidingStart` to capture the value when the user begins interacting with the slider and `onSlidingComplete` for the final committed value upon release. ```tsx import React, {useState} from 'react'; import {Text, View} from 'react-native'; import Slider from '@react-native-community/slider'; export default function GestureCallbacks() { const [start, setStart] = useState(null); const [end, setEnd] = useState(null); return ( Started at: {start?.toFixed(3) ?? '—'} Committed: {end?.toFixed(3) ?? '—'} setStart(v)} onSlidingComplete={(v) => setEnd(v)} /> ); } ``` -------------------------------- ### `onSlidingStart` / `onSlidingComplete` — Gesture Lifecycle Callbacks Source: https://context7.com/callstack/react-native-slider/llms.txt These callbacks manage the gesture lifecycle of the slider. `onSlidingStart` is triggered on initial touch, and `onSlidingComplete` is triggered upon release. ```APIDOC ## `onSlidingStart` / `onSlidingComplete` — Gesture Lifecycle Callbacks ### Description `onSlidingStart` fires when the user first touches the slider (receives the value at touch-down). `onSlidingComplete` fires when the user releases the thumb (receives the final committed value). ### Method Callback Functions ### Parameters #### `onSlidingStart` Callback Parameters - **v** (number) - The value of the slider at the moment of touch-down. #### `onSlidingComplete` Callback Parameters - **v** (number) - The final committed value of the slider upon release. ### Request Example ```tsx console.log('Started at:', v)} onSlidingComplete={(v) => console.log('Completed at:', v)} /> ``` ### Response #### Callback Response - **v** (number) - The value relevant to the specific callback (`onSlidingStart` or `onSlidingComplete`). ``` -------------------------------- ### Using Custom Thumb Images with `thumbImage` Source: https://context7.com/callstack/react-native-slider/llms.txt Replace the default slider thumb with a custom image using the `thumbImage` prop. It supports local and network images and is scaled by `thumbSize`. ```tsx import Slider from '@react-native-community/slider'; // Local image thumb // Network image thumb (Windows) ``` -------------------------------- ### Custom Step Marker Component (`StepMarker`) Source: https://context7.com/callstack/react-native-slider/llms.txt Implement a custom component to render markers at each step position. Requires `step > 0` for visible steps. The component receives properties like `stepMarked`, `currentValue`, `index`, `min`, and `max`. ```tsx import React, {FC, useState} from 'react'; import {Text, View} from 'react-native'; import Slider, {MarkerProps} from '@react-native-community/slider'; const DotMarker: FC = ({stepMarked, currentValue, index, max}) => { if (stepMarked) { // Thumb is here — render a callout bubble return ( {index}/{max} ); } // Regular step dot return ( index ? '#1565C0' : '#B0BEC5', }} /> ); }; export default function MarkerSlider() { const [val, setVal] = useState(2); return ( Step: {val} ); } ``` -------------------------------- ### Customizing Thumb Appearance with `thumbTintColor` and `thumbSize` Source: https://context7.com/callstack/react-native-slider/llms.txt Modify the thumb's appearance using `thumbTintColor` (Android only) to tint the default thumb and `thumbSize` to set its width and height. ```tsx import Slider from '@react-native-community/slider'; // Colored, enlarged thumb ``` -------------------------------- ### Built-in Step Number Labels (`renderStepNumber`) Source: https://context7.com/callstack/react-native-slider/llms.txt Enable automatic rendering of numeric labels below the slider track. Requires `step > 0`. Font size adjusts automatically based on the number of steps (≤ 9 steps use a larger font). ```tsx import React, {useState} from 'react'; import {View, Text} from 'react-native'; import Slider from '@react-native-community/slider'; export default function NumberedSteps() { const [val, setVal] = useState(3); return ( Level: {val} ); } ``` -------------------------------- ### Screen Reader Support (`accessibilityUnits`, `accessibilityIncrements`) Source: https://context7.com/callstack/react-native-slider/llms.txt Enhance screen reader announcements by providing custom unit labels and specific labels for each discrete value. Both properties must be used together. ```tsx import Slider from '@react-native-community/slider'; // Screen reader announces: "1 star" instead of "33%" ``` -------------------------------- ### renderStepNumber Source: https://github.com/callstack/react-native-slider/blob/main/README.md Enables the display of step numbers below the slider track. The font size is automatically adjusted based on the total number of steps. ```APIDOC ## `renderStepNumber` ### Description Turns on the displaying of numbers of steps. Numbers of steps are displayed under the track. Two font sizes are available and they will be selected automatically depending on the overall number of steps. ### Usage This is a boolean prop to enable step numbers. ``` -------------------------------- ### Imperative Handle (`ref`, `updateValue`) Source: https://context7.com/callstack/react-native-slider/llms.txt Programmatically control the slider's thumb position on the Web using a forwarded ref. The `updateValue` method can be called to set a specific value without triggering events. ```tsx import React, {useRef} from 'react'; import {Button, View} from 'react-native'; import Slider, {SliderRef} from '@react-native-community/slider'; export default function RefSlider() { const sliderRef = useRef(null); return (