-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
DynamicTabs.tsx
58 lines (53 loc) · 1.51 KB
/
DynamicTabs.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
import Feather from '@expo/vector-icons/Feather';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import { Button, Title } from 'react-native-paper';
type BottomTabParams = {
[key: string]: undefined;
};
const BottomTabs = createBottomTabNavigator<BottomTabParams>();
export default function BottomTabsScreen() {
const [tabs, setTabs] = React.useState([0, 1]);
return (
<BottomTabs.Navigator>
{tabs.map((i) => (
<BottomTabs.Screen
key={i}
name={`tab-${i}`}
options={{
title: `Tab ${i}`,
tabBarIcon: ({ color, size }) => (
<Feather name="octagon" color={color} size={size} />
),
}}
>
{() => (
<View style={styles.container}>
<Title>Tab {i}</Title>
<Button onPress={() => setTabs((tabs) => [...tabs, tabs.length])}>
Add a tab
</Button>
<Button
onPress={() =>
setTabs((tabs) =>
tabs.length > 1 ? tabs.slice(0, -1) : tabs
)
}
>
Remove a tab
</Button>
</View>
)}
</BottomTabs.Screen>
))}
</BottomTabs.Navigator>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});