Use the main App Header for Nested StackNavigation - react-native

I'm working on a React Native App, which I have on the main App.js file created a Drawer and a Stack Navigatior, the problem that I'm facing is that when I navigate through the Drawer to the Pages with the Stack Navigation, I get 2 Headers (one below the Other), is there a way to use the same header (top header or Main header) when I get to the Stack Pages.
Here is the App.js code:
import 'react-native-gesture-handler';
import React from 'react';
import { StyleSheet} from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createDrawerNavigator } from '#react-navigation/drawer';
import { createStackNavigator } from '#react-navigation/stack';
//Importacion de Screens
import HomeScreen from './src/screens/HomeScreen';
import DetailsScreen from './src/screens/DetailScreen';
import OrderSearchScreen from './src/screens/OrderSearchScreen';
import OrderNumberScreen from './src/screens/OrderNumberScreen';
const OrderStack = createStackNavigator();
const Drawer = createDrawerNavigator();
const OrderStackScreen = () =>(
<OrderStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#009387',
},
headerTintColor: '#fff',
headerTitleStyle:{
fontWeight: 'bold',
} ,
headerTitleStyle: { alignSelf: 'center' },
/*headerShown: false*/
}}>
<OrderStack.Screen name="OrderSearchScreen" component={OrderSearchScreen}/>
<OrderStack.Screen name="OrderNumberScreen" component={OrderNumberScreen}/>
</OrderStack.Navigator>
);
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home" screenOptions={{
headerStyle: {
backgroundColor: '#009387',
},
headerTintColor: '#fff',
headerTitleStyle:{
fontWeight: 'bold',
} ,
headerTitleStyle: { alignSelf: 'center' },
}}>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Details" component={DetailsScreen} />
<Drawer.Screen name="Orders" component={OrderStackScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Here is what I see inside the Stack:
What I wish to see is that the top Header Changes and the Bottom one never appears, so the Top Header will have the Title of the Page being visited and right next to the Drawer Icon (the 3 lines, I think it is called Hamburger button), I get the Arrow to go back.
Is there a way to do this.
Thanks

Hide the stack header likes this:
<OrderStack.Navigator screenOptions={{ headerShown: false }}>
{/* whatever */}
</OrderStack.Navigator>
Configure the drawer header to show stack's screen name:
import { getFocusedRouteNameFromRoute } from '#react-navigation/native';
// ...
<Drawer.Navigator
initialRouteName="Home"
screenOptions={({ route }) => {
const routeName =
getFocusedRouteNameFromRoute(route) ?? 'OrderSearchScreen';
let headerTitle;
switch (routeName) {
case 'OrderSearchScreen':
headerTitle = 'Search';
break;
case 'OrderNumberScreen':
headerTitle = 'Order no.';
break;
}
return {
headerTitle,
headerShown: true,
headerStyle: { backgroundColor: '#009387' },
headerTintColor: '#fff',
headerTitleStyle: { fontWeight: 'bold' },
headerTitleAlign: 'center',
};
}}
>
{/* whatever */}
</Drawer.Navigator>;
Docs: https://reactnavigation.org/docs/screen-options-resolution/#setting-parent-screen-options-based-on-child-navigators-state
If you want to show both hamburger menu and back icon, you need to use headerLeft to override the default one. Though it's very unusual to show both at once.

Related

React Navigation how to hide tabbar inside stack navigation

I'm new to react native, I couldn't do what I wanted to do.
The situation is
When I click the button in the SettingsScreen, I Hide the Bottom Tab, but
The thing I can't understand is,
Is my path and course wrong?
Tab Bottom Height changes, thank you in advance for your help.
import * as React from 'react';
import { getFocusedRouteNameFromRoute } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import SettingScreen from '../screen/SettingScreen';
import SettingDetails from '../screen/SettingDetails';
const Stack = createStackNavigator();
const tabHiddenRoutes = ['SettingDetails'];
function SettingStack({ navigation, route }) {
React.useLayoutEffect(() => {
if (tabHiddenRoutes.includes(getFocusedRouteNameFromRoute(route))) {
navigation.setOptions({ tabBarStyle: { display: 'none' } });
} else {
navigation.setOptions({ tabBarStyle: { display: 'flex' } });
}
}, [navigation, route]);
return (
<Stack.Navigator
initialRouteName="Setting"
screenOptions={{
headerBackTitleVisible: false,
headerTitleAlign: 'center',
headerStyle: {
backgroundColor: '#5D3EBD',
},
headerTitleStyle: {
color: '#fff',
},
headerBackTitleStyle: {
color: '#fff',
},
headerTintColor: '#fff',
}}>
<Stack.Screen
name="Setting"
component={SettingScreen}
options={{ title: 'Setting Page' }}
/>
<Stack.Screen
name="SettingDetails"
component={SettingDetails}
options={{ title: 'Setting Details' }}
/>
</Stack.Navigator>
);
}
export default SettingStack;
Snack

Delayed rendering of parent Drawer header inside Bottom Tab

I have BottomTab navigator with 2 screens Home and Activity, nested inside a Drawer Navigator. When I switch from one screen to second one using BottomTab, my header of Drawer Navigator hides with flickering effect and same thing happens again when I show it up on previous screen. I am handling headerShown:true and headerShown:false in listeners prop of Tab.Screen using focus and blur of that screen.
It seems like header is rendering after rendering of components below it. This header showing and hiding has more delay if I have multiple components inside both screens.
Snack repo is attached.
https://snack.expo.dev/#a2nineu/bottomtab-inside-drawer
I suggest you use Interaction Manager
As react-native is single threaded, JS gets blocked while running animation which can cause UI to lag and jitter.
Attaching code with changes
import 'react-native-gesture-handler';
import * as React from 'react';
import {
Text,
View,
StyleSheet,
Image,
InteractionManager,
} from 'react-native';
import Constants from 'expo-constants';
import { NavigationContainer } from '#react-navigation/native';
import { createDrawerNavigator } from '#react-navigation/drawer';
import { createMaterialBottomTabNavigator } from '#react-navigation/material-bottom-tabs';
const Drawer = createDrawerNavigator();
const Tab = createMaterialBottomTabNavigator();
const Home = (props) => {
React.useEffect(() => {
const interactionPromise = InteractionManager.runAfterInteractions(() =>
setShowContent(true)
);
return () => interactionPromise.cancel();
}, []);
const [showContent, setShowContent] = React.useState(false);
return showContent ? (
<View>
<Text>Home</Text>
<Image
source={{
uri: 'https://images.unsplash.com/photo-1596265371388-43edbaadab94?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80',
}}
style={{ height: 500, width: 500 }}
resizeMode={'cover'}></Image>
</View>
) : null;
};
const Activity = () => {
return <Text>Activity</Text>;
};
const BottomTab = () => {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen
name="Activity"
component={Activity}
listeners={({ navigation, route }) => ({
focus: () => {
navigation.getParent().setOptions({
headerShown: false,
});
},
blur: () => {
navigation.getParent().setOptions({
headerShown: true,
});
},
})}
/>
</Tab.Navigator>
);
};
export default function App() {
return (
<View style={styles.container}>
<NavigationContainer>
<Drawer.Navigator screenOptions={{ headerMode: 'float' }}>
<Drawer.Screen
options={{ headerStyle: { height: 100 } }}
name="BottomTab"
component={BottomTab}
/>
</Drawer.Navigator>
</NavigationContainer>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});

