-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathApp.js
More file actions
214 lines (205 loc) · 6.02 KB
/
App.js
File metadata and controls
214 lines (205 loc) · 6.02 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @flow
*/
import SegmentedControl from '..';
import React, {useEffect, useState} from 'react';
import {ScrollView, StyleSheet, Text, View, Platform, useColorScheme} from 'react-native';
const App = () => {
const colorScheme = useColorScheme();
const [textColor, setTextColor] = useState('#000');
const [value, setValue] = useState('Unselected');
const [selectedIndex, setSelectedIndex] = useState(undefined);
useEffect(() => {
setTextColor(colorScheme === 'dark' ? '#FFF' : '#000');
}, [colorScheme]);
const _onChange = (event) => {
setSelectedIndex(event.nativeEvent.selectedSegmentIndex);
};
const _onValueChange = (val) => {
setValue(val);
};
return (
<ScrollView
contentContainerStyle={[
styles.container,
{backgroundColor: colorScheme === 'dark' ? '#000' : '#FFF'},
]}>
<View style={styles.segmentContainer}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can have values and images
</Text>
<SegmentedControl
values={['One', 'Two', require('./assets/images/user.png')]}
/>
</View>
<View style={styles.segmentSection}>
<SegmentedControl
values={[
'One',
'Two',
require('../assets/images/user.png'),
'Three',
'Four',
'Five',
]}
/>
</View>
{Platform.OS === 'ios' && (
<View style={styles.segmentContainer}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can have SF Symbols (iOS only)
</Text>
<SegmentedControl
values={[
{systemImage: 'list.bullet'},
{systemImage: 'square.grid.2x2'},
{systemImage: 'rectangle.grid.1x2'},
]}
selectedIndex={0}
/>
</View>
)}
{Platform.OS === 'ios' && (
<View style={styles.segmentContainer}>
<Text style={[styles.text, {color: textColor}]}>
SF Symbols can be mixed with text
</Text>
<SegmentedControl
values={[
'All',
{systemImage: 'star.fill', fontSize: 16, weight: 'semibold'},
{systemImage: 'clock', fontSize: 16},
]}
selectedIndex={0}
/>
</View>
)}
<View style={styles.segmentSection}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can have pre-selected values
</Text>
<SegmentedControl values={['One', 'Two']} selectedIndex={0} />
</View>
<View style={styles.segmentSection}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can be momentary
</Text>
<SegmentedControl values={['One', 'Two']} momentary={true} />
</View>
<View style={styles.segmentSection}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can be disabled
</Text>
<SegmentedControl
enabled={false}
values={['One', 'Two']}
selectedIndex={1}
/>
</View>
<View style={styles.segmentContainer}>
<Text style={[styles.text, {color: textColor}]}>
Custom colors can be provided
</Text>
<SegmentedControl
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedIndex={0}
backgroundColor="#0000ff"
/>
</View>
<View style={styles.segmentContainer}>
<SegmentedControl
tintColor="#00ff00"
values={['One', 'Two', 'Three']}
selectedIndex={1}
/>
</View>
<View style={styles.segmentSection}>
<SegmentedControl
fontStyle={{color: '#ff00ff'}}
activeFontStyle={{color: 'blue'}}
values={['One', 'Two']}
selectedIndex={1}
/>
</View>
<View style={styles.segmentContainer}>
<Text style={[styles.text, {color: textColor}]}>
Segmented controls can have defined fontSize
</Text>
<View style={styles.segmentContainer}>
<SegmentedControl
values={['One', 'Two']}
style={{height: 80}}
fontStyle={styles.fontStyle}
/>
</View>
<SegmentedControl
values={['One', 'Two']}
tintColor="red"
style={{height: 80}}
fontStyle={{
fontFamily: 'Optima',
fontSize: 32,
}}
activeFontStyle={styles.activeFontStyle}
/>
</View>
<View>
<Text style={[styles.text, {color: textColor}]}>
Custom colors can be provided
</Text>
<View style={styles.segmentContainer}>
<SegmentedControl
values={['One', 'Two', 'Three']}
selectedIndex={selectedIndex}
onChange={_onChange}
onValueChange={_onValueChange}
/>
</View>
<Text style={[styles.text, {color: textColor}]}>
Value: {value} Index: {selectedIndex}
</Text>
</View>
<View>
<Text style={[styles.text, {color: textColor}]}>
Appearance value can be provided
</Text>
<View style={styles.segmentContainer}>
<SegmentedControl
appearance="light"
values={['One', 'Two', 'Three']}
selectedIndex={1}
/>
</View>
<View style={styles.segmentContainer}>
<SegmentedControl
appearance="dark"
values={['One', 'Two', 'Three']}
selectedIndex={2}
/>
</View>
</View>
</ScrollView>
);
};
const styles = StyleSheet.create({
text: {
fontSize: 14,
textAlign: 'center',
fontWeight: '500',
margin: 10,
},
segmentContainer: {
marginBottom: 10,
},
segmentSection: {
marginBottom: 25,
},
container: {
paddingTop: 80,
},
});
export default App;