|
1 | | -import { View, StyleSheet, Text } from 'react-native'; |
2 | | -import type { ColorValue } from 'react-native'; |
3 | | -import { LinearGradient } from 'expo-linear-gradient'; |
4 | | -import { |
5 | | - PillSwitch, |
6 | | - useControlListState, |
7 | | -} from 'react-native-multiswitch-controller'; |
| 1 | +import Navigation from './Navigation'; |
8 | 2 |
|
9 | 3 | export default function App() { |
10 | | - const controlListState0 = useControlListState({ |
11 | | - options: [ |
12 | | - { value: 'morning', label: '🌅' }, |
13 | | - { value: 'afternoon', label: '☀️' }, |
14 | | - { value: 'evening', label: '🌇' }, |
15 | | - { value: 'night', label: '🌙' }, |
16 | | - ], |
17 | | - defaultOption: 'morning', |
18 | | - variant: 'segmentedControl', |
19 | | - }); |
20 | | - |
21 | | - const getGradientColors = (timeOfDay: string): [ColorValue, ColorValue] => { |
22 | | - switch (timeOfDay) { |
23 | | - case 'morning': |
24 | | - return ['#FFF5E6', '#FFE4B5']; |
25 | | - case 'afternoon': |
26 | | - return ['#E6F3FF', '#B3D9FF']; |
27 | | - case 'evening': |
28 | | - return ['#FFE6E0', '#FFD6CC']; |
29 | | - case 'night': |
30 | | - return ['#E6E6FA', '#D8D8F6']; |
31 | | - default: |
32 | | - return ['#FFFFFF', '#F8F8F8']; |
33 | | - } |
34 | | - }; |
35 | | - |
36 | | - const controlListState1 = useControlListState({ |
37 | | - options: [ |
38 | | - { value: 'First', label: 'First' }, |
39 | | - { value: 'Second', label: 'Second' }, |
40 | | - { value: 'Third', label: 'Third' }, |
41 | | - { value: 'Fourth', label: 'Fourth' }, |
42 | | - { value: 'Fifth', label: 'Fifth' }, |
43 | | - { value: 'Sixth', label: 'Sixth' }, |
44 | | - { value: 'Seventh', label: 'Seventh' }, |
45 | | - { value: 'Eighth', label: 'Eighth' }, |
46 | | - { value: 'Ninth', label: 'Ninth' }, |
47 | | - { value: 'Tenth', label: 'Tenth' }, |
48 | | - { value: 'Eleventh', label: 'Eleventh' }, |
49 | | - { value: 'Twelfth', label: 'Twelfth' }, |
50 | | - { value: 'Thirteenth', label: 'Thirteenth' }, |
51 | | - { value: 'Fourteenth', label: 'Fourteenth' }, |
52 | | - { value: 'Fifteenth', label: 'Fifteenth' }, |
53 | | - { value: 'Sixteenth', label: 'Sixteenth' }, |
54 | | - ], |
55 | | - defaultOption: 'First', |
56 | | - variant: 'segmentedControl', |
57 | | - }); |
58 | | - const controlListState2 = useControlListState({ |
59 | | - options: [ |
60 | | - { value: 'First', label: 'First' }, |
61 | | - { value: 'Second', label: 'Second' }, |
62 | | - ], |
63 | | - defaultOption: 'First', |
64 | | - variant: 'segmentedControl', |
65 | | - }); |
66 | | - const controlListState3 = useControlListState({ |
67 | | - options: [ |
68 | | - { value: 'First', label: 'First' }, |
69 | | - { value: 'Second', label: 'Second' }, |
70 | | - ], |
71 | | - defaultOption: 'Second', |
72 | | - variant: 'segmentedControl', |
73 | | - }); |
74 | | - const controlListState4 = useControlListState({ |
75 | | - options: [ |
76 | | - { value: 'First', label: 'First is a very long label' }, |
77 | | - { value: 'Second', label: 'Second is short' }, |
78 | | - ], |
79 | | - defaultOption: 'First', |
80 | | - variant: 'segmentedControl', |
81 | | - }); |
82 | | - |
83 | | - const isTestMode = false; |
84 | | - |
85 | | - return ( |
86 | | - <LinearGradient |
87 | | - colors={getGradientColors(controlListState0.activeOption)} |
88 | | - style={styles.container} |
89 | | - > |
90 | | - <View style={styles.exampleContainer}> |
91 | | - <Text style={styles.title}>Time of Day</Text> |
92 | | - <PillSwitch |
93 | | - controlListState={controlListState0} |
94 | | - inactiveBackgroundColor="rgba(59, 130, 246, 0.08)" |
95 | | - activeBackgroundColor="rgb(37, 99, 235)" |
96 | | - inactiveTextColor="rgb(37, 99, 235)" |
97 | | - activeTextColor="rgb(253, 230, 138)" |
98 | | - /> |
99 | | - {isTestMode && ( |
100 | | - <Text style={styles.selectedText}> |
101 | | - Selected: {controlListState3.activeOption} |
102 | | - </Text> |
103 | | - )} |
104 | | - </View> |
105 | | - |
106 | | - <View style={styles.exampleContainer}> |
107 | | - <Text style={styles.title}>Align to left, center or right</Text> |
108 | | - <PillSwitch |
109 | | - controlListState={controlListState2} |
110 | | - align="left" |
111 | | - inactiveBackgroundColor="rgb(21, 87, 21)" |
112 | | - activeBackgroundColor="rgb(60, 180, 20)" |
113 | | - inactiveTextColor="rgb(208, 249, 205)" |
114 | | - /> |
115 | | - <PillSwitch |
116 | | - controlListState={controlListState2} |
117 | | - align="center" |
118 | | - inactiveBackgroundColor="rgba(220, 38, 38, 0.08)" |
119 | | - activeBackgroundColor="rgb(185, 28, 28)" |
120 | | - inactiveTextColor="rgb(185, 28, 28)" |
121 | | - /> |
122 | | - <PillSwitch |
123 | | - controlListState={controlListState2} |
124 | | - align="right" |
125 | | - inactiveBackgroundColor="rgba(205, 197, 40, 0.08)" |
126 | | - activeBackgroundColor="rgb(180, 170, 20)" |
127 | | - inactiveTextColor="rgb(180, 170, 20)" |
128 | | - /> |
129 | | - {isTestMode && ( |
130 | | - <Text style={styles.selectedText}> |
131 | | - Selected: {controlListState2.activeOption} |
132 | | - </Text> |
133 | | - )} |
134 | | - </View> |
135 | | - |
136 | | - <View style={styles.exampleContainer}> |
137 | | - <Text style={styles.title}>Set initial value</Text> |
138 | | - <PillSwitch |
139 | | - controlListState={controlListState3} |
140 | | - inactiveBackgroundColor="rgba(59, 130, 246, 0.08)" |
141 | | - activeBackgroundColor="rgb(37, 99, 235)" |
142 | | - inactiveTextColor="rgb(37, 99, 235)" |
143 | | - activeTextColor="rgb(253, 230, 138)" |
144 | | - /> |
145 | | - {isTestMode && ( |
146 | | - <Text style={styles.selectedText}> |
147 | | - Selected: {controlListState3.activeOption} |
148 | | - </Text> |
149 | | - )} |
150 | | - </View> |
151 | | - |
152 | | - <View style={styles.exampleContainer}> |
153 | | - <Text style={styles.title}>Use different width for labels</Text> |
154 | | - <PillSwitch |
155 | | - controlListState={controlListState4} |
156 | | - containerHeight={48} |
157 | | - itemHeight={36} |
158 | | - inactiveBackgroundColor="rgba(30, 64, 175, 0.08)" |
159 | | - activeBackgroundColor="rgb(30, 64, 175)" |
160 | | - inactiveTextColor="rgb(30, 64, 175)" |
161 | | - /> |
162 | | - {isTestMode && ( |
163 | | - <Text style={styles.selectedText}> |
164 | | - Selected: {controlListState4.activeOption} |
165 | | - </Text> |
166 | | - )} |
167 | | - </View> |
168 | | - |
169 | | - <View style={styles.exampleContainer}> |
170 | | - <Text style={styles.title}> |
171 | | - Scrollable if there is not enough width |
172 | | - </Text> |
173 | | - <PillSwitch |
174 | | - controlListState={controlListState1} |
175 | | - customItemStyle={{}} |
176 | | - containerHeight={54} |
177 | | - itemHeight={48} |
178 | | - /> |
179 | | - {isTestMode && ( |
180 | | - <Text style={styles.selectedText}> |
181 | | - Selected: {controlListState1.activeOption} |
182 | | - </Text> |
183 | | - )} |
184 | | - </View> |
185 | | - </LinearGradient> |
186 | | - ); |
| 4 | + return <Navigation />; |
187 | 5 | } |
188 | | - |
189 | | -const styles = StyleSheet.create({ |
190 | | - container: { |
191 | | - flex: 1, |
192 | | - justifyContent: 'center', |
193 | | - gap: 16, |
194 | | - padding: 10, |
195 | | - }, |
196 | | - title: { |
197 | | - fontSize: 18, |
198 | | - padding: 10, |
199 | | - }, |
200 | | - selectedText: { |
201 | | - fontSize: 16, |
202 | | - padding: 4, |
203 | | - alignSelf: 'center', |
204 | | - }, |
205 | | - bigContainer: { |
206 | | - width: '100%', |
207 | | - marginBottom: 20, |
208 | | - }, |
209 | | - exampleContainer: {}, |
210 | | -}); |
0 commit comments