Expo Ref usage and Navigation Container Conflicting

I am using Expo Camera to take some user pictures for a profile form. What is happening is when I try to set camera's ref to a state it crashes and throw the following error.
Couldn't find a navigation context. Have you wrapped your app with
'NavigationContainer'? See
https://reactnavigation.org/docs/getting-started for setup
instructions.
Everything is inside a Navigation Container and I really can't figure out what is happening.
Every time I comment ref={(ref) => console.tron.log(ref)} from Expo Camera component everything works fine, but when I uncomment the ref line I get the error.
I am stuck here since last week and nothing on internet about this problem...
Thanks in advance =)
App.js
import React from 'react';
import { NavigationContainer } from '#react-navigation/native';
import { AuthProvider } from './src/context/authContext';
import Routes from './src/routes';
import Theme from './src/theme';
import './src/config/reactotron.config';
export default function App() {
return (
<Theme>
<AuthProvider>
<NavigationContainer>
<Routes />
</NavigationContainer>
</AuthProvider>
</Theme>
);
}
routes.js
import React from 'react';
import { createStackNavigator } from '#react-navigation/stack';
import arrowLeft from '../../assets/img/arrow-left-header.png';
import SignUp from '../pages/auth/SignUp';
import Profile from '../pages/auth/Profile';
import Login from '../pages/auth/Login';
import Habits from '../pages/auth/Habits';
import AddChildren from '../pages/auth/AddChildren';
import ChildProfile from '../pages/auth/ChildProfile';
import RegisterFinish from '../pages/auth/RegisterFinish';
import { CameraView } from '../components';
const AuthStack = createStackNavigator();
const theme = {
color: {
brandPrimary: '#16B4A1',
white: '#fff',
},
};
const AuthRoutes = () => {
return (
<AuthStack.Navigator
screenOptions={{
headerTintColor: theme.color.white,
headerStyle: {
backgroundColor: theme.color.brandPrimary,
},
cardStyle: {
backgroundColor: theme.color.white,
},
headerBackTitle: 'Voltar',
}}
>
<AuthStack.Screen
name='Profile'
component={Profile}
options={{
headerLeft: null,
}}
/>
<AuthStack.Screen
name='Login'
component={Login}
options={{ headerShown: false }}
/>
<AuthStack.Screen
name='SignUp'
component={SignUp}
options={{ headerShown: false }}
/>
<AuthStack.Screen
name='RegisterFinish'
component={RegisterFinish}
options={{
headerLeft: null,
headerShown: false,
}}
/>
<AuthStack.Screen
name='TakeAPicture'
component={CameraView}
options={{
headerLeft: null,
headerShown: false,
}}
/>
<AuthStack.Screen name='Habits' component={Habits} />
<AuthStack.Screen name='AddChildren' component={AddChildren} />
<AuthStack.Screen name='ChildProfile' component={ChildProfile} />
</AuthStack.Navigator>
);
};
export default AuthRoutes;
CameraView.js
import React, { useState, useEffect, useRef } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
import { Camera } from 'expo-camera';
import { FontAwesome5 } from '#expo/vector-icons';
import { CameraButton, CameraButtonRing } from './styles';
const CameraView = ({ route, navigation }) => {
const cameraRef = useRef()
// CAMERA SETTINGS
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.front);
useEffect(() => {
console.tron.log('rolou')
async function handleCameraPermission() {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
}
handleCameraPermission();
}, []);
const handleTakePictureButton = async () => {
if (!cameraRef) {
console.tron.log('Não tem cam ref')
return
};
let photo = await cameraRef.takePictureAsync();
console.tron.log(photo)
handlePicture(photo)
}
return (
<View style={{ flex: 1 }}>
<Camera
style={{ flex: 1 }}
type={type}
ref={(ref) => console.tron.log(ref)}
>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
border: '1px solid red '
}}
>
<TouchableOpacity
style={{
// flex: ,
// alignSelf: 'flex-end',
// alignItems: 'center',
position: 'absolute',
bottom: 40,
right: 32,
}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}
>
<FontAwesome5 name='sync-alt' size={32} color='#fff' />
</TouchableOpacity>
<TouchableOpacity
style={{
// flex: 0.1,
alignSelf: 'flex-end',
height: 56,
width: 56,
backgroundColor: 'transparent',
marginLeft: 'auto',
marginRight: 'auto',
marginBottom: 24,
border: '1px solid red'
}}
onPress={handleTakePictureButton}
>
<View style={{position: 'relative'}}>
<CameraButton />
<CameraButtonRing />
</View>
</TouchableOpacity>
</View>
</Camera>
</View>
);
};
export default CameraView;
For anyone stumbling on this, I really don't know the reason behind, but what was crashing my app with the exact same error, was trying to log to Reactotron. It was the only thing in common with the code on the question, and after removing that, the application stopped crashing and worked just fine.
Now... if anyone discovers the reason, I would really like to know as well.

