how to add another screen on navigator - reactjs

I'm using a tab bottom navigator in my project. I want to show a new page in a tab of the tab bottom navigator but I want the tab navigator to appear again at the bottom. I don't want to add the button of the new page I want to show below. How do I manage this situation.I created the new scene as another js file and added it to the app js. I mean. I have a button to redirect to a new page in the Home tab, but how do I navigate
my navigator codes in app.js:
import LoadingScreen from './screens/LoadingScreen'
import HomeScreen from './screens/HomeScreen'
import LoginScreen from './screens/LoginScreen'
import RegisterScreen from './screens/RegisterScreen'
import ProfileScreen from './screens/profileScreen'
import NotificationScreen from './screens/notificationScreen'
import PostScreen from './screens/postScreen'
import soruOnaylaScreen from './screens/soruOnaylaScreen'
const AppContainer = createStackNavigator(
{
default: createBottomTabNavigator(
{
soruOnayla: {
screen: soruOnaylaScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-chatboxes" size={24} color={tintColor} />
}
},
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-home" size={24} color={tintColor} />
}
},
Post: {
screen: PostScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons
name="ios-add-circle"
size={36}
color='#E9446A'
style={{
shadowColor: "#E9446A",
shadowOffset: { width: 0, height: 0 },
shadowRadius: 10,
shadowOpacity: 0.3
}}
/>
}
}
, Notification: {
screen: NotificationScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-notifications" size={24} color={tintColor} />
}
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-person" size={24} color={tintColor} />
}
}
},
{
tabBarOptions: {
activeTintColor: "#161f3d",
inactiveTintColor: "#b8bbc4",
}
}
),
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"
}
)
)

Related

Can't show custom header in tabNavigator

I can't show my custom header with static navigation options. It's only TabNavigator on my Title. What should I do?
This is my HomeScreen Component;
export default class Home extends Component {
static navigationOptions = ({navigation}) => ({
title: 'MENEMENOYS',
headerLeft : (
<TouchableOpacity
onPress={() => {
AuthStore.LogOut().then(() => {
navigation.navigate('LoginPage');
});
}}>
<Icon
name="md-log-out"
size={30}
color={'white'}
style={{marginLeft:10}}
/>
</TouchableOpacity>
)
})
And this is my router : stack navigator with tab navigator.
const TabNavigator = createBottomTabNavigator(
{
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon
name="md-home"
size={30}
color={tintColor}
style={styles.homeIcon}
/>
),
},
},
AddNewCar: {
screen: AddNewCar,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon
name="md-add-circle"
size={40}
color={tintColor}
style={styles.addIcon}
/>
),
},
},
OtoparkList: {
screen: OtoparkList,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<IconAwesome name="car" size={30} color={tintColor} />
),
},
},
},
{
tabBarOptions: {
showLabel: false,
activeTintColor: '#41AB5F',
inactiveTintColor: 'white',
style: {
backgroundColor: '#1F202D',
borderTopColor: 'transparent',
},
},
},
);
const AppNavigator = createStackNavigator(
{
TabNavigator: {
screen: TabNavigator,
navigationOptions: {
}
},
LoginPage: {
screen: LoginPage,
navigationOptions: {
headerShown: false,
},
},
ParkingDetail: {
screen: ParkingDetail,
navigationOptions: {
headerShown: false,
},
},
Print: {
screen: Print,
navigationOptions: {
headerShown: false,
}
}
},
{
initialRouteName: 'LoginPage',
},
);
But my header is not shown. Only Header title:TabNavigator and default back button.
Where am i doing wrong ? Please help me. Thanks.
Hey in React navigation latest version 5.x syntax is changed try following
Take a look at doc here Header buttons
static navigationOptions = ({ navigation }) => {
return {
headerTitle: () =>(
<View>
<Text>MENEMENOYS</Text>
</View>
),
headerLeft: () => (
<TouchableOpacity
onPress={() => {
AuthStore.LogOut().then(() => {
navigation.navigate('LoginPage');
});
}}>
<Icon
name="md-log-out"
size={30}
color={'white'}
style={{marginLeft:10}}
/>
</TouchableOpacity>
),
};
};

Is there way to create a navigation that not include in BottomTabNavigator using React Navigation?

