-
Notifications
You must be signed in to change notification settings - Fork 21
/
App.js
84 lines (80 loc) · 2.17 KB
/
App.js
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
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import data from './data';
import { Transition, Transitioning } from 'react-native-reanimated';
const transition = (
<Transition.Together>
<Transition.In type='fade' durationMs={200} />
<Transition.Change />
<Transition.Out type='fade' durationMs={200} />
</Transition.Together>
);
export default function App() {
const [currentIndex, setCurrentIndex] = React.useState(null);
const ref = React.useRef();
return (
<Transitioning.View
ref={ref}
transition={transition}
style={styles.container}
>
<StatusBar hidden />
{data.map(({ bg, color, category, subCategories }, index) => {
return (
<TouchableOpacity
key={category}
onPress={() => {
ref.current.animateNextTransition();
setCurrentIndex(index === currentIndex ? null : index);
}}
style={styles.cardContainer}
activeOpacity={0.9}
>
<View style={[styles.card, { backgroundColor: bg }]}>
<Text style={[styles.heading, { color }]}>{category}</Text>
{index === currentIndex && (
<View style={styles.subCategoriesList}>
{subCategories.map((subCategory) => (
<Text key={subCategory} style={[styles.body, { color }]}>
{subCategory}
</Text>
))}
</View>
)}
</View>
</TouchableOpacity>
);
})}
</Transitioning.View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center',
},
cardContainer: {
flexGrow: 1,
},
card: {
flexGrow: 1,
alignItems: 'center',
justifyContent: 'center',
},
heading: {
fontSize: 38,
fontWeight: '900',
textTransform: 'uppercase',
letterSpacing: -2,
},
body: {
fontSize: 20,
lineHeight: 20 * 1.5,
textAlign: 'center',
},
subCategoriesList: {
marginTop: 20,
},
});