Header is not showing in react-navigation-drawer React-Native

I am implementing react-navigation-drawer from React Navigation Library. But facing problem related to header. The header bar is not showing in any of the screens.
This is my App.js
import React from "react";
import { StyleSheet, ScrollView, View } from "react-native";
//import DrawerNavigator from "./navigation/DrawerNavigator";
import { Platform, Dimensions } from "react-native";
import { createAppContainer } from "react-navigation";
import { createDrawerNavigator } from "react-navigation-drawer";
import Home from "./components/home";
import Contact from "./components/contact";
const WIDTH = Dimensions.get("window").width;
const RouteConfigs = {
Home: {
screen: Home
},
Contact: {
screen: Contact
}
};
const DrawerNavigatorConfig = {
drawerWidth: WIDTH * 0.75,
drawerType: "both",
initialRouteName: "Home"
};
const DrawerNavigator = createDrawerNavigator(
RouteConfigs,
DrawerNavigatorConfig
);
const MyApp = createAppContainer(DrawerNavigator);
export default class App extends React.Component {
render() {
return <MyApp />;
}
}
And this is my home screen
import React, { Component } from "react";
import { View, Image, Text, StyleSheet, ScrollView } from "react-native";
import { FontAwesomeIcon } from "#fortawesome/react-native-fontawesome";
import { faTruck, faHome } from "#fortawesome/free-solid-svg-icons";
class Home extends Component {
static navigationOptions = {
headerTitle: "Home",
drawerIcon: ({ tintColor }) => <FontAwesomeIcon size={25} icon={faHome} />
};
render() {
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Screen</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#F5F5F5",
flexDirection: "column"
},
icon: {
width: 24,
height: 24
}
});
export default Home;
Can anyone help me. Thanks in advance!!!
#hongdeveloper this is a simple example solution for react navigation 5:
function Root() {
return (
<Stack.Navigator>
<Stack.Screen options={{title: "Profile"}} name="Profile" component={Profile} />
<Stack.Screen options={{title: "Settings"}} name="Settings" component={Settings} />
</Stack.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="Root" component={Root} />
</Drawer.Navigator>
</NavigationContainer>
);
}
You can find about the navigation to a screen in a nested navigator in docs and you can try this example on Snack
The drawer navigator does not contain headers. Stack navigators must be configured to display headers.
const DrawerNavigator = createDrawerNavigator(
RouteConfigs,
DrawerNavigatorConfig
);
const Root = createStackNavigator({
Main: { screen : DrawerNavigator}
},
{
defaultNavigationOptions : ({ navigation }) => ({
title: "Screen"
})
})
const Stacks = createAppContainer(Root)
export default Stacks;
Since December 2020 you can now use the headerShown: true setting in screenOptions of your Drawer.Navigator to show the header in React Navigation 5.
See more about this issue here: https://github.com/react-navigation/react-navigation/issues/1632
See the commit and comments about the new feature in React Navigation 5 here
https://github.com/react-navigation/react-navigation/commit/dbe961ba5bb243e8da4d889c3c7dd6ed1de287c4
Late reply, But I did it with the below code.
I created separate stack navigators for each screen and after that added all the stack navigators in the drawer navigator.
The good thing is it is fully customized.
Please see my code below.
const WIDTH = Dimensions.get('window').width;
const HomeNavigator = createStackNavigator(
{
Home: Home
},
{
defaultNavigationOptions: ({ navigation }) => {
return {
headerStyle: {
backgroundColor: '#1e89f4'
},
headerTitle: 'Knowledge Woledge',
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
textAlign: 'center',
flex: 1
},
headerLeft: (
<View style={{ paddingLeft: 13 }}>
<FontAwesomeIcon
size={25}
color='#fff'
icon={faBars}
onPress={() => navigation.openDrawer()}
/>
</View>
),
headerRight: <View />
};
}
}
);
const DetailNavigator = createStackNavigator(
{
PostDetail: PostDetail
},
{
defaultNavigationOptions: ({ navigation }) => {
return {
headerStyle: {
backgroundColor: '#1e89f4'
},
headerTitle: () => {
return (
<Text
style={{
color: '#fff',
fontWeight: 'bold',
textAlign: 'center',
flex: 1,
fontSize: 20
}}
>
{navigation.getParam('headerTitle')}
</Text>
);
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
textAlign: 'center',
flex: 1
},
headerLeft: (
<View style={{ paddingLeft: 13 }}>
<FontAwesomeIcon
size={25}
color='#fff'
icon={faArrowLeft}
onPress={() => navigation.goBack(null)}
/>
</View>
),
headerRight: <View />
};
}
}
);
Assigned this in a const
const RouteConfigs = {
Home: {
screen: HomeNavigator,
navigationOptions: {
drawerLabel: 'Home',
drawerIcon: ({ tintColor }) => (
<FontAwesomeIcon size={20} color={tintColor} icon={faHome} />
)
}
},
Detail: {
screen: DetailNavigator,
navigationOptions: {
drawerLabel: () => {
return null;
}
}
}
};
And finally, create a drawer navigator with this.
const DrawerNavigatorConfig = {
drawerWidth: WIDTH * 0.75,
drawerType: 'both',
initialRouteName: 'Home'
};
const DrawerNavigator = createDrawerNavigator(
RouteConfigs,
DrawerNavigatorConfig
);
const Stacks = createAppContainer(DrawerNavigator);
export default Stacks;

