|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { |
| 3 | + StyleSheet, |
| 4 | + Text, |
| 5 | + View, |
| 6 | + Button, |
| 7 | + SafeAreaView, |
| 8 | + StatusBar, |
| 9 | +} from 'react-native'; |
| 10 | +import RangeSlider from 'react-native-range-slider-fast'; |
| 11 | + |
| 12 | +function App() { |
| 13 | + const MIN = 0; |
| 14 | + const MAX = 500; |
| 15 | + const STEP = 1; |
| 16 | + const [values, setValues] = useState([MIN, MAX]); |
| 17 | + const [finalValues, setFinalValues] = useState([MIN, MAX]); |
| 18 | + |
| 19 | + const resetSlider = () => { |
| 20 | + setValues([MIN, MAX]); |
| 21 | + setFinalValues([MIN, MAX]); |
| 22 | + }; |
| 23 | + |
| 24 | + return ( |
| 25 | + <SafeAreaView style={styles.container}> |
| 26 | + <StatusBar barStyle="dark-content" /> |
| 27 | + |
| 28 | + <Text style={styles.title}>Range Slider Example</Text> |
| 29 | + |
| 30 | + <View style={styles.sliderContainer}> |
| 31 | + <View style={styles.labelContainer}> |
| 32 | + <Text style={styles.sliderLabel}> |
| 33 | + Current Selection: {values[0]} - {values[1]} |
| 34 | + </Text> |
| 35 | + <Text style={styles.labelEvent}>(onValuesChange)</Text> |
| 36 | + </View> |
| 37 | + |
| 38 | + <RangeSlider |
| 39 | + initialMinValue={values[0]} |
| 40 | + initialMaxValue={values[1]} |
| 41 | + min={MIN} |
| 42 | + max={MAX} |
| 43 | + step={STEP} |
| 44 | + width={280} |
| 45 | + selectedTrackColor="#8A2BE2" |
| 46 | + onValuesChange={setValues} |
| 47 | + onValuesChangeFinish={setFinalValues} |
| 48 | + /> |
| 49 | + |
| 50 | + <View style={styles.labelContainer}> |
| 51 | + <Text style={styles.sliderRange}> |
| 52 | + Selected Range: {finalValues[0]} - {finalValues[1]} |
| 53 | + </Text> |
| 54 | + <Text style={styles.rangeEvent}>(onValuesChangeFinish)</Text> |
| 55 | + </View> |
| 56 | + |
| 57 | + <View style={styles.buttonContainer}> |
| 58 | + <Button title="Reset Slider" onPress={resetSlider} color="#8A2BE2" /> |
| 59 | + </View> |
| 60 | + </View> |
| 61 | + </SafeAreaView> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +const styles = StyleSheet.create({ |
| 66 | + container: { |
| 67 | + flex: 1, |
| 68 | + backgroundColor: 'white', |
| 69 | + }, |
| 70 | + title: { |
| 71 | + fontSize: 22, |
| 72 | + fontWeight: 'bold', |
| 73 | + textAlign: 'center', |
| 74 | + marginVertical: 20, |
| 75 | + }, |
| 76 | + sliderContainer: { |
| 77 | + flex: 1, |
| 78 | + alignItems: 'center', |
| 79 | + paddingTop: 40, |
| 80 | + }, |
| 81 | + sliderLabel: { |
| 82 | + fontSize: 16, |
| 83 | + fontWeight: '500', |
| 84 | + color: '#444', |
| 85 | + }, |
| 86 | + sliderRange: { |
| 87 | + fontSize: 16, |
| 88 | + fontWeight: '600', |
| 89 | + color: '#8A2BE2', |
| 90 | + }, |
| 91 | + buttonContainer: { |
| 92 | + marginTop: 20, |
| 93 | + width: 280, |
| 94 | + }, |
| 95 | + labelContainer: { |
| 96 | + alignItems: 'center', |
| 97 | + marginVertical: 30, |
| 98 | + }, |
| 99 | + labelEvent: { |
| 100 | + fontSize: 15, |
| 101 | + color: '#777', |
| 102 | + marginTop: 4, |
| 103 | + }, |
| 104 | + rangeEvent: { |
| 105 | + fontSize: 15, |
| 106 | + color: '#9C6ADE', |
| 107 | + marginTop: 4, |
| 108 | + }, |
| 109 | +}); |
| 110 | + |
| 111 | +export default App; |
0 commit comments