|
1 | | -import { Text, View, StyleSheet } from 'react-native'; |
2 | | -import { multiply } from 'react-native-multiswitch-controller'; |
3 | | - |
4 | | -const result = multiply(3, 7); |
| 1 | +import { View, StyleSheet, Text } from 'react-native'; |
| 2 | +import { |
| 3 | + PillSwitch, |
| 4 | + useControlListState, |
| 5 | +} from 'react-native-multiswitch-controller'; |
5 | 6 |
|
6 | 7 | export default function App() { |
| 8 | + const controlListState1 = useControlListState({ |
| 9 | + options: [ |
| 10 | + { value: 'First', label: 'First' }, |
| 11 | + { value: 'Second', label: 'Second' }, |
| 12 | + { value: 'Third', label: 'Third' }, |
| 13 | + { value: 'Fourth', label: 'Fourth' }, |
| 14 | + { value: 'Fifth', label: 'Fifth' }, |
| 15 | + { value: 'Sixth', label: 'Sixth' }, |
| 16 | + { value: 'Seventh', label: 'Seventh' }, |
| 17 | + { value: 'Eighth', label: 'Eighth' }, |
| 18 | + { value: 'Ninth', label: 'Ninth' }, |
| 19 | + { value: 'Tenth', label: 'Tenth' }, |
| 20 | + { value: 'Eleventh', label: 'Eleventh' }, |
| 21 | + { value: 'Twelfth', label: 'Twelfth' }, |
| 22 | + { value: 'Thirteenth', label: 'Thirteenth' }, |
| 23 | + { value: 'Fourteenth', label: 'Fourteenth' }, |
| 24 | + { value: 'Fifteenth', label: 'Fifteenth' }, |
| 25 | + { value: 'Sixteenth', label: 'Sixteenth' }, |
| 26 | + ], |
| 27 | + defaultOption: 'First', |
| 28 | + variant: 'segmentedControl', |
| 29 | + }); |
| 30 | + const controlListState2 = useControlListState({ |
| 31 | + options: [ |
| 32 | + { value: 'First', label: 'First' }, |
| 33 | + { value: 'Second', label: 'Second' }, |
| 34 | + ], |
| 35 | + defaultOption: 'First', |
| 36 | + variant: 'segmentedControl', |
| 37 | + }); |
| 38 | + const controlListState3 = useControlListState({ |
| 39 | + options: [ |
| 40 | + { value: 'First', label: 'First' }, |
| 41 | + { value: 'Second', label: 'Second' }, |
| 42 | + ], |
| 43 | + defaultOption: 'Second', |
| 44 | + variant: 'segmentedControl', |
| 45 | + }); |
| 46 | + const controlListState4 = useControlListState({ |
| 47 | + options: [ |
| 48 | + { value: 'First', label: 'First is a very long label' }, |
| 49 | + { value: 'Second', label: 'Second is short' }, |
| 50 | + ], |
| 51 | + defaultOption: 'First', |
| 52 | + variant: 'segmentedControl', |
| 53 | + }); |
| 54 | + |
| 55 | + const isTestMode = false; |
| 56 | + |
7 | 57 | return ( |
8 | 58 | <View style={styles.container}> |
9 | | - <Text>Result: {result}</Text> |
| 59 | + <View style={styles.exampleContainer}> |
| 60 | + <Text style={styles.title}>Align to left, center or right</Text> |
| 61 | + <PillSwitch |
| 62 | + controlListState={controlListState2} |
| 63 | + align="left" |
| 64 | + inactiveBackgroundColor="rgb(21, 87, 21)" |
| 65 | + activeBackgroundColor="rgb(60, 180, 20)" |
| 66 | + inactiveTextColor="rgb(208, 249, 205)" |
| 67 | + /> |
| 68 | + <PillSwitch |
| 69 | + controlListState={controlListState2} |
| 70 | + align="center" |
| 71 | + inactiveBackgroundColor="rgba(220, 38, 38, 0.08)" |
| 72 | + activeBackgroundColor="rgb(185, 28, 28)" |
| 73 | + inactiveTextColor="rgb(185, 28, 28)" |
| 74 | + /> |
| 75 | + <PillSwitch |
| 76 | + controlListState={controlListState2} |
| 77 | + align="right" |
| 78 | + inactiveBackgroundColor="rgba(205, 197, 40, 0.08)" |
| 79 | + activeBackgroundColor="rgb(180, 170, 20)" |
| 80 | + inactiveTextColor="rgb(180, 170, 20)" |
| 81 | + /> |
| 82 | + {isTestMode && ( |
| 83 | + <Text style={styles.selectedText}> |
| 84 | + Selected: {controlListState2.activeOption} |
| 85 | + </Text> |
| 86 | + )} |
| 87 | + </View> |
| 88 | + |
| 89 | + <View style={styles.exampleContainer}> |
| 90 | + <Text style={styles.title}>Set initial value</Text> |
| 91 | + <PillSwitch |
| 92 | + controlListState={controlListState3} |
| 93 | + inactiveBackgroundColor="rgba(59, 130, 246, 0.08)" |
| 94 | + activeBackgroundColor="rgb(37, 99, 235)" |
| 95 | + inactiveTextColor="rgb(37, 99, 235)" |
| 96 | + activeTextColor="rgb(253, 230, 138)" |
| 97 | + /> |
| 98 | + {isTestMode && ( |
| 99 | + <Text style={styles.selectedText}> |
| 100 | + Selected: {controlListState3.activeOption} |
| 101 | + </Text> |
| 102 | + )} |
| 103 | + </View> |
| 104 | + |
| 105 | + <View style={styles.exampleContainer}> |
| 106 | + <Text style={styles.title}>Use different width for labels</Text> |
| 107 | + <PillSwitch |
| 108 | + controlListState={controlListState4} |
| 109 | + containerHeight={48} |
| 110 | + itemHeight={36} |
| 111 | + inactiveBackgroundColor="rgba(30, 64, 175, 0.08)" |
| 112 | + activeBackgroundColor="rgb(30, 64, 175)" |
| 113 | + inactiveTextColor="rgb(30, 64, 175)" |
| 114 | + /> |
| 115 | + {isTestMode && ( |
| 116 | + <Text style={styles.selectedText}> |
| 117 | + Selected: {controlListState4.activeOption} |
| 118 | + </Text> |
| 119 | + )} |
| 120 | + </View> |
| 121 | + |
| 122 | + <View style={styles.exampleContainer}> |
| 123 | + <Text style={styles.title}> |
| 124 | + Scrollable if there is not enough width |
| 125 | + </Text> |
| 126 | + <PillSwitch |
| 127 | + controlListState={controlListState1} |
| 128 | + customItemStyle={{}} |
| 129 | + containerHeight={54} |
| 130 | + itemHeight={48} |
| 131 | + /> |
| 132 | + {isTestMode && ( |
| 133 | + <Text style={styles.selectedText}> |
| 134 | + Selected: {controlListState1.activeOption} |
| 135 | + </Text> |
| 136 | + )} |
| 137 | + </View> |
10 | 138 | </View> |
11 | 139 | ); |
12 | 140 | } |
13 | 141 |
|
14 | 142 | const styles = StyleSheet.create({ |
15 | 143 | container: { |
16 | 144 | flex: 1, |
17 | | - alignItems: 'center', |
18 | 145 | justifyContent: 'center', |
| 146 | + gap: 16, |
| 147 | + padding: 10, |
| 148 | + }, |
| 149 | + title: { |
| 150 | + fontSize: 18, |
| 151 | + padding: 10, |
| 152 | + }, |
| 153 | + selectedText: { |
| 154 | + fontSize: 16, |
| 155 | + padding: 4, |
| 156 | + alignSelf: 'center', |
| 157 | + }, |
| 158 | + bigContainer: { |
| 159 | + width: '100%', |
| 160 | + marginBottom: 20, |
19 | 161 | }, |
| 162 | + exampleContainer: {}, |
20 | 163 | }); |
0 commit comments