-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.tsx
171 lines (164 loc) · 4.63 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React from 'react'
import { View, Text, StyleSheet, AppRegistry, Platform } from 'react-native'
import { Slider, RangeSlider } from './src'
import { name as appName } from './app.json'
const styles = StyleSheet.create({
category: {
flexDirection: 'row',
justifyContent: 'space-around'
},
slider: {
width: 200,
height: 40,
flexGrow: 0,
borderWidth: 1,
borderColor: 'black',
borderStyle: 'solid',
padding: 10
},
verticalSlider: {
height: 200,
width: 40,
flexGrow: 0,
borderWidth: 1,
borderColor: 'black',
borderStyle: 'solid'
},
title: {
fontSize: 28,
margin: 20
}
})
const CustomThumb = ({ value }) => {
return <Text>{value}</Text>
}
const CustomTrack = ({ thickness, vertical, color, style }) => {
return (
<View
style={[
style,
{
borderStyle: 'dashed',
borderTopWidth: vertical ? 0 : thickness / 2,
borderBottomWidth: vertical ? 0 : thickness / 2,
borderLeftWidth: vertical ? thickness / 2 : 0,
borderRightWidth: vertical ? thickness / 2 : 0,
borderColor: color,
backgroundColor: 'transparent',
[vertical ? 'width' : 'height']: 0
}
]}
/>
)
}
const App = () => {
const [value, setValue] = React.useState(0)
const [range, setRange] = React.useState<[number, number]>([0, 0])
const [max, setMax] = React.useState(1)
React.useEffect(() => {
setInterval(() => setMax((max) => max + 1), 2000)
}, [])
return (
<View>
<Text style={styles.title}>Raw Slider</Text>
<View style={styles.category}>
<Slider
onSlidingStart={(value) => console.log('start:', value)}
onSlidingComplete={(value) => console.log('complete:', value)}
onValueChange={(value) => console.log('change:', value)}
style={styles.slider}
inverted={true}
slideOnTap={false}
minimumValue={0}
maximumValue={max}
/>
<Slider
style={styles.slider}
minimumValue={0}
maximumValue={100}
value={value}
CustomThumb={CustomThumb}
step={10}
onValueChange={setValue}
minimumTrackTintColor="blue"
maximumTrackTintColor="red"
/>
<Slider
style={styles.verticalSlider}
minimumValue={0}
maximumValue={10}
value={value}
step={1}
inverted={true}
vertical={true}
CustomTrack={CustomTrack}
onValueChange={setValue}
minimumTrackTintColor="blue"
maximumTrackTintColor="red"
/>
<Slider
onSlidingStart={(value) => console.log('start:', value)}
onSlidingComplete={(value) => console.log('complete:', value)}
onValueChange={(value) => console.log('change:', value)}
style={styles.slider}
minimumValue={0}
maximumValue={max}
step={0.1}
/>
</View>
<Text style={styles.title}>Range Slider</Text>
<View style={styles.category}>
<RangeSlider
onSlidingStart={(value) => console.log('start:', value)}
onSlidingComplete={(value) => console.log('complete:', value)}
onValueChange={(value) => console.log('change:', value)}
style={styles.slider}
inverted={true}
slideOnTap={false}
minimumValue={0}
maximumValue={1}
/>
<RangeSlider
style={styles.slider}
minimumValue={0}
maximumValue={10}
crossingAllowed
range={range}
step={1}
CustomThumb={CustomThumb}
onValueChange={setRange}
outboundColor="blue"
inboundColor="red"
/>
<RangeSlider
style={styles.verticalSlider}
minimumValue={0}
maximumValue={10}
range={range}
step={1}
inverted={true}
vertical={true}
onValueChange={setRange}
outboundColor="blue"
inboundColor="red"
/>
<RangeSlider
onSlidingStart={(value) => console.log('start:', value)}
onSlidingComplete={(value) => console.log('complete:', value)}
onValueChange={(value) => console.log('change:', value)}
style={styles.slider}
minimumValue={0}
maximumValue={1}
step={0.1}
/>
</View>
</View>
)
}
export default App
AppRegistry.registerComponent(appName, () => App)
if (Platform.OS === 'web') {
AppRegistry.runApplication(appName, {
rootTag: document.getElementsByTagName('body')[0]
})
}