-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
94 lines (86 loc) · 2.27 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
import React, {Dispatch, SetStateAction, useState} from 'react';
import {Pressable, SafeAreaView, StyleSheet, Text, View} from 'react-native';
import Simple from './screens/Simple';
import ItemSeparators from './screens/ItemSeparators';
import HeadersAndFooters from './screens/HeadersAndFooters';
import Everything from './screens/Everything';
enum TabNames {
Simple = 'simple',
ItemSeparators = 'itemSeparators',
HeadersAndFooters = 'headersAndFooters',
Everything = 'everything',
}
const TABS = [
{
name: TabNames.Simple,
title: 'Simple',
},
{
name: TabNames.ItemSeparators,
title: 'Item Separators',
},
{
name: TabNames.HeadersAndFooters,
title: 'Headers & Footers',
},
{
name: TabNames.Everything,
title: 'Everything',
},
];
type TabsProps = {
activeExample: TabNames;
setActiveExample: Dispatch<SetStateAction<TabNames>>;
};
const Tabs = ({activeExample, setActiveExample}: TabsProps) => (
<View style={styles.container}>
{TABS.map(({name, title}) => {
return (
<Pressable
key={name}
onPress={() => {
setActiveExample(name);
}}>
<Text
style={[styles.tab, activeExample === name && styles.activeTab]}>
{title}
</Text>
</Pressable>
);
})}
</View>
);
const styles = StyleSheet.create({
container: {
paddingVertical: 16,
paddingHorizontal: 8,
borderTopWidth: 4,
borderTopColor: '#ccc',
backgroundColor: '#f9f9f9',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: 64,
},
tab: {
fontSize: 12,
},
activeTab: {
fontWeight: 'bold',
},
});
const App = () => {
const [activeExample, setActiveExample] = useState<TabNames>(TabNames.Simple);
return (
<SafeAreaView style={{flex: 1}}>
<View style={{flex: 1}}>
{activeExample === TabNames.Simple && <Simple />}
{activeExample === TabNames.ItemSeparators && <ItemSeparators />}
{activeExample === TabNames.HeadersAndFooters && <HeadersAndFooters />}
{activeExample === TabNames.Everything && <Everything />}
</View>
<Tabs activeExample={activeExample} setActiveExample={setActiveExample} />
</SafeAreaView>
);
};
export default App;