### Handle Slider Touch Start in RN Range Slider
Source: https://github.com/githuboftigran/rn-range-slider/blob/master/README.md
Callback executed when a user initiates interaction with the slider. It provides the current low and high values at the start of the touch. The high value is disregarded if `disableRange` is enabled.
```TypeScript
onSliderTouchStart: (low: number, high: number) => void;
```
--------------------------------
### Implement RN Range Slider with Custom Components
Source: https://context7.com/githuboftigran/rn-range-slider/llms.txt
Demonstrates how to integrate the RangeSlider component into a React Native application. It shows the setup for custom rendering of thumbs, rails, labels, and notches, along with handling value changes and touch events. This example requires React Native and the 'rn-range-slider' library.
```tsx
import React, { useCallback, useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import RangeSlider from 'rn-range-slider';
// Custom thumb component
const Thumb = () => (
);
// Custom rail (background track)
const Rail = () => (
);
// Custom selected rail (highlighted track)
const RailSelected = () => (
);
// Custom label showing the value
const Label = ({ text }) => (
{text}
);
// Custom notch (small triangle below label)
const Notch = () => (
);
const App = () => {
const [low, setLow] = useState(20);
const [high, setHigh] = useState(80);
const renderThumb = useCallback(() => , []);
const renderRail = useCallback(() => , []);
const renderRailSelected = useCallback(() => , []);
const renderLabel = useCallback((value) => , []);
const renderNotch = useCallback(() => , []);
const handleValueChange = useCallback((low, high, fromUser) => {
setLow(low);
setHigh(high);
if (fromUser) {
console.log('User changed values to:', low, high);
}
}, []);
const handleSliderTouchStart = useCallback((low, high) => {
console.log('Touch started at:', low, high);
}, []);
const handleSliderTouchEnd = useCallback((low, high) => {
console.log('Touch ended at:', low, high);
}, []);
return (
Selected Range: {low} - {high}
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
justifyContent: 'center',
},
slider: {
height: 80,
},
thumb: {
width: 20,
height: 20,
borderRadius: 10,
backgroundColor: '#3b82f6',
borderWidth: 2,
borderColor: '#ffffff',
},
rail: {
flex: 1,
height: 4,
borderRadius: 2,
backgroundColor: '#e5e7eb',
},
railSelected: {
height: 4,
backgroundColor: '#3b82f6',
borderRadius: 2,
},
label: {
paddingHorizontal: 8,
paddingVertical: 4,
backgroundColor: '#3b82f6',
borderRadius: 4,
},
labelText: {
color: '#ffffff',
fontSize: 12,
fontWeight: 'bold',
},
notch: {
width: 8,
height: 8,
backgroundColor: '#3b82f6',
transform: [{ rotate: '45deg' }],
},
valueText: {
fontSize: 16,
marginBottom: 20,
textAlign: 'center',
},
});
export default App;
```
--------------------------------
### Set Minimum Range Constraint in React Native Range Slider
Source: https://context7.com/githuboftigran/rn-range-slider/llms.txt
This example demonstrates how to enforce a minimum distance between the two thumbs of the RangeSlider using the `minRange` prop. It prevents users from moving the thumbs closer than the specified value. The snippet also shows custom rendering for different colored thumbs based on whether they represent the low or high value.
```tsx
import React, { useCallback, useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import RangeSlider from 'rn-range-slider';
const Thumb = () => ;
const Rail = () => ;
const RailSelected = () => ;
const MinRangeSlider = () => {
const [low, setLow] = useState(30);
const [high, setHigh] = useState(70);
const renderThumb = useCallback((name) => {
// Render different colors for low and high thumbs
return (
);
}, []);
const renderRail = useCallback(() => , []);
const renderRailSelected = useCallback(() => , []);
const handleValueChange = useCallback((low, high, fromUser) => {
setLow(low);
setHigh(high);
}, []);
return (
Range: {low} - {high} (minimum gap: 20)
Thumbs cannot be moved closer than 20 units apart
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
},
slider: {
height: 60,
},
thumb: {
width: 20,
height: 20,
borderRadius: 10,
},
rail: {
flex: 1,
height: 4,
borderRadius: 2,
backgroundColor: '#e5e7eb',
},
railSelected: {
height: 4,
backgroundColor: '#8b5cf6',
borderRadius: 2,
},
valueText: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 8,
},
infoText: {
fontSize: 14,
color: '#6b7280',
marginBottom: 20,
},
});
export default MinRangeSlider;
```
--------------------------------
### Basic RangeSlider Usage in React Native
Source: https://github.com/githuboftigran/rn-range-slider/blob/master/README.md
This snippet demonstrates the basic implementation of the RangeSlider component in a React Native application. It shows how to import the component, define callback functions for rendering custom elements (Thumb, Rail, RailSelected, Label, Notch), and handle value changes. The component requires React Native versions 0.59.0 or higher due to its use of React hooks.
```javascript
import React, { useCallback } from 'react';
import { View, StyleSheet } from 'react-native';
import RangeSlider from 'rn-range-slider';
// Placeholder components for Thumb, Rail, RailSelected, Label, Notch
const Thumb = () => ;
const Rail = () => ;
const RailSelected = () => ;
const Label = ({ text }) => {text};
const Notch = () => ;
const App = () => {
const [low, setLow] = React.useState(0);
const [high, setHigh] = React.useState(100);
const renderThumb = useCallback(() => , []);
const renderRail = useCallback(() => , []);
const renderRailSelected = useCallback(() => , []);
const renderLabel = useCallback(value =>