I'm currently new developing a project using React Native, and I have problem regarding creating a navigation which, I won't allow the navigation will insert on the BottomTabNavigator. I have module where when i press the Setting my screen will go to the ProfileScreen.
Question: How can I navigate screen that not include in the BottomTabNavigator?
Import File:
import React, {Component} from 'react';
import {Platform, StyleSheet, View, YellowBox, Dimensions, AppRegistry, Image, TouchableOpacity, AsyncStorage,} from 'react-native';
import axios from 'axios';
import {Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, Item, Input,Toast} from 'native-base';
import {
createSwitchNavigator,
createAppContainer,
createStackNavigator,
createDrawerNavigator,
createBottomTabNavigator
}
from 'react-navigation';
import Fa5Icons from 'react-native-vector-icons/FontAwesome5';
import Mat5Icons from 'react-native-vector-icons/MaterialCommunityIcons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import AuthLoadingScreen from './Screens/AuthLoadingScreen';
import SignInScreen from './Screens/SignInScreen';
import DriverSettingScreen from './Screens/DriverSettingScreen';
import DriverHistoryScreen from './Screens/DriverHistoryScreen';
import DriverDashScreen from './Screens/DriverDashScreen';
import DriverNotificationScreen from './Screens/DriverNotificationScreen';
import DriverAssignOrderScreen from './Screens/DriverAssignOrderScreen';
import DriverProfileScreen from './Screens/DriverProfileScreen';
Navigation:
const AuthStackNavigator = createStackNavigator({
SignIn: SignInScreen,
});
let that = this;
const AppTabNavigator = createBottomTabNavigator({
DriverDashScreen: {
screen:DriverDashScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Home",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverDashScreen') {
return <Fa5Icons name='compass' size={22} color={tintColor} />
}
else
{
return <Fa5Icons name='compass' size={22} style={{color:'black'}}/>
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverAssignOrderScreen: {
screen:DriverAssignOrderScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Orders",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverAssignOrderScreen') {
return <Mat5Icons name='food' size={27} color={tintColor} />
}
else
{
return <Mat5Icons name='food' size={27} style={{color:'black'}} />
}
},
tabStyle: { justifyContent: 'center', alignItems: 'center', paddingVertical: 5 },
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverHistoryScreen: {
screen:DriverHistoryScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"History",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverHistoryScreen') {
return <Fa5Icons name='history' size={19} color={tintColor} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverNotificationScreen: {
screen:DriverNotificationScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Notification",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverNotificationScreen') {
return <MaterialIcons name='notifications-active' size={22} color={tintColor} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverSettingScreen: {
screen:DriverSettingScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Account",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverSettingScreen') {
return <MaterialIcons name='account-circle' size={22} color={tintColor} />
}
else
{
return <MaterialIcons name='account-circle' size={22} style={{color:'black'}} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
})
const AppStackNavigator = createStackNavigator({
AppTabNavigator: {
screen:AppTabNavigator
}
},{
header: null,
headerMode: 'none'
});
const AppDrawerNavigator = createDrawerNavigator({
Home:AppStackNavigator,
})
export default createAppContainer(createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
Auth:AuthStackNavigator,
App: AppDrawerNavigator,
},
{
initialRouteName: 'AuthLoading',
}
))
My Action Button:
<ListItem icon onPress={() => navigate('DriverProfileScreen')}>
<Left>
<Button style={{ backgroundColor: "#FF9501", width:25, height:25}}>
<Icon type="MaterialIcons" name="settings" style={{fontSize:16}}/>
</Button>
</Left>
<Body>
<Text style={{fontSize:14}}>Settings</Text>
</Body>
<Right>
<Icon name="arrow-forward" />
</Right>
</ListItem>
Import File:
import React, {Component} from 'react';
import {Platform, StyleSheet, View, YellowBox, Dimensions, AppRegistry,
Image, TouchableOpacity, AsyncStorage,} from 'react-native';
import axios from 'axios';
import {Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, Item, Input,Toast} from 'native-base';
import {
createSwitchNavigator,
createAppContainer,
createStackNavigator,
createDrawerNavigator,
}
from 'react-navigation';
import Fa5Icons from 'react-native-vector-icons/FontAwesome5';
import Mat5Icons from 'react-native-vector-icons/MaterialCommunityIcons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import AuthLoadingScreen from './Screens/AuthLoadingScreen';
import SignInScreen from './Screens/SignInScreen';
import DriverSettingScreen from './Screens/DriverSettingScreen';
import DriverHistoryScreen from './Screens/DriverHistoryScreen';
import DriverDashScreen from './Screens/DriverDashScreen';
import DriverNotificationScreen from './Screens/DriverNotificationScreen';
import DriverAssignOrderScreen from './Screens/DriverAssignOrderScreen';
import DriverProfileScreen from './Screens/DriverProfileScreen';
Navigation:
const AuthStackNavigator = createStackNavigator({
SignIn: SignInScreen,
});
let that = this;
const stackNav = createStackNavigator({
DriverDashScreen: {
screen: DriverDashScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverAssignOrderScreen: {
screen: DriverAssignOrderScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverHistoryScreen: {
screen: DriverHistoryScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverNotificationScreen: {
screen: DriverNotificationScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverSettingScreen: {
screen: DriverSettingScreen,
navigationOptions: ({ navigation }) => ({
})
},
})
const AppDrawerNavigator = createDrawerNavigator({
Home:stackNav,
})
export default createAppContainer(createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
Auth:AuthStackNavigator,
App: AppDrawerNavigator,
},
{
initialRouteName: 'AuthLoading',
}
))
My Action Button:
<ListItem icon onPress={() =>
this.props.navigation.navigate('DriverSettingScreen')}>
<Left>
<Button style={{ backgroundColor: "#FF9501", width:25, height:25}}>
<Icon type="MaterialIcons" name="settings" style={{fontSize:16}}/>
</Button>
</Left>
<Body>
<Text style={{fontSize:14}}>Settings</Text>
</Body>
<Right>
<Icon name="arrow-forward" />
</Right>
</ListItem>

createBottomTabNavigator keep stackes mounted

I have an top level SwitchNavigator with two stacks (AuthStack and MainStack)
MainStack contains the stack of an logged user.
When I try to switch from one screen to other it's fine, but if I start an action that change the state of the current screen, if I leave and then come back the state keeps the same, it's like the screens was not unmounted when I switch between others.
Working example: https://snack.expo.io/HJrslFk34
Try to move to settings, click on "add" and then switch between the screens, the state keeps the same and screens were not being unmounted
const MainStack = createBottomTabNavigator(
{
[homeDrawerLabel]: {
screen: HomeNavigator,
navigationOptions: {
tabBarLabel: homeDrawerLabel,
tabBarIcon: ({ tintColor }) => (
<Ionicons
name="ios-bookmarks"
size={25}
color={tintColor}
/>
),
},
},
[calendarDrawerLabel]: {
screen: CalendarNavigator,
navigationOptions: {
tabBarLabel: calendarDrawerLabel,
tabBarIcon: ({ tintColor }) => (
<Ionicons
name="ios-bookmarks"
size={25}
color={tintColor}
/>
),
headerLayoutPreset: "center",
},
},
[messagesDrawerLabel]: {
screen: MessagesNavigator,
navigationOptions: {
tabBarLabel: messagesDrawerLabel,
tabBarIcon: ({ tintColor }) => (
<Ionicons
name="ios-bookmarks"
size={25}
color={tintColor}
/>
),
},
},
[notificationsDrawerLabel]: {
screen: NotificationsNavigator,
navigationOptions: {
tabBarLabel: notificationsDrawerLabel,
tabBarIcon: ({ tintColor }) => (
<IconNavigatorWithBadge
badgeCount={3}
name="md-checkmark-circle"
size={25}
color={tintColor}
/>
),
},
},
EditProfile: { screen: EditProfile },
[paymentDrawerLabel]: {
screen: PaymentsNavigator,
navigationOptions: {
tabBarLabel: paymentDrawerLabel,
tabBarIcon: ({ tintColor }) => (
<Ionicons
name="ios-bookmarks"
size={25}
color={tintColor}
/>
),
},
},
},
{
tabBarOptions: {
activeTintColor: "#29C2AF",
inactiveTintColor: "rgba(41, 194, 175, 0.4)",
style: {
height: 60,
paddingVertical: 10,
borderTopColor: "rgba(0,0,0,0.2)",
shadowColor: "#000",
shadowOffset: {
width: 2,
height: 5,
},
shadowOpacity: 0.75,
shadowRadius: 3.84,
elevation: 7,
},
},
headerMode: "none",
headerLayoutPreset: "center",
},
);
const AppNavigator = createSwitchNavigator(
{
AuthStack: AuthStack,
Main: MainStack,
},
{
headerMode: "none",
initialRouteName: "AuthStack",
}
);
const AppContainer = createAppContainer(AppNavigator);
With React Navigation, Tab Navigator views are not unmounted when switching between tabs. You can see the details about the lifecycle in react-navigation in their documentation here: Navigation lifecycle - Example scenario, the important part being here:
We start on the HomeScreen and navigate to DetailsScreen. Then we use the tab bar to switch to the SettingsScreen and navigate to ProfileScreen. After this sequence of operations is done, all 4 of the screens are mounted!
If you want to know and act on the active tab, what you will be looking for are the focus/blur events outlined here

MaterialBottomTabNavigator / React-Native / React Navigation

im using the Material-Bottom-Tab-Navigatior and would like to get a transparent bar background however my result atm looks like this
This is the code
import React from 'react';
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs';
import Icon from 'react-native-vector-icons/Feather';
import HomePage from '../components/whatsOn/HomePage';
import ComingSoon from '../components/comingSoon/ComingSoon';
import Favourites from '../components/favourites/Favourites';
import config from '../static/config.json';
import texts from '../static/texts.json';
const { gradient } = config.colors;
const { ComingSoonTitle, HomeTitle, FavouritesTitle } = texts.Tabs;
const lang = config.language;
export const TabStack = createMaterialBottomTabNavigator({
comingSoon: {
screen: ComingSoon,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: ComingSoonTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="calendar" color={tintColor} size={24} />),
},
},
whatsOn: {
screen: HomePage,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: HomeTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="film" color={tintColor} size={24} />),
},
},
favourites: {
screen: Favourites,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: FavouritesTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="star" color={tintColor} size={24} />),
},
},
}, {
shifting: true,
initialRouteName: 'whatsOn',
order: ['comingSoon', 'whatsOn', 'favourites'],
tabBarPosition: 'bottom',
});
this TabStack is nested inside this stack:
export const HomeStack = createStackNavigator({
Tabs: {
screen: TabStack,
navigationOptions: {
title: 'Compeso',
header: props => <CustomHeader {...props} />,
headerStyle: {
backgroundColor: 'transparent',
},
headerTitleStyle: {
fontSize: 24,
fontWeight: '500',
color: colors.typography,
},
headerRight: MenuIcon,
headerLeft: SearchIcon,
animationEnabled: true,
},
},
Drawer: {
screen: MoreInfromation,
},
}, {
initialRouteName: 'Tabs',
cardStyle: { backgroundColor: 'transparent' },
});
the HomeStack is nested in a switchNavigator
export default class Router extends Component {
render() {
return (
<MainStack />
);
}
}
const MainStack = createSwitchNavigator({
Auth: LoginStack,
Home: HomeStack,
},
{
initialRouteName: 'Home',
});
This MainStack is getting rendered in my App.js
I put this tab navigator into a stack navigator and each component that gets displayed shows a scroll view with a height of 815 pixels to make sure the background is behind the bar.
Can someone advice ?
Thanks in advance
You need to include barStyle.
So, for transparent the style will be something like this:
barStyle: {backgroundColor:'transparent'}
In your code it will look something like this(included at bottom).
export const TabStack = createMaterialBottomTabNavigator({
comingSoon: {
...
},
...
}, {
shifting: true,
initialRouteName: 'whatsOn',
order: ['comingSoon', 'whatsOn', 'favourites'],
tabBarPosition: 'bottom',
barStyle: {backgroundColor:'transparent'}
});

ReactNative:How to change the header for tab navigator inside a drawer navigator

I am building a react native app with a login and profile screen.The navigation is as below:
I wanted to change the header title when I navigate to each tabs.Also, i want my drawer to be able to open from any screen.So drawer icon should always be in the profile at left.
I cant make the header none/hide in profile screen as it will hide the drawer icon as well.Any idea how to solve it?
const TabStack = TabNavigator(
{
Home: {
screen: Home
},
Settings: {
screen: SettingsTab
}
}
);
const DrawerMain = DrawerNavigator(
{
TabStack: {
screen: TabStack
}
},
{
drawerOpenRoute: "DrawerOpen",
drawerCloseRoute: "DrawerClose"
);
const Profile = StackNavigator(
{
DrawerMain: {
screen: DrawerMain
}
},
{
headerMode: "screen",
navigationOptions: ({ navigation }) => ({
headerStyle: {
backgroundColor: "white"
},
headerLeft: (
<TouchableOpacity
onPress={() => {
if (navigation.state.index === 0) {
navigation.navigate("DrawerOpen");
} else {
navigation.navigate("DrawerClose");
}
}}
>
<Icon name={"ios-menu"} size={20} style={{ color: "red" }} />
</TouchableOpacity>
)
})
}
);
export default (App = StackNavigator({
Login: {
screen: Login
},
Profile: {
screen: Profile,
}
}));
This is how the profile should look like.
First, change your navigation hierarchy to like this.
Drawer
ㄴ Stack
__ ㄴ Tab
Then, you need to pass DrawerNavigator's navigation to StackNavigator to control a drawer from a button in StackNavigator.
And use it through screenProps.
...
const Profile = StackNavigator(
{
TabStack: {
screen: TabStack
}
},
navigationOptions: ({ screenProps }) => ({
...
headerLeft: (
<TouchableOpacity
onPress={() => {
screenProps.myDrawerNavigation.navigate("DrawerOpen");
}}
>
<Icon name={"ios-menu"} size={20} style={{ color: "red" }} />
</TouchableOpacity>
)
...
const DrawerMain = DrawerNavigator(
{
Profile: {
screen: ({navigation}) => <Profile screenProps={{myDrawerNavigation:navigation}}/>
}
},
...

Resources