REACT-native; react-navigation-tabs for createBottomTabNavigator wuth tabBarVisible=false not working.
I tried to hide bottom tab for AddSetting & Manager but unsuccessful. My code as below:
import React from 'react' import { createSwitchNavigator, createAppContainer } from 'react-navigation' import { StyleSheet, Text, TextInput, View, Icon, Image, Button, ScrollView } from 'react-native';
import { createBottomTabNavigator} from "react-navigation-tabs"; import Ionicons from "react-native-vector-icons/Ionicons";
import Login from '../screens/Login' import Signup from '../screens/Signup'
import MyList from '../MyList' import MyForm from '../MyForm';
import Manager from '../Manager'; import ManagerScreen from '../ManagerScreen';
import Setting from '../Setting';
import SettingScreen from '../SettingScreen';
import AddSetting from '../AddSetting'
const Tabs = createBottomTabNavigator({
Request: {
screen: MyForm,
navigationOptions: ({navigation}) => ({
title: 'Request',
tabBarVisible: true,
tabBarIcon: ({tintColor}) => (
<View style={styles.bottomButtons}>
<Ionicons
name="ios-paper"
size={25}
color={tintColor}
/>
</View>
)
})
},
Status: {
screen: MyList,
navigationOptions: ({navigation}) => ({
title: 'Status',
tabBarVisible: true,
tabBarIcon: ({tintColor}) => (
<View style={styles.bottomButtons}>
<Ionicons
name="ios-alarm"
size={25}
color={tintColor}
/>
</View>
)
})
},
Setting: {
screen: Setting,
navigationOptions: ({navigation}) => ({
title: 'Setting',
tabBarVisible: true,
tabBarIcon: ({tintColor}) => (
<View style={styles.bottomButtons}>
<Ionicons
name="ios-settings"
size={25}
color={tintColor}
/>
</View>
)
})
},
AddSetting: {
screen: AddSetting,
navigationOptions: ({navigation}) => ({
title: 'AddSetting',
tabBarVisible: false,
tabBarIcon: ({tintColor}) => (
<View style={styles.bottomButtons}>
<Ionicons
name="ios-settings"
size={25}
color={tintColor}
/>
</View>
)
})
},
Manager: {
screen: Manager,
navigationOptions: ({navigation}) => ({
title: 'Manager',
tabBarVisible: false,
tabBarIcon: ({tintColor}) => (
<View style={styles.bottomButtons}>
<Ionicons
name="ios-person"
size={25}
color={tintColor}
/>
</View>
)
})
}
});
const SwitchNavigator = createSwitchNavigator({
Login: {
screen: Login
},
Signup: {
screen: Signup
},
Home: {
screen: Tabs
}
},
{
initialRouteName: 'Login'
}
)
export default createAppContainer(SwitchNavigator)
const styles = StyleSheet.create({
buttonBottom: {
width: 200
},
textFont:{
fontFamily:'arial',
size:20,
alignItems: 'center',
}
})
Please advise.
Regards,
Micheale
you'll have to make use of StackNavigator for those that you want the tabbar to be invisible
const SettingsStack = createStackNavigator({
Setting: {screen: Setting}
})
SettingsStack.navigationOptions = ({navigation}) => {
let tabBarVisible = true;
if(navigation.state.index > 0){
tabBarVisible = false;
}
return {
tabBarVisible,
}
}
const Tabs = createBottomTabNavigator({
SettingsStack :{ screen :SettingsStack }
})
Related
I have a bit of a Problem. I am trying to implement Logout from the Stacknavigator in React native. I have sought online and have not seen any good source to learn a thing or two from.
My source code for App.js is looking somewhat like this.
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View , Image, TextInput, TouchableOpacity,Alert } from 'react-native';
import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {createDrawerNavigator} from 'react-navigation-drawer';
import Icon from 'react-native-vector-icons/SimpleLineIcons';
import Splash from './src/Splash';
import Dashboard from './src/Dashboard';
import DubaiVisaRequest from './src/DubaiVisaRequest';
import HotelReserveRequest from './src/HotelReserveRequest';
import Login from './src/Login';
const DashboardNavigator = createStackNavigator({
'Dashboard':{screen: Dashboard,
navigationOptions: ({navigation}) => ({
headerLeft: () => (
<TouchableOpacity
style={{marginLeft: 20}}
onPress={() => navigation.toggleDrawer()}>
<Icon name="menu" size={12} /></TouchableOpacity>
)})
},
});
const DubaiVisaReqNavigator = createStackNavigator({
'Dubai Visa Request':{screen: DubaiVisaRequest,
navigationOptions: ({navigation}) => ({
headerLeft: () => (
<TouchableOpacity
style={{marginLeft: 20}}
onPress={() => navigation.toggleDrawer()}>
<Icon name="menu" size={12} /></TouchableOpacity>
)})
},
});
const HotelReqNavigator = createStackNavigator({
'Hotel Reservation':{screen: HotelReserveRequest,
navigationOptions: ({navigation}) => ({
headerLeft: () => (
<TouchableOpacity
style={{marginLeft: 20}}
onPress={() => navigation.toggleDrawer()}>
<Icon name="menu" size={12} /></TouchableOpacity>
)})
},
});
const DrawerNavigator = createDrawerNavigator({
Dashboard:{
navigationOptions:{
drawerLabel: 'Dashboard',
},
screen: DashboardNavigator,
},
DubaiVisaRequest:{
navigationOptions:{
drawerLabel: 'Dubai Visas',
},
screen: DubaiVisaReqNavigator,
},
HotelReserveRequest:{
navigationOptions:{
drawerLabel: 'Request Hotel',
},
screen: HotelReqNavigator,
},
});
const AppSwitchNavigator = createSwitchNavigator({
'Splash' : {screen: Splash},
'Login' : {screen : Login},
'Drawer' : {screen: DrawerNavigator}
},
{
initialRouteName: 'Splash'
})
const App = createAppContainer(AppSwitchNavigator);
export default App;
Please I would like to know how I can implement Logout, I tried something like this
const LogoutNavigator = createStackNavigator({
'Hotel Reservation':{screen: Login,
navigationOptions: ({navigation}) => ({
headerLeft: () => (
<TouchableOpacity
style={{marginLeft: 20}}
onPress={() => navigation.navigate('Login')}>
<Icon name="menu" size={12} /></TouchableOpacity>
)})
},
});
But this does not work as I expect. Kindly Assist. I am a bit new to React native.
import {ProfileScreen} from './ProfileScreen';
import {DashboardScreen} from './DashboardScreen';
import {
DrawerNavigator,
createSwitchNavigator,
createAppContainer,
} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {
createDrawerNavigator,
DrawerNavigatorItems,
} from 'react-navigation-drawer';
import {NotificationScreen} from './NotificationScreen';
export class A_HomePage extends Component {
static navigationOptions = {
header: null,
};
state = {
email: '',
};
render() {
this.setState({
email: 'qwerty#gmail.com',
});
return <AppContainer />;
}
}
const ProfileStackNavigator = createStackNavigator(
{
ProfileNavigator: ProfileScreen,
},
{
defaultNavigationOptions: ({navigation}) => {
return {
headerLeft: (
<Icon2
style={{paddingLeft: 10}}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}
/>
),
};
},
},
);
const NotificationScreenStackNavigator = createStackNavigator(
{
NotificationScreenNavigator: NotificationScreen,
},
{
defaultNavigationOptions: ({navigation}) => {
return {
headerLeft: (
<Icon2
style={{paddingLeft: 10}}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}
/>
),
};
},
},
);
const AppDrawerNavigator = createDrawerNavigator(
{ Profile: {
screen: ProfileStackNavigator,
navigationOptions: {
drawerLabel: 'Profile',
drawerIcon: ({tintColor}) => (
<Icon name="glass" size={25} color="#00b33c" />
),
},
},Notification: {
screen:NotificationScreenStackNavigator ,
navigationOptions: {
drawerLabel: 'Notifications',
drawerIcon: ({tintColor}) => (
<Icon4 name="notification" size={25} color="#cc0099" />
),
},
},
},);
const AppSwitchNavigator = createSwitchNavigator(
{
Profile: {screen: ProfileScreen},
Notification: {screen:NotificationScreen},
},);
const AppContainer = createAppContainer(AppSwitchNavigator);
**
here i have created the two drawernavigation and homescreen contains all the stack of
drawernavigator screen how do i pass this.state.email to the profile and notification screen of the drawernavigation or how can i access the states(here is email) in the screens profile and notification screens pls help this can improve my project work i have searched it in google and docs but didnt got any idea **
Use React Redux with Redux
Redux is central state management system which also available for React-Native
React Redux Getting Started
I want to Make TabNavigation Using react-navigation.
like that picture.
Here is picture my App. I want to Touch that 'red-section' But it is now work now
I want to active that section. Please tell me how can i do...
Middle Button is more bigger than others
this is my App.js Code. And I made AddButton Component.
const AppContainer = createStackNavigator(
{
default: createBottomTabNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) => <AntDesign name="home" size={35} color={tintColor} />
}
},
Post: {
screen: () => null,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<TouchableOpacity size={150}
activeOpacity={1}
style={{
width:75,
height:75,
justifyContent: 'center',
alignItems: 'center',
height:80,
marginBottom:80
}}
>
<AddButton/>
</TouchableOpacity>
),
},
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) => <MaterialIcons name="person-outline" size={35} color={tintColor} />
}
}
},
{
defaultNavigationOptions: {
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.key === 'Post') {
navigation.navigate('postModal')
} else {
defaultHandler()
}
}
},
tabBarOptions: {
activeTintColor: '#5A2AB7',
inactiveTintColor: '#404040',
showLabel: false,
style: { height: 80 },
}
}
),
postModal: {
screen: PostScreen
}
},
{
mode: 'modal',
headerMode: 'none',
}
)
const AuthStack = createStackNavigator({
Login: LoginScreen,
Register: RegisterScreen
})
export default createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: AppContainer,
Auth: AuthStack
},
{
initialRouteName: "Loading"
}
)
);
here is AddButton.js
import React from 'react'
import {View, StyleSheet, Text, TouchableHighlight, Animated} from 'react-native'
import {FontAwesome5} from '#expo/vector-icons'
export default class AddButton extends React.Component {
render() {
return (
<View style={styles.button} underlayColor='#875EC1'>
<FontAwesome5 name="plus" size= {24} color="#FFF" />
</View>
)
}
}
const styles = StyleSheet.create({
button:{
backgroundColor:'#875EC1',
alignItems:'center',
justifyContent:'center',
width:72,
height:72,
borderRadius:36,
shadowColor:'#875EC1',
shadowRadius:5,
shadowOffset: {height:10},
shadowOpacity:0.3,
elevation:3
}
})
I have a Router.js to set all of my components with react-navigation.
When I click the component FloorScreen headerRight button will show click alert.
Now I want to change it like this.props.navigation.navigate.goBack();
Router.js:
import React, { Component } from 'react';
import { Image, TouchableOpacity } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
// and import some screen...
const Router = createStackNavigator({
WelcomeScreen: {
screen: WelcomeScreen,
navigationOptions: () => ({
header: null
}),
},
HomeScreen: {
screen: HomeScreen
},
FloorScreen: {
screen: FloorScreen,
navigationOptions: {
drawerLabel: 'test',
headerStyle: {
backgroundColor: commonColor.appBackgroundColor,
},
headerRight: (
<TouchableOpacity onPress={() => alert('click')}>
<Image style={{ width: 20, height: 20}} source={BackIcon} />
</TouchableOpacity>
)
}
}
},
{
initialRouteName: 'WelcomeScreen',
headerMode: 'screen'
});
export default createAppContainer(Router);
I know I can set the code in FloorScreen.js to achieve it:
static navigationOptions = ({ navigation }) => ({
headerRight : (
<TouchableOpacity onPress={() => { navigation.goBack() }}>
<Image />
</TouchableOpacity>
),
});
Is possible to set the code in my Router.js ? Or set the code in FloorScreen.js is the only way to do it ?
Any help would be appreciated.
You can implement it at navigationOption
navigationOptions: () => ({
tabBarLabel: strings.labelJobs,
tabBarIcon: ({ tintColor }) => (
<Icon type="FontAwesome" name="someName" />
),
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.index > 0) {
navigation.dispatch(StackActions.popToTop());
}
defaultHandler();
}
})
The above is to demonstrate how to display first screen of stack, just to show you how you can access navigation within navigationOptions
I want to create a header on top with title for each screen and button on the right to open the drawer in react navigation 3.x
In the code below the header does not show.
//Updated with Current code
import React, { Component } from 'react';
import { Button } from 'react-native';
import {
createStackNavigator,
createDrawerNavigator,
createAppContainer
} from 'react-navigation';
import MyHomeScreen from './components/HomeScreen';
import MyNotificationsScreen from './components/ProfileScreen';
const MyDrawerNavigator = createDrawerNavigator(
{
Home: {
screen: MyHomeScreen
},
Notifications: {
screen: MyNotificationsScreen
}
},
{
initialRouteName: 'Home',
navigationOptions: navigationOptionsHeader
}
);
const navigationOptionsHeader = ({ navigation }) => {
return {
headerTitle: 'MY Home',
headerRight: (
<Button
onPress={() => navigation.toggleDrawer()}
title="Info"
color="#222"
/>
)
};
};
const AppContainer = createAppContainer(MyDrawerNavigator);
class App extends Component {
render() {
return <AppContainer />;
}
}
export default App;
Use this inside your screen class
static navigationOptions = ({ navigation }) => {
return {
title: 'Home',
headerLeft: (
< Icon name="menu" size={30} style={{marginStart:10}} backgroundColor="#000000" onPress={() => navigation.openDrawer()} > < /Icon>
),
};
};
try this
const MyDrawerNavigator = createDrawerNavigator(
{
Home: {
screen: MyHomeScreen
},
Notifications: {
screen: MyNotificationsScreen
}
},
{
initialRouteName: 'Home'
navigationOptions: navigationOptionsHeader,
}
);
const navigationOptionsHeader=({navigation})=>{
return {
headerRight: (
<Button
onPress={() => navigation.toggleDrawer();
}
title="Info"
color="#222"
/>
)
};
}
you can also add other stuffs in header like this
const navigationOptionsHeader=({navigation})=>{
return {
headerRight: (
<Button
onPress={() => navigation.toggleDrawer();
}
title="Info"
color="#222"
/>
)
headerLeft : <headerLeft/>,
title: //Header Title
headerStyle: { backgroundColor: '#161616', height:48, },
headerTitleStyle:{ color:'#cd9bf0', fontWeight: '400', alignSe
};
}
The navigationoptions had been renamed as defaultNavigationOptions in v3.
Please refer the documentation from https://reactnavigation.org/docs/en/headers.html
For React Navigation 5
Use the prop options as a function:
<Stack.Screen
name="screen name"
component={ScreenComponent}
options={({ navigation }) => ({
headerRight: (props) => {
return <Button onPress={() => navigation.toggleDrawer() }} />
}
})}
/>
https://reactnavigation.org/docs/upgrading-from-4.x/#configuring-the-navigator
For react navigation 5.x
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerLeft: () => (
<View>
<Icon
onPress={() => navigation.toggleDrawer()}
name="menu"
/>
</View>
),
}}
/>