-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
133 lines (121 loc) · 2.78 KB
/
App.tsx
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
133
import { useState } from 'react'
import {
Button,
SafeAreaView,
Text,
TextStyle,
TouchableOpacity,
View,
ViewStyle,
} from 'react-native'
import { Basic } from './examples/Basic'
import { BurstEffect } from './examples/BurstEffect'
import { Confetti } from './examples/Confetti'
import { ConfettiCannon } from './examples/ConfettiCannon'
import { Emoji } from './examples/Emoji'
import { Fire } from './examples/Fire'
import { Fireworks } from './examples/Fireworks'
import { PokemonList } from './examples/List'
import { Snow } from './examples/Snow'
const Examples: Record<string, { Component: React.FC; title: string }> = {
Basic: {
Component: Basic,
title: 'Basic',
},
Emoji: {
Component: Emoji,
title: 'Emoji',
},
Fire: {
Component: Fire,
title: 'Fire',
},
Snow: {
Component: Snow,
title: 'Snow',
},
Fireworks: {
Component: Fireworks,
title: 'Fireworks',
},
BurstEffect: {
Component: BurstEffect,
title: 'Burst Effect',
},
Confetti: {
Component: Confetti,
title: 'Confetti',
},
ConfettiCannon: {
Component: ConfettiCannon,
title: 'Confetti Cannon',
},
List: {
Component: PokemonList,
title: 'List',
},
}
type ExampleKeys = keyof typeof Examples
export default function App() {
const [selectedExample, setSelecteExample] = useState<ExampleKeys | null>(
null,
)
if (!selectedExample) {
return (
<SafeAreaView style={$homeContainer}>
<Text style={$homeHeadingText}>Examples</Text>
{Object.entries(Examples).map(([exampleName, { title }]) => (
<Button
key={exampleName}
title={title}
onPress={() => setSelecteExample(exampleName as ExampleKeys)}
/>
))}
</SafeAreaView>
)
}
const { Component } = Examples[selectedExample]
return (
<View style={$homeContainer}>
<Component />
<View style={$buttonContainerStyles}>
<TouchableOpacity
activeOpacity={0.8}
style={$buttonStyles}
onPress={() => setSelecteExample(null)}>
<Text style={$backButtonTextStyle}>BACK</Text>
</TouchableOpacity>
</View>
</View>
)
}
const $homeContainer: ViewStyle = {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
const $homeHeadingText: TextStyle = {
fontSize: 32,
fontWeight: '600',
marginBottom: 16,
}
const $buttonContainerStyles: ViewStyle = {
position: 'absolute',
bottom: 40,
width: '100%',
}
const $buttonStyles: ViewStyle = {
marginHorizontal: 16,
padding: 16,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#194c7f',
borderColor: 'gray',
borderWidth: 1,
borderRadius: 8,
}
const $backButtonTextStyle: TextStyle = {
fontSize: 16,
color: 'white',
fontWeight: '600',
}