-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathApp.tsx
More file actions
132 lines (123 loc) · 2.91 KB
/
App.tsx
File metadata and controls
132 lines (123 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { useEffect, useState } from 'react';
import {
BackHandler,
PlatformColor,
Pressable,
ScrollView,
StatusBar,
StyleSheet,
Text,
} from 'react-native';
import CustomImage from './screens/CustomImage';
import Demo from './screens/Demo';
import { COLORS, SPACING } from './constants';
import { IMAGES } from './data';
import PaletteExampleItem from './components/PaletteExampleItem';
const ROUNDNESS = 10;
export default function App() {
const [screen, setScreen] = useState<'home' | 'demo' | 'custom'>('home');
useEffect(() => {
const subscription = BackHandler.addEventListener(
'hardwareBackPress',
() => {
if (screen === 'demo' || screen === 'custom') {
setScreen('home');
return true;
}
return false;
}
);
return () => subscription.remove();
}, [screen]);
if (screen === 'demo') {
return <Demo />;
}
if (screen === 'custom') {
return <CustomImage />;
}
return (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
{IMAGES.map((img, index) => (
<PaletteExampleItem
key={index}
image={img.source}
author={img.author}
/>
))}
<Pressable style={styles.button} onPress={() => setScreen('demo')}>
<Text style={styles.buttonLabel}>Go to Demo</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => setScreen('custom')}>
<Text style={styles.buttonLabel}>Build Demo from URL / gallery</Text>
</Pressable>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: COLORS.background,
},
content: {
padding: SPACING * 4,
paddingTop: SPACING * 4 + (StatusBar.currentHeight ?? 0),
paddingBottom: SPACING * 4 + 10,
gap: SPACING * 4,
},
item: {
width: '100%',
padding: SPACING * 2,
borderRadius: ROUNDNESS + SPACING * 2,
overflow: 'hidden',
},
underlay: {
...StyleSheet.absoluteFill,
backgroundColor: '#e0e0e0',
mixBlendMode: 'luminosity',
},
row: {
flexDirection: 'row',
},
image: {
flexGrow: 1,
height: null,
width: null,
borderRadius: ROUNDNESS,
margin: SPACING,
},
palettes: {
flex: 1,
minWidth: 100,
flexDirection: 'row',
flexWrap: 'wrap',
},
palette: {
width: '50%',
padding: SPACING,
},
color: {
alignItems: 'center',
padding: SPACING * 2,
borderRadius: ROUNDNESS,
overflow: 'hidden',
},
title: {
fontWeight: 'bold',
},
subtitle: {
fontSize: 14,
},
author: {
margin: SPACING,
fontStyle: 'italic',
},
button: {
backgroundColor: PlatformColor('@android:color/system_accent1_50'),
paddingVertical: SPACING * 2,
paddingHorizontal: SPACING * 4,
borderRadius: ROUNDNESS + SPACING * 2,
},
buttonLabel: {
textAlign: 'center',
color: PlatformColor('@android:color/system_accent1_700'),
},
});