Skip to content

Commit 4ae8b29

Browse files
committed
feat: Add expo gradient for first example
1 parent 3fe7a10 commit 4ae8b29

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"@expo/metro-runtime": "~5.0.4",
1313
"expo": "~53.0.9",
14+
"expo-linear-gradient": "^14.1.5",
1415
"expo-status-bar": "~2.2.3",
1516
"react": "19.0.0",
1617
"react-dom": "19.0.0",

example/src/App.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
import { View, StyleSheet, Text } from 'react-native';
2+
import type { ColorValue } from 'react-native';
3+
import { LinearGradient } from 'expo-linear-gradient';
24
import {
35
PillSwitch,
46
useControlListState,
57
} from 'react-native-multiswitch-controller';
68

79
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+
836
const controlListState1 = useControlListState({
937
options: [
1038
{ value: 'First', label: 'First' },
@@ -55,7 +83,26 @@ export default function App() {
5583
const isTestMode = false;
5684

5785
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+
59106
<View style={styles.exampleContainer}>
60107
<Text style={styles.title}>Align to left, center or right</Text>
61108
<PillSwitch
@@ -135,7 +182,7 @@ export default function App() {
135182
</Text>
136183
)}
137184
</View>
138-
</View>
185+
</LinearGradient>
139186
);
140187
}
141188

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6362,6 +6362,17 @@ __metadata:
63626362
languageName: node
63636363
linkType: hard
63646364

6365+
"expo-linear-gradient@npm:^14.1.5":
6366+
version: 14.1.5
6367+
resolution: "expo-linear-gradient@npm:14.1.5"
6368+
peerDependencies:
6369+
expo: "*"
6370+
react: "*"
6371+
react-native: "*"
6372+
checksum: 7550e1ff999fbe3da4a4b189a430fbadaeeffa98a2bfe5b4642a27dfdec73e7920e5a60e7db0c3bcc8345604841b4ea251cd5aa30c32d166d6ac2d86e00ecb58
6373+
languageName: node
6374+
linkType: hard
6375+
63656376
"expo-modules-autolinking@npm:2.1.10":
63666377
version: 2.1.10
63676378
resolution: "expo-modules-autolinking@npm:2.1.10"
@@ -11338,6 +11349,7 @@ __metadata:
1133811349
"@babel/core": ^7.20.0
1133911350
"@expo/metro-runtime": ~5.0.4
1134011351
expo: ~53.0.9
11352+
expo-linear-gradient: ^14.1.5
1134111353
expo-status-bar: ~2.2.3
1134211354
react: 19.0.0
1134311355
react-dom: 19.0.0

0 commit comments

Comments
 (0)