[英]Navigation from the header of the bottom tab navigator in react native
I am using bottom tab navigator inside stack navigator of react-navigation in react native.我在 react native 的 react-navigation 的堆栈导航器中使用底部选项卡导航器。 I want to navigate from the left or right element of the header when the stack comes to the bottom tab navigator.当堆栈来到底部选项卡导航器时,我想从标题的左侧或右侧元素进行导航。 I added the left and right button but when I am trying to navigate it gives me error my navigators are as follow.我添加了左右按钮,但是当我尝试导航时,它给了我错误,我的导航器如下所示。
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import FIcon from 'react-native-vector-icons/FontAwesome5';
import { TouchableOpacity, View } from 'react-native';
import AIcon from 'react-native-vector-icons/AntDesign';
import React from 'react';
import Login from './src/component/Login/Login';
import Registration from './src/component/Registration/Registration';
import Navigator from './src/component/AfterLogingIn/AfterLoginRoute';
import ChatDashboard from './src/component/AfterLogingIn/Chat/Chatboard';
const navigator = createStackNavigator({
login: {
screen: Login,
navigationOptions: {
header: null,
},
},
registration: {
screen: Registration,
navigationOptions: {
header: null,
},
},
Navigator: {
screen: Navigator,
navigationOptions: {
headerStyle: {
backgroundColor: '#192a56'
},
headerRight: (
<View style = {{flexDirection: 'row'}}>
<TouchableOpacity style={{ marginRight: 20 }}
>
<FIcon name='search' style={{ color: 'grey' }} size={25} />
</TouchableOpacity>
<TouchableOpacity style={{ marginRight: 10 }}
onPress={() => this.navigation.navigate('ChatDashboard')}
>
<AIcon name='message1' style={{ color: 'grey' }} size={25} />
</TouchableOpacity>
</View>
),
}
},
SignOut: {
screen: Profile,
},
ChatDashboard: {
screen: ChatDashboard,
},
},
{
initialRouteName: 'login',
}
);
// Export it as the root component
export default createAppContainer(navigator);
Here is the bottom tab navigator这是底部的标签导航器
const TabNavigator = createBottomTabNavigator({
posts:{
screen: Posts,
navigationOptions: {
title: 'ABC',
tabBarLabel: 'Posts',
tabBarIcon: ({tintColor}) =>(
<MCIcon name='calendar-text' color = {tintColor} size = {25} />
)
}
},
events: {
screen: Events,
navigationOptions:{
tabBarLabel: 'Events',
tabBarIcon: ({tintColor}) =>(
<MIcon name = 'event' color = {tintColor} size = {25} />
)
}
},
addPost:{
screen: AddPost,
navigationOptions:{
tabBarLabel: 'Add Post',
tabBarIcon: ({tintColor}) =>(
<FIcon name="plus-square" color={tintColor} size = {25} />
)
}
},
alumniStory: {
screen: AlumniStory,
navigationOptions:{
tabBarLabel: 'Alumni Story',
tabBarIcon: ({tintColor}) =>(
<FIcon name = 'book-reader' color = {tintColor} size = {25} />
)
}
},
Profile: {
screen: Profile,
navigationOptions: {
tabBarLabel: 'Profile',
tabBarIcon: ({tintColor}) =>(
<FIcon name = 'user' color= {tintColor} size = {25} />
)
}
},
},
{
swipeEnabled: true,
tabBarOptions: {
style: {
backgroundColor: '#192a56',
}
},
}
);
How do I navigate from header?如何从标题导航?
Because you try using navigation
in renderHeader
and don't have navigation
in register screen file, so let try this instead of defined in that file, we defined it in the Navigator component.因为您尝试在renderHeader
使用navigation
并且在注册屏幕文件中没有navigation
,所以让我们试试这个而不是在那个文件中定义,我们在 Navigator 组件中定义它。
class Navigator extends React.Component {
static navigationOptions = ({ navigation, navigationOptions }) => {
return {
headerStyle: {
backgroundColor: '#192a56'
},
headerRight: (
<View style = {{flexDirection: 'row'}}>
<TouchableOpacity style={{ marginRight: 20 }}
>
<FIcon name='search' style={{ color: 'grey' }} size={25} />
</TouchableOpacity>
<TouchableOpacity style={{ marginRight: 10 }}
onPress={() => navigation.navigate('ChatDashboard')}
>
<AIcon name='message1' style={{ color: 'grey' }} size={25} />
</TouchableOpacity>
</View>
),
};
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.