React native drawer navigation with stack navigator

I'm trying to develop an app to understand the react native basics. I'm usin react navigation and I would like to see menu in every page of my app. I've developed someting like;
-StackNavigtor
-Login Screen
-DrawerNagivation
-Screen1
-Screen2
However, inner drawer's components can not benefit from the stacking feature. What's the best way of obtaining drawer navigation with stack navigator in order to obtain menu in every page of my app.
Thanks.
Yes you can follow the following step.
App.js
import React, {Component} from 'react';'
import {Platform, StyleSheet, Text, View} from 'react-native';
import { createStackNavigator } from 'react-navigation';
import Login from './src/authScreen/login/Login';
import DrawerNavigator from './src/navigation/drawerNavigation/DrawerNavigator';
export default class App extends Component{
render() {
return (
<AppStackNavigator />
);
}
}
const AppStackNavigator = createStackNavigator({
Login:{
screen:Login
},
DrewerNav:{
screen:DrawerNavigator
}
},
navigationOptions={
headerMode:'none'
})
then create src folder and create DrawerNavigator.js . and Enter the following code.
import React from 'react' import { StyleSheet, Text, View, SafeAreaView, ScrollView, Dimensions, Image} from 'react-native';
import { createDrawerNavigator, DrawerItems } from 'react-navigation';
import Icon from 'react-native-vector-icons/FontAwesome5';import DrawerScreen1
from '../../screens/drawerScreen/DrawerScreen1' import DrawerScreen2
from '../../screens/drawerScreen/DrawerScreen2' import DrawerScreen3
from '../../screens/drawerScreen/DrawerScreen3' // import { Right }
from 'native-base';
const CustomDrawerComponent = (props)=>( <SafeAreaView>
<View style={{height:150, backgroundColor:'white', alignItems:'center', justifyContent:'center'}}>
<Image source={require('../../Images/user.jpg')} style={{height:120, width:120, borderRadius:60}} />
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView> </SafeAreaView> )
export default createDrawerNavigator(>
DrawerScreen1: {
screen: DrawerScreen1,
navigationOptions: {
drawerLabel: 'DrawerScreen1',
drawerIcon: ({ tintColor }) => <Icon name="user-circle" size={17} />,
} },
DrawerScreen2: {
screen: DrawerScreen2,
navigationOptions: {
drawerLabel: 'DrawerScreen2',
drawerIcon: ({ tintColor }) => <Icon name="user-circle" size={17} />,
} },
DrawerScreen3: {
screen: DrawerScreen3,
navigationOptions: {
drawerLabel: 'DrawerScreen3',
drawerIcon: ({ tintColor }) => <Icon name="user-circle" size={17} />,
} }, }, { drawerPosition :"right", contentComponent:CustomDrawerComponent
});
Here CustomDrawerComponent add a Drawer Icon.
and add the login.js
import React, { Component } from 'react';
import {View,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import { Container, Header, Content, Button, Text } from 'native-base';
class Login extends Component{
constructor(props){
super(props);
}
loginHandler=()=>{
this.props.navigation.navigate('DrewerNav')
}
render(){
return(
<View style={styles.container}>
<Text> Login </Text>
<View style={{alignItems:'center'}}>
<Button onPress={this.loginHandler}>
<Text>Click Me!</Text>
</Button>
</View>
</View>
)
}
}
export default Login;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Further more: you can refer https://github.com/ChanakaUOMIT/React-Native-Root-boiler-plate/tree/master this project.. here also add Stack navigation, Tab Navigation and Drawer navigation in one project.
import 'react-native-gesture-handler';
import * as React from 'react';
import {View, TouchableOpacity, Image} from 'react-native';
import {NavigationContainer} from '#react-navigation/native';
import {createStackNavigator} from '#react-navigation/stack';
import {createDrawerNavigator} from '#react-navigation/drawer';
import LoginPage from './src/pages/LoginPage';
import SecondPage from './src/pages/SecondPage';
import ThirdPage from './src/pages/ThirdPage';
// Import Custom Sidebar
import CustomSidebarMenu from './src/pages/CustomSidebarMenu';
import SignUpPage from './src/pages/SignUp';
import Home from './src/pages/Home';
import VendingMachineList from './src/pages/VendingMachineList';
import ProductList from './src/pages/ProductList';
import ProductDetails from './src/pages/ProductDetails';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const NavigationDrawerStructure = (props) => {
//Structure for the navigatin Drawer
const toggleDrawer = () => {
//Props to open/close the drawer
props.navigationProps.toggleDrawer();
};
return (
<View style={{flexDirection: 'row'}}>
<TouchableOpacity onPress={toggleDrawer}>
<Image
source={require('./src/assets/image/Vector.png')}
style={{width: 30, height: 20, marginLeft: 5}}
/>
</TouchableOpacity>
<TouchableOpacity onPress={toggleDrawer}>
<Image
source={require('./src/assets/image/track-fresh.png')}
style={{width: 30, height: 20, marginLeft: 5}}
/>
</TouchableOpacity>
</View>
);
};
function firstScreenStack({navigation}) {
return (
<Stack.Navigator initialRouteName="LoginPage">
<Stack.Screen
name="LoginPage"
component={LoginPage}
options={{
title: 'First Page', //Set Header Title
headerLeft: () => (
<NavigationDrawerStructure
navigationProps={navigation}
/>
),
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerShown:false,
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
<Stack.Screen
name="SignUpPage"
component={SignUpPage}
options={{
title: 'First Page', //Set Header Title
headerLeft: () => (
<NavigationDrawerStructure
navigationProps={navigation}
/>
),
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerShown:false,
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
</Stack.Navigator>
);
}
function HomeStack({navigation}) {
return (
<Stack.Navigator
initialRouteName="VendingMachineList"
screenOptions={{
headerLeft: () => (
<NavigationDrawerStructure navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#fff', //Set Header color
},
headerTintColor: '#000', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="HomePage"
component={Home}
options={{
title: '', headerShown:false, //Set Header Title
}}
/>
<Stack.Screen
name="ProductList"
component={ProductList}
options={{
title: '', headerShown:false, //Set Header Title
}}
/>
<Stack.Screen
name="ProductDetails"
component={ProductDetails}
options={{
title: '', headerShown:false, //Set Header Title
}}
/>
<Stack.Screen
name="VendingMachineList"
component={VendingMachineList}
options={{
title: '', headerShown:false, //Set Header Title
}}
/>
<Stack.Screen
name="ThirdPage"
component={ThirdPage}
options={{
title: 'Third Page', //Set Header Title
}}
/>
</Stack.Navigator>
);
}
function secondScreenStack({navigation}) {
return (
<Stack.Navigator
initialRouteName="SecondPage"
screenOptions={{
headerLeft: () => (
<NavigationDrawerStructure navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="SecondPage"
component={SecondPage}
options={{
title: 'Second Page', //Set Header Title
}}
/>
<Stack.Screen
name="ThirdPage"
component={ThirdPage}
options={{
title: 'Third Page', //Set Header Title
}}
/>
</Stack.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: {marginVertical: 5},
}}
drawerContent={(props) => <CustomSidebarMenu {...props} />}>
<Drawer.Screen
name="LoginPage"
options={{drawerLabel: 'First page Option',swipeEnabled:false}}
component={firstScreenStack}
/>
<Drawer.Screen
name="Home"
options={{drawerLabel: 'Second page Option'}}
component={HomeStack}
/>
<Drawer.Screen
name="SecondPage"
options={{drawerLabel: 'Second page Option'}}
component={secondScreenStack}
/>
</Drawer.Navigator>
</NavigationContainer>
);
}
export default App;