### Basic React Native Slider Example Source: https://context7.com/sharcoux/slider/llms.txt Demonstrates a basic single-value slider with custom colors, step increments, and tap-to-slide functionality. It utilizes React hooks for state management and provides callbacks for value changes, sliding start, and completion. ```javascript import React, { useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { Slider } from '@react-native-assets/slider'; const BasicSliderExample = () => { const [value, setValue] = useState(50); return ( Value: {value} { setValue(newValue); console.log('Value changed:', newValue); }} onSlidingStart={(value) => console.log('Started sliding:', value)} onSlidingComplete={(value) => console.log('Finished sliding:', value)} style={styles.slider} /> ); }; const styles = StyleSheet.create({ container: { padding: 20 }, slider: { width: 300, height: 40 } }); ``` -------------------------------- ### Install @react-native-assets/slider Source: https://github.com/sharcoux/slider/blob/master/README.md This command installs the slider package as a dependency for your project using npm. Ensure you have npm installed and configured in your project environment. ```bash npm i -S @react-native-assets/slider ``` -------------------------------- ### Vertical React Native Slider Example Source: https://context7.com/sharcoux/slider/llms.txt Illustrates how to implement a vertical slider by setting the `vertical` prop to `true`. The `inverted` prop can be used to control the orientation (top-to-bottom or bottom-to-top). This example shows a volume control slider. ```javascript import React, { useState } from 'react'; import { View, Text } from 'react-native'; import { Slider } from '@react-native-assets/slider'; const VerticalSliderExample = () => { const [volume, setVolume] = useState(50); return ( Volume: {volume}% ); }; ``` -------------------------------- ### Customize Slider Styles (JavaScript) Source: https://context7.com/sharcoux/slider/llms.txt This example demonstrates how to customize the appearance of a single-value Slider component. It utilizes props like `thumbStyle`, `trackStyle`, `minTrackStyle`, and `maxTrackStyle` to define specific visual properties for the thumb and track segments. Dependencies include React, React Native core components, and the Slider component from '@react-native-assets/slider'. ```javascript import React, { useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { Slider } from '@react-native-assets/slider'; const StyledSliderExample = () => { const [brightness, setBrightness] = useState(70); return ( Brightness: {brightness}% ); }; const styles = StyleSheet.create({ container: { padding: 20, alignItems: 'center' }, label: { fontSize: 18, marginBottom: 20, fontWeight: 'bold' } }); ``` -------------------------------- ### Custom Slider Track Rendering with CustomTrack Prop Source: https://context7.com/sharcoux/slider/llms.txt This example demonstrates how to customize the visual appearance of the slider's track using the `CustomTrack` prop. The `CustomTrack` prop accepts a React component that receives track properties like length, thickness, and orientation. This allows for unique styling, such as rendering a dashed track as shown. It utilizes React Native and the Slider component from '@react-native-assets/slider'. ```javascript import React, { useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { Slider } from '@react-native-assets/slider'; const DashedTrack = ({ length, thickness, vertical, color, style }) => ( ); const CustomTrackExample = () => { const [progress, setProgress] = useState(35); return ( Progress: {progress}% ); }; const styles = StyleSheet.create({ container: { padding: 20, alignItems: 'center' }, label: { fontSize: 16, marginBottom: 15, fontWeight: '600' } }); ``` -------------------------------- ### Customize Range Slider Styles (JavaScript) Source: https://context7.com/sharcoux/slider/llms.txt This example shows how to customize the appearance of a RangeSlider component, allowing for distinct styling of the minimum, middle, and maximum track segments. It uses props such as `minTrackStyle`, `midTrackStyle`, and `maxTrackStyle` for segment-specific styling, alongside `thumbStyle` and `trackStyle` for common elements. This is useful for visually representing different states or ranges within a single slider. Dependencies include React, React Native core components, and the RangeSlider component from '@react-native-assets/slider'. ```javascript import React, { useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { RangeSlider } from '@react-native-assets/slider'; const StyledRangeExample = () => { const [tempRange, setTempRange] = useState([18, 24]); return ( Temperature: {tempRange[0]}°C - {tempRange[1]}°C ); }; const styles = StyleSheet.create({ container: { padding: 20, alignItems: 'center' }, label: { fontSize: 16, marginBottom: 15, fontWeight: '600' } }); ``` -------------------------------- ### Prevent Slider Value Changes with onValueChange Callback Source: https://context7.com/sharcoux/slider/llms.txt This example shows how to conditionally prevent the slider's value from updating. By returning `false` within the `onValueChange` callback, the slider's internal value will not change. This is useful for implementing validation logic or allowing updates only under certain conditions. It uses React Native and the Slider component from '@react-native-assets/slider'. ```javascript import React, { useState } from 'react'; import { View, Text, StyleSheet, Button } from 'react-native'; import { Slider } from '@react-native-assets/slider'; const ConditionalSliderExample = () => { const [value, setValue] = useState(50); const [locked, setLocked] = useState(false); const [attemptedValue, setAttemptedValue] = useState(null); return ( Status: {locked ? 'LOCKED 🔒' : 'UNLOCKED 🔓'} Current Value: {value} {attemptedValue !== null && ( Attempted: {attemptedValue} )} { setAttemptedValue(newValue); if (locked) { console.log('Blocked value change:', newValue); return false; // Prevent update } setValue(newValue); setAttemptedValue(null); }} style={{ width: 300, height: 40 }} />