|
1 | | -import { LinearGradient } from 'expo-linear-gradient'; |
2 | | -import { Button, StyleSheet, Text, View } from 'react-native'; |
| 1 | +import { Button } from 'react-native'; |
3 | 2 | import { MultiswitchController } from 'react-native-multiswitch-controller'; |
4 | 3 |
|
5 | 4 | import { |
6 | 5 | useNavigation, |
7 | 6 | type StaticScreenProps, |
8 | 7 | } from '@react-navigation/native'; |
9 | | -import type { TimeOfDay } from '../types'; |
| 8 | +import ExampleWrapper from '../examples/ExampleWrapper'; |
| 9 | +import type { FavoriteDrink } from '../types'; |
10 | 10 |
|
11 | 11 | type ExampleInitialSetScreenProps = StaticScreenProps<{ |
12 | | - timeOfDay: TimeOfDay; |
| 12 | + favoriteDrink: FavoriteDrink; |
13 | 13 | }>; |
14 | 14 |
|
15 | 15 | export default function ExampleInitialSetScreen({ |
16 | 16 | route, |
17 | 17 | }: ExampleInitialSetScreenProps) { |
18 | | - const { timeOfDay } = route.params; |
| 18 | + const { favoriteDrink } = route.params; |
19 | 19 |
|
20 | 20 | const navigation = useNavigation(); |
21 | 21 |
|
22 | 22 | return ( |
23 | | - <LinearGradient colors={['#FFF5E6', '#FFE4B5']} style={styles.container}> |
24 | | - <View style={styles.exampleContainer}> |
25 | | - <Text style={styles.title}>Time of Day</Text> |
26 | | - <MultiswitchController |
27 | | - options={[ |
28 | | - { value: 'morning', label: '🌅' }, |
29 | | - { value: 'afternoon', label: '☀️' }, |
30 | | - { value: 'evening', label: '🌇' }, |
31 | | - { value: 'night', label: '🌙' }, |
32 | | - ]} |
33 | | - defaultOption="morning" |
34 | | - variant="tabs" |
35 | | - onChangeOption={(value) => { |
36 | | - console.log( |
37 | | - 'State ExampleInitialSetScreen onChangeOption changed:', |
38 | | - value |
39 | | - ); |
40 | | - }} |
41 | | - styleProps={{ |
42 | | - inactiveBackgroundColor: 'rgba(59, 130, 246, 0.08)', |
43 | | - activeBackgroundColor: 'rgb(37, 99, 235)', |
44 | | - }} |
45 | | - /> |
46 | | - <Button |
47 | | - title="Go to SegmentedControlExample" |
48 | | - onPress={() => { |
49 | | - navigation.navigate( |
50 | | - 'SegmentedControlExample', |
51 | | - { |
52 | | - timeOfDay: 'evening', |
53 | | - }, |
54 | | - { pop: true } |
55 | | - ); |
56 | | - }} |
57 | | - /> |
58 | | - </View> |
59 | | - <Text style={styles.title}>RERENDER TEST {timeOfDay}</Text> |
60 | | - </LinearGradient> |
| 23 | + <ExampleWrapper title={`Preselected option: ${favoriteDrink}`}> |
| 24 | + <MultiswitchController<FavoriteDrink> |
| 25 | + variant="tabs" |
| 26 | + defaultOption={favoriteDrink} |
| 27 | + options={[ |
| 28 | + { value: 'water', label: '💧' }, |
| 29 | + { value: 'coffee', label: '☕️' }, |
| 30 | + { value: 'tea', label: '🍵' }, |
| 31 | + { value: 'juice', label: '🍹' }, |
| 32 | + { value: 'soda', label: '🥤' }, |
| 33 | + ]} |
| 34 | + optionGap={10} |
| 35 | + /> |
| 36 | + <Button |
| 37 | + title="Back with new value for first example: 'evening'" |
| 38 | + onPress={() => { |
| 39 | + navigation.navigate( |
| 40 | + 'Examples', |
| 41 | + { |
| 42 | + timeOfDay: 'evening', |
| 43 | + }, |
| 44 | + { pop: true } |
| 45 | + ); |
| 46 | + }} |
| 47 | + /> |
| 48 | + </ExampleWrapper> |
61 | 49 | ); |
62 | 50 | } |
63 | | - |
64 | | -const styles = StyleSheet.create({ |
65 | | - container: { |
66 | | - flex: 1, |
67 | | - gap: 16, |
68 | | - padding: 10, |
69 | | - }, |
70 | | - title: { |
71 | | - fontSize: 18, |
72 | | - padding: 10, |
73 | | - }, |
74 | | - selectedText: { |
75 | | - fontSize: 16, |
76 | | - padding: 4, |
77 | | - alignSelf: 'center', |
78 | | - }, |
79 | | - bigContainer: { |
80 | | - width: '100%', |
81 | | - marginBottom: 20, |
82 | | - }, |
83 | | - exampleContainer: {}, |
84 | | - smallText: { |
85 | | - fontSize: 12, |
86 | | - }, |
87 | | - stateReader: { |
88 | | - marginTop: 20, |
89 | | - padding: 10, |
90 | | - backgroundColor: 'rgba(255, 255, 255, 0.8)', |
91 | | - borderRadius: 8, |
92 | | - }, |
93 | | - subtitle: { |
94 | | - fontSize: 14, |
95 | | - color: '#666', |
96 | | - marginTop: 5, |
97 | | - }, |
98 | | - button: { |
99 | | - fontSize: 14, |
100 | | - color: '#007AFF', |
101 | | - marginTop: 10, |
102 | | - textDecorationLine: 'underline', |
103 | | - }, |
104 | | -}); |
0 commit comments