mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-11 23:58:31 +08:00
<img width="740" alt="Screen Shot 2020-05-20 at 16 31 30" src="https://user-images.githubusercontent.com/1174278/82458770-673d8880-9ab7-11ea-81d3-8ac0c1e52705.png">
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import * as React from 'react';
|
|
import { View, StyleSheet } from 'react-native';
|
|
import { Title, Button } from 'react-native-paper';
|
|
import Feather from 'react-native-vector-icons/Feather';
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
|
|
|
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',
|
|
},
|
|
});
|