【发布时间】:2021-12-13 15:24:28
【问题描述】:
我想在底部堆栈导航器中添加一个组件(比如说“Autobus”),这样它将接收“navigation”参数,并且我将能够导航到“Autobus”组件 - navigation.navigate('Autbous')。但是,我不想在“Tab.Navigator”中实际显示“Autobus”组件。
我有以下代码:
import React from 'react'
import { Ionicons } from '@expo/vector-icons'
import { StyleSheet, View, TouchableOpacity } from 'react-native'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import THEME from '../theme'
import PostsScreen from '../screens/PostsScreen'
import CreateScreen from '../screens/CreateScreen'
import ProfileScreen from '../screens/ProfileScreen'
const Tab = createBottomTabNavigator()
const Tabs = () => {
return (
<Tab.Navigator
initialRouteName='Posts'
screenOptions={{
tabBarShowLabel: false,
tabBarStyle: { ...styles.tab, ...styles.shadow }
}}
>
<Tab.Screen
name='Profile'
component={ProfileScreen}
options={{
tabBarIcon: ({ focused }) => (
<CustomTabIcon focused={focused} iconName='person' />
)
}}
/>
<Tab.Screen
name='Create'
component={CreateScreen}
options={{
// tabBarShowLabel: true,
tabBarIcon: ({ focused }) => (
<CustomTabIcon focused={focused} iconName='add' />
),
tabBarButton: props => <CustomCircleButton {...props} />
}}
/>
<Tab.Screen
name='Posts'
component={PostsScreen}
options={{
tabBarIcon: ({ focused }) => (
<CustomTabIcon focused={focused} iconName='search' />
)
}}
/>
</Tab.Navigator>
)
}
const CustomTabIcon = ({ focused, iconName }) => {
return (
<Ionicons
size={24}
color={THEME.INFO_COLOR}
name={focused ? iconName : `${iconName}-outline`}
/>
)
}
const CustomCircleButton = ({ children, onPress }) => {
return (
<TouchableOpacity
onPress={onPress}
style={{
...styles.center,
...styles.shadow
}}
>
<View style={styles.circle}>{children}</View>
</TouchableOpacity>
)
}
const styles = StyleSheet.create({
tab: {
position: 'absolute',
bottom: 15,
left: 20,
right: 20,
elevation: 0,
backgroundColor: 'white',
borderRadius: 15,
height: 70
},
shadow: {
shadowColor: '#7f5df0',
shadowOffset: {
width: 0,
height: 10
},
shadowOpacity: 0.25,
shadowRadius: 3.5,
elevation: 5
},
center: {
top: -20,
justifyContent: 'center',
alignItems: 'center'
},
circle: {
width: 70,
height: 70,
borderRadius: 35,
backgroundColor: THEME.DANGER_COLOR
}
})
export default Tabs
【问题讨论】:
标签: react-native react-navigation