|
1 | 1 | import { View, StyleSheet, Text } from 'react-native'; |
| 2 | +import type { ColorValue } from 'react-native'; |
| 3 | +import { LinearGradient } from 'expo-linear-gradient'; |
2 | 4 | import { |
3 | 5 | PillSwitch, |
4 | 6 | useControlListState, |
5 | 7 | } from 'react-native-multiswitch-controller'; |
6 | 8 |
|
7 | 9 | 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 | + |
8 | 36 | const controlListState1 = useControlListState({ |
9 | 37 | options: [ |
10 | 38 | { value: 'First', label: 'First' }, |
@@ -55,7 +83,26 @@ export default function App() { |
55 | 83 | const isTestMode = false; |
56 | 84 |
|
57 | 85 | return ( |
58 | | - <View style={styles.container}> |
| 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 | + |
59 | 106 | <View style={styles.exampleContainer}> |
60 | 107 | <Text style={styles.title}>Align to left, center or right</Text> |
61 | 108 | <PillSwitch |
@@ -135,7 +182,7 @@ export default function App() { |
135 | 182 | </Text> |
136 | 183 | )} |
137 | 184 | </View> |
138 | | - </View> |
| 185 | + </LinearGradient> |
139 | 186 | ); |
140 | 187 | } |
141 | 188 |
|
|
0 commit comments