I want to know how to combine bottom tab navigator with Stack Navigator on Home Navigator in app.js
Here is my code
import React from 'react';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import Signup from './screens/signup';
import Login from './screens/login';
import Home from './screens/Home';
import Loading from './screens/Loading';
import Welcome from './screens/Welcome';
import ForgotPassword from './screens/ForgotPassword';
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
const navigator = createStackNavigator({
loading: {
screen: Loading,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
Welcome: {
screen: Welcome,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
signup: {
screen: Signup,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
login: {
screen: Login,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
Home: {
screen: Home,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
InitialRouteName: Loading,
});
const AppContainer = createAppContainer(navigator);
Any suggest to add bottom tab navigator in this code? I want to know how to combine Tab bottom navigator with stack navigator in app.js (calling home with bottom tab navigator)
thanks
You can create a tabNavigator and set it like any other route.
Obs: Also work for drawerNavigator.
Example:
const MainTab = TabNavigator(tabs, {
initialRouteName: initialRouteName,
tabBarPosition: "bottom",
});
const RootNavigator = StackNavigator(
{
Root: {
screen: MainTab,
navigationOptions: {
headerMode: "none"
}
},
/* Other Screens */
Login: { screen: LoginScreen },
}
)
const AppContainer = createAppContainer(RootNavigator);
Obs: this also work for drawerNavigator.
Related
I got the following react-navigation structure :
<NavigationContainer>
{authToken ? (
<Tab.Navigator>
<Tab.Screen
name='HomeScreen'
component={HomeScreen}
/>
<Tab.Screen
name='SettingsScreen'
component={SettingsScreen}
/>
</Tab.Navigator>
) : (
<Stack.Navigator>
<Stack.Screen name="SignUpScreen" component={SignUpScreen} />
</Stack.Navigator>
)}
</NavigationContainer>
How to navigate from SignUpScreen to HomeScreen and conversely :
// HomeScreen.js button :
onPress={() => {
// remove authToken and then :
navigation.navigate(`SignUpScreen`);
}}
Got the error message : The action 'NAVIGATE' with payload {"name":"SignUpScreen"} was not handled by any navigator. Do you have a screen named 'SignUpScreen'?
Same from SignUpScreen after authToken = true.
Is there a way to navigate from one stack to another in a ternary operator ? (Or trigger the index of the navigation to re-render the condition ?).
Assuming what what you want to implement is an App that has a different navigation if you are logged in or out, I would suggest using the Switch navigator. In your case, your error it is most likely caused because the signup screen does not exist in the tree of both stack navigators. I'll post the entire main code but the part you should take a look is this:
const Navigator = createSwitchNavigator({
Main: MainTabNavigator,
Auth: AuthNavigator,
SplashScreen: SplashScreen,
Onboarding: Onboarding,
}, {
initialRouteName: 'SplashScreen',
headerMode: 'none'
});
The rest:
import React from "react";
import { createStackNavigator, createBottomTabNavigator, createSwitchNavigator, createAppContainer } from 'react-navigation';
import {ThemeProvider} from 'styled-components'
import {configureStore} from "./redux/store"
import { Provider } from 'react-redux'
const theme = {
primaryColor: '#3F51B5',
darkPrimaryColor: '#303F9F',
containerBackgroundColor: '#FFFFFF',
lightPrimaryColor: '#C5CAE9',
accentColor: '#FF5722',
backgroundColor: 'white',
font: 'Lato-Regular',
fontBold: 'Lato-Bold'
}
const ConfigNavigator = createStackNavigator({
Config: ConfigScreen,
SettingsScreen: SettingsScreen,
...coreRoutes
}, {
initialRouteName: 'Config',
headerMode: 'none'
});
const HomeNavigator = createStackNavigator({
...coreRoutes
}, {
initialRouteName: 'HomeScreen',
headerMode: 'none'
});
const PlacesNavigator = createStackNavigator({
Places: PlacesScreen,
POI: POIScreen,
}, {
initialRouteName: 'Places',
headerMode: 'none'
});
const PinnedNavigator = createStackNavigator({
Pinned: PinnedScreen,
POI: POIScreen,
}, {
initialRouteName: 'Pinned',
headerMode: 'none'
});
const MainTabNavigator = createBottomTabNavigator({
Home: HomeNavigator,
Places: PlacesNavigator,
Pinned: PinnedNavigator,
Chat: ChatScreen,
Config: ConfigNavigator,
}, {
initialRouteName: 'Home',
tabBarPosition: "bottom",
swipeEnabled: false,
tabBarComponent: props => {
return <TabNavigation {...props}
items={[
{
text: Strings['home'], icon: { name: "home", type: "MaterialCommunityIcons" },
route: "Home"
},
{
text: Strings['places'], icon: { name: "map-marker-multiple", type: "MaterialCommunityIcons"},
route: "Places"
},
{
text: Strings['pinned'], icon: { name: "pin", type: "MaterialCommunityIcons" },
route: "Pinned"
},
{
text: Strings['chat'], icon: { name: "wechat", type: "MaterialCommunityIcons" },
route: "Chat"
},
{
text: Strings['settings'], icon: { name: "settings", type: "MaterialCommunityIcons" },
route: "Config"
}
]}
/>
}
});
const AuthNavigator = createStackNavigator({
Registration: RegistrationScreen,
}, {
initialRouteName: 'Registration',
headerMode: 'none'
});
const Navigator = createSwitchNavigator({
Main: MainTabNavigator,
Auth: AuthNavigator,
SplashScreen: SplashScreen,
Onboarding: Onboarding,
}, {
initialRouteName: 'SplashScreen',
headerMode: 'none'
});
const AppContainer = createAppContainer(Navigator)
let store = configureStore();
class App extends React.Component {
constructor(){
super();
this.theme = new Theme(theme);
}
render(){
return <Provider store={store}>
<ThemeProvider theme={this.theme.getTheme()}>
<AppContainer/>
</ThemeProvider>
</Provider>
}
};
export default App;
From then, you just navigate to Auth or Main and the entire navigator tree changes.
I want to asking about why bottom tab didnt showing at home screen (hidden)
here is my code
import React from 'react';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import Signup from './screens/signup';
import Login from './screens/login';
import Home from './screens/Home';
import Loading from './screens/Loading';
import Welcome from './screens/Welcome';
import ForgotPassword from './screens/ForgotPassword';
import ApplyLoan from './screens/ApplyLoan';
import Profile from './screens/Profile';
import LoanHistory from './screens/LoanHistory';
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs';
export default class App extends React.Component {
render()
{
return (
<AppContainer>
<RootNavigator/>
<MainTab/>
</AppContainer>
);
}
}
const RootNavigator = createStackNavigator({
loading: {
screen: Loading,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
Welcome: {
screen: Welcome,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
signup: {
screen: Signup,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
login: {
screen: Login,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
Home: {
screen: Home,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
ForgotPassword: {
screen: ForgotPassword,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
ApplyLoan: {
screen: ApplyLoan,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
LoanHistory: {
screen: LoanHistory,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
Profile: {
screen: Profile,
navigationOptions: {
headerShown: false,
headerTransparent: true,
},
},
InitialRouteName : Loading
});
const MainTab = createMaterialBottomTabNavigator(
{
Home: { screen: Home,
navigationOptions:{
tabBarLabel:'Home',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon style={[{color: tintColor}]} size={25} name={'ios-home'}/>
</View>),
}
},
Profile: { screen: Profile,
navigationOptions:{
tabBarLabel:'Profile',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon style={[{color: tintColor}]} size={25} name={'ios-person'}/>
</View>),
activeColor: '#f60c0d',
inactiveColor: '#f65a22',
barStyle: { backgroundColor: '#f69b31' },
}
},
},
{
initialRouteName: "Home",
activeColor: '#f0edf6',
inactiveColor: '#226557',
barStyle: { backgroundColor: '#3BAD87' },
},
);
const AppContainer = createAppContainer(RootNavigator, MainTab);
Is something wrong about my code?
I am trying to implement drawer navigator in my react native application. I have used the openDrawer() function in the component that should open the drawer. However on clicking the component the drawer is directly launching the screen inside the drawer rather than simply opening the drawer. Is the way i am using the navigator wrong? Any help would be appreciated.
Navigator.js
import React from 'react';
import { createAppContainer,createSwitchNavigator} from 'react-navigation';
import {createDrawerNavigator } from 'react-navigation-drawer';
import { createStackNavigator } from 'react-navigation-stack';
import {View,Platform,StatusBar} from 'react-native';
import LoginForm from './Components/LoginForm';
import TheatreList from './Components/TheatreList';
import Menu from './Components/Menu';
import EmployeeEdit from './Components/EmployeeEdit';
import CartScreen from './Components/CartScreen';
import Screen from './Components/Screen';
import ShoppingCartIcon from './Components/ShoppingCartIcon';
import PaymentScreen from './Components/PaymentScreen';
import Screen1 from './Screen/Screen1';
import Screen2 from './Screen/Screen2';
import * as Expo from 'expo';
const Navigator = createStackNavigator({
TheatreList:{
screen:TheatreList
} ,
Login: {
screen:LoginForm
},
Menu: {
screen:Menu
},
Cart: {
screen:CartScreen
},
PaymentScreen:{
screen:PaymentScreen
},
},
{
headerMode: 'none',
navigationOptions: {
header: null,
},
},
{
initialRouteName: 'TheatreList'
}
);
const AppDrawerNavigator=createDrawerNavigator(
{
Navigator,
Screen1:{
screen:Screen1
},
Screen2:{
screen:Screen2
}
});
const RootNav=createSwitchNavigator({
Navigator,
AppDrawerNavigator
});
export default createAppContainer(RootNav);
ProfileIcon.js
import React, { Component } from 'react';
import { View, Text, Picker,Button } from 'react-native';
import { connect } from 'react-redux';
import Icon from 'react-native-vector-icons/Entypo';
import { Actions } from 'react-native-router-flux';
import { DrawerActions } from 'react-navigation-drawer';
const ProfileIcon = (props) => (
<View style ={{
position:'absolute',
top:0,
left:0,
right:5,
// padding:7,
width: 40,
height: 40,
borderRadius: 40/2,
border: '1px solid #c45653',
justifyContent: 'center',
marginLeft: 15,padding:7}}>
<Icon name="menu" onPress={() => props.navi.dispatch(DrawerActions.openDrawer())} style ={{fontSize:50, position:'absolute', top:0, right:0,width:40, color:'#fe003a'}} />
</View>
)
export default ProfileIcon;
You need to make nested stacknavigators. Inside AppDrawerNavigator ,call your Navigator stack
Try This
const RootNavigator = createStackNavigator({
DrawerMenu: { screen: DrawerMenu },
Home: { screen: Home },
},
{
initialRouteName: 'Home',
navigationOptions: ({ navigation }) => ({
})
});
const Drawer = createDrawerNavigator({
RootNavigator: {
screen: RootNavigator, //rootNavigator
navigationOptions: { title: 'titleHere' },
},
},
{
initialRouteName: 'RootNavigator',
drawerPosition: 'Left',
backBehavior: 'none',
contentComponent: props => <DrawerMenu {...props} />,
drawerOpenRoute: 'DrawerOpen',
},
);
const LoginNavigator = createStackNavigator({
Login: {
screen: Login,
navigationOptions: {
drawerLockMode: 'locked-closed',
headerStyle: { },
headerTitleStyle: { },
title: 'Title'
}
},
})
export default createSwitchNavigator({
AuthLoading: AuthLoadingScreen, //SplashScreen
LoginNavigator: LoginNavigator,
Drawer: Drawer,
},
{
initialRouteName: 'AuthLoading',
})
i am trying to use stack navigation and tab navigation at the same time,i have created a stack navigator and tabs in my app.js files but whenever my app loads they are showing different pages at the same time and i don,t know how to resolve this issue. my app.js code is
import { createStackNavigator, createAppContainer } from 'react-navigation';
import IntroSlides from './src/screens/introslides/introslides';
import Dashboard from './src/screens/dashboard/dashboard';
import InboxScreen from '../screens/inbox/inbox';
import Favourites from '../screens/favourite/favourite';
const MainNavigator = createStackNavigator({
dashboard: { screen: Dashboard },
intro: { screen: IntroSlides },
}, {
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
});
const TabNavigator = createBottomTabNavigator({
// dashboard: { screen: Dashboard },
Inbox: { screen: InboxScreen },
Favourites: { screen: Favourites }
});
const App = createAppContainer(MainNavigator);
export default App;
when the app loads both the stack shows pages at the same time ,any Help would be appreciated
Here is an example to use tab navigator and stack navigator together:
const Stylelist = StackNavigator({
Login: {
screen: LoginScreen,
navigationOptions: ({ navigation }) => ({
header: null,
}),
},
Register: {
screen: RegisterScreen,
navigationOptions: ({ navigation }) => ({
header: null,
}),
},
Home: {
screen: TabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: ({ navigation }) => ({
title: 'Home',
}),
},
Friends: {
screen: FriendsScreen,
navigationOptions: ({ navigation }) => ({
title: 'My Friends',
}),
},
}),
navigationOptions: ({ navigation }) => ({
title: 'Home',
}),
},
});
export default Stylelist;
Hi friends I am scratching my head with react-navigation from last 2 days, I tried many things(documentation doesn't seems that clear for a beginner), so right now I am facing few problem that seems little complex to me and hence I seek advice and help to proceed further.following are the cases/problem/scenario I seek help for -
react-navigation does not cover the header and statusbar, I wanted to achieve something like gmail but I ended up with like this
I used following code blocks to reach to this point
import React, {Component} from 'react';
import { AppRegistry, View, BackAndroid, StatusBar,} from 'react-native';
import {
NavigationActions,
addNavigationHelpers,
StackNavigator,
DrawerNavigator
} from 'react-navigation';
import LandingScreen from 'src/screens/landingScreen';
import Login from 'src/screens/login'
import SignUp from 'src/screens/signUp'
import ForgotPassword from 'src/screens/forgotPassword'
import Dashboard from 'src/screens/dashboard'
import UserProfile from 'src/screens/userProfile'
export const Drawer = DrawerNavigator({
Dashboard:{
path:'/',
screen:Dashboard,
},
UserProfile:{
path:'/'
screen:UserProfile
},
}, {
initialRouteName: 'Dashboard',
contentOptions: {
activeTintColor: '#e91e63',
},
headerMode: 'screen',
});
const routesConfig = {
Landing:{screen:LandingScreen},
Login: { screen: Login },
SignUp: { screen: SignUp },
ForgotPassword: { screen: ForgotPassword },
Drawer:{screen:Drawer}
};
export const AppNavigator = StackNavigator(routesConfig, {
initialRouteName: 'Drawer'
});
AppRegistry.registerComponent('Riduk', () => AppNavigator);
Other problem is how should I add 2 drawers in my app at the same screen
Here is a simplified example:
const FooStackNavigator = StackNavigator({
Foo: {
screen: FooScreen,
navigationOptions: {
title: 'Foo',
}
},
});
const BarStackNavigator = StackNavigator({...});
const MyDrawerNavigator = DrawerNavigator({
FooStack: {
screen: FooStackNavigator,
navigationOptions: {
drawer: () => ({
label: 'Foo',
})
},
},
BarStack: {
screen: BarStackNavigator,
navigationOptions: {
drawer: () => ({
label: 'Bar',
})
},
}
});
const AppNavigator = StackNavigator({
Drawer: { screen: MyDrawerNavigator },
}, {
headerMode: 'none',
});
There is an issue for Header in DrawerNavigator.
But you can fix by using StackNavigator inside DrawerNavigator
export const Drawer = DrawerNavigator({
Dashboard:{
path:'/',
screen: StackNavigator( { Screen1: {
screen: Dashboard
}})
},
UserProfile:{
path:'/',
screen: StackNavigator( { Screen1: {
screen: UserProfile
}})
},
}});
Then set headerMode: 'none' to root StackNavigator
export const AppNavigator = StackNavigator(routesConfig, {
headerMode: 'none'
});
Here, AppNavigator is root StackNavigator and routesConfig has above DrawerNavigator and other screens.
Is this the issue you're trying to resolve?
https://blog.callstack.io/android-drawer-statusbar-done-right-for-react-native-7e85f01fc099
As per my knowledge, you have to do 2 things:
1. Put drawer control at the top of navigation stack.
2. Set translucent propery of StatusBar
<StatusBar
translucent
backgroundColor="rgba(0, 0, 0, 0.24)"
animated
/>
{ Platform.OS === 'android' && Platform.Version >= 20 ?
<View
style={{
height: 24,
backgroundColor: "#512DA8",
}}
/>
: null }
Kindly let me know if it does work.
DrawerNavigator must over on StackNavigator, this is my way to fix this:
const navStack = StackNavigator({
Home: { screen: Main, },
Example01: { screen: Example01, },
Example02: { screen: Example02, },
});
const navDrawer = DrawerNavigator({
Home: {
screen: navStack, // Drawer over on StackNavigator
navigationOptions: {
drawerLabel: 'Home',
header: null,
}
},
Example03: {
screen: Example03,
navigationOptions: {
drawerLabel: 'Example03',
}
},
},
{
headerMode: 'none',
headerVisible: false,
navigationOptions: {
header: null
}
});
Hope this helps.