React Native navigation v5 navigate to another screen from header - react-native

I am currently following a tutorial that has an older version of navigator. I have update the code to use v5. When moving to a screen the navigation function is available as in
const CreateScreen = ({ navigation }) => {
I am then able to set the navigation with
onPress={() => navigation.navigate("home")
Please can someone show me how to expose the navigation function within the createStackNavigator function
import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import IndexScreen from "./src/screens/IndexScreens"
import ShowScreen from "./src/screens/ShowScreen"
import CreateScreen from "./src/screens/CreateScreen"
import EditScreen from "./src/screens/EditScreen"
import { Provider} from "./src/context/BlogContext"
import { Feather } from '#expo/vector-icons';
import { EvilIcons } from '#expo/vector-icons';
const Stack = createStackNavigator();
const MyStack = () => (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={IndexScreen}
options={{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
}}
/>
<Stack.Screen
name="Show"
component={ShowScreen}
options={{
title: 'Blog Post Detail',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<EvilIcons name="pencil" size={35} />
</TouchableOpacity>
)
}}
/>
<Stack.Screen
name="Create"
component={CreateScreen}
options={{
title: 'Create A Blog Post',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center"
}}
/>
<Stack.Screen
name="Edit"
component={EditScreen}
options={{
title: 'Edit Blog Post',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center"
}}
/>
</Stack.Navigator>
);
const App = () => (
<NavigationContainer>
<MyStack />
</NavigationContainer>
);
export default () => {
return <Provider>
<App />
</Provider>
}

change your options
options={{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
}}
to
options={({ navigation }) => (
{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => navigation.navigate("Show")}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
})}
Do the same with the options in Show stack screen.
Hope this helps!

Replace navigation.navigate("Show") with navigation.navigate("Create")

Related

passing parameter in react native drawer

When user login in LoginScreen.js I can get username, password, token.
To implement logout in CustomSidebarMenu.js, I need to pass those parameters from LoginScreen.js to CustomSidebarMenu.js (LoginScreen.js -> DrawerNavigationRoutes.js -> CustomSidebarMenu.js)
I checked that I implemented from LoginScreen.js to DrawerNaviagtionRoutes.js by using
alert(props.route.params.token)
in DrawerNavigatorRoutes.js
but I have no idea to pass parameter in
drawerContent={props => <CustomSidebarMenu {...props} />}>
here's my code
LoginScreen.js
import React, {useState, createRef} from 'react';
import {
StyleSheet,
TextInput,
View,
Text,
ScrollView,
Image,
Keyboard,
TouchableOpacity,
KeyboardAvoidingView,
} from 'react-native';
import AsyncStorage from '#react-native-community/async-storage';
import Loader from './Components/Loader';
const LoginScreen = ({navigation}) => {
const [userName, setUserName] = useState('');
const [userPassword, setUserPassword] = useState('');
const [loading, setLoading] = useState(false);
const [errortext, setErrortext] = useState('');
const emailInputRef = createRef();
const passwordInputRef = createRef();
const handleSubmitPress = () => {
setErrortext('');
if (!userName) {
alert('Please fill Username');
return;
}
if (!userPassword) {
alert('Please fill Password');
return;
}
setLoading(true);
fetch('http://localhost:8000/user/login/', {
method: 'POST',
//body: formBody,
headers: {
//Header Defination
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: userName,
password: userPassword,
})
})
.then((response) => response.json())
.then((responseJson) => {
//Hide Loader
setLoading(false);
console.log(responseJson);
// If server response message same as Data Matched
if (responseJson.status === 'success') {
navigation.replace('DrawerNavigationRoutes', {username:userName, password:userPassword, token:responseJson.token});
} else {
setErrortext(responseJson.error);
}
})
.catch((error) => {
//Hide Loader
setLoading(false);
console.error(error);
});
};
return (
<View style={styles.mainBody}>
<Loader loading={loading} />
<ScrollView
keyboardShouldPersistTaps="handled"
contentContainerStyle={{
flex: 1,
justifyContent: 'center',
alignContent: 'center',
}}>
<View>
<KeyboardAvoidingView enabled>
<View style={{alignItems: 'center'}}>
<Image
source={require('../Image/techmate.png')}
style={{
width: '50%',
height: 100,
resizeMode: 'contain',
margin: 30,
}}
/>
</View>
<View style={styles.SectionStyle}>
<TextInput
style={styles.inputStyle}
onChangeText={(UserName) =>
setUserName(UserName)
}
placeholder="Enter Username"
placeholderTextColor="#8b9cb5"
autoCapitalize="none"
returnKeyType="next"
onSubmitEditing={() =>
emailInputRef.current && emailInputRef.current.focus()
}
underlineColorAndroid="#f000"
blurOnSubmit={false}
/>
</View>
<View style={styles.SectionStyle}>
<TextInput
style={styles.inputStyle}
onChangeText={(UserPassword) =>
setUserPassword(UserPassword)
}
placeholder="Enter Password" //12345
placeholderTextColor="#8b9cb5"
keyboardType="default"
ref={passwordInputRef}
onSubmitEditing={Keyboard.dismiss}
blurOnSubmit={false}
secureTextEntry={true}
underlineColorAndroid="#f000"
returnKeyType="next"
/>
</View>
{errortext != '' ? (
<Text style={styles.errorTextStyle}>
{errortext}
</Text>
) : null}
<TouchableOpacity
style={styles.buttonStyle}
activeOpacity={0.5}
onPress={handleSubmitPress}>
<Text style={styles.buttonTextStyle}>LOGIN</Text>
</TouchableOpacity>
<Text
style={styles.registerTextStyle}
onPress={() => navigation.navigate('RegisterScreen')}>
New Here ? Register
</Text>
</KeyboardAvoidingView>
</View>
</ScrollView>
</View>
);
};
export default LoginScreen;
DrawerNavigationRoutes.js
import React from 'react';
// Import Navigators from React Navigation
import {createStackNavigator} from '#react-navigation/stack';
import {createDrawerNavigator} from '#react-navigation/drawer';
// Import Screens
import HomeScreen from './DrawerScreens/HomeScreen';
import CameraScreen from './DrawerScreens/CameraScreen';
import LedgerScreen from './DrawerScreens/LedgerScreen';
import RecommendScreen from './DrawerScreens/RecommendScreen';
import SettingsScreen from './DrawerScreens/SettingScreen';
import CustomSidebarMenu from './Components/CustomSidebarMenu';
import NavigationDrawerHeader from './Components/NavigationDrawerHeader';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const HomeScreenStack = ({navigation}) => {
return (
<Stack.Navigator initialRouteName="HomeScreen">
<Stack.Screen
name="HomeScreen"
component={HomeScreen}
options={{
title: 'Home', //Set Header Title
headerLeft: () => (
<NavigationDrawerHeader navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#307ecc', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
</Stack.Navigator>
);
};
const CameraScreenStack = ({navigation}) => {
return (
<Stack.Navigator
initialRouteName="CameraScreen"
screenOptions={{
headerLeft: () => (
<NavigationDrawerHeader navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#307ecc', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="CameraScreen"
component={CameraScreen}
options={{
title: 'Camera', //Set Header Title
}}
/>
</Stack.Navigator>
);
};
const LedgerScreenStack = ({navigation}) => {
return (
<Stack.Navigator
initialRouteName="LedgerScreen"
screenOptions={{
headerLeft: () => (
<NavigationDrawerHeader navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#307ecc', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="LedgerScreen"
component={LedgerScreen}
options={{
title: 'Ledger', //Set Header Title
}}
/>
</Stack.Navigator>
);
};
const RecommendScreenStack = ({navigation}) => {
return (
<Stack.Navigator
initialRouteName="RecommendScreen"
screenOptions={{
headerLeft: () => (
<NavigationDrawerHeader navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#307ecc', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="RecommendScreen"
component={SettingsScreen}
options={{
title: 'Recommend', //Set Header Title
}}
/>
</Stack.Navigator>
);
};
const SettingScreenStack = ({navigation}) => {
return (
<Stack.Navigator
initialRouteName="SettingsScreen"
screenOptions={{
headerLeft: () => (
<NavigationDrawerHeader navigationProps={navigation} />
),
headerStyle: {
backgroundColor: '#307ecc', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}>
<Stack.Screen
name="SettingsScreen"
component={SettingsScreen}
options={{
title: 'Settings', //Set Header Title
}}
/>
</Stack.Navigator>
);
};
const DrawerNavigatorRoutes = (props) => {
return (
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#cee1f2',
color: '#cee1f2',
itemStyle: {marginVertical: 5, color: 'white'},
labelStyle: {
color: '#d8d8d8',
},
}}
screenOptions={{headerShown: false}}
drawerContent={props => <CustomSidebarMenu {...props} />}>
<Drawer.Screen
name="homeScreenStack"
options={{drawerLabel: 'Home Screen'}}
component={HomeScreenStack}
/>
<Drawer.Screen
name="cameraScreenStack"
options={{drawerLabel: 'Camera Screen'}}
component={CameraScreenStack}
/>
<Drawer.Screen
name="ledgerScreenStack"
options={{drawerLabel: 'Ledger Screen'}}
component={LedgerScreenStack}
/>
<Drawer.Screen
name="recommendScreenStack"
options={{drawerLabel: 'Recommend Screen'}}
component={RecommendScreenStack}
/>
<Drawer.Screen
name="settingScreenStack"
options={{drawerLabel: 'Setting Screen'}}
component={SettingScreenStack}
/>
</Drawer.Navigator>
);
};
export default DrawerNavigatorRoutes;
CustomSidebarMenu.js
import React from 'react';
import {View, Text, Alert, StyleSheet} from 'react-native';
import {
DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '#react-navigation/drawer';
const CustomSidebarMenu = (props) => {
const logout = () => {
fetch('http://localhost:8000/user/logout/', {
method: 'POST',
headers: {
//Header Defination
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: props.route.params.token,
},
body: JSON.stringify({
username: props.route.params.username,
password: props.route.params.password,
})
})
.then((response) => response.json())
.then((responseJson) => {
//Hide Loader
//setLoading(false);
console.log(responseJson);
// If server response message same as Data Matched
if (responseJson.status === 'success') {
props.navigation.replace('Auth');
} else {
setErrortext(responseJson.error);
}
})
.catch((error) => {
//Hide Loader
setLoading(false);
console.error(error);
});
}
return (
<View style={stylesSidebar.sideMenuContainer}>
<View style={stylesSidebar.profileHeader}>
<View style={stylesSidebar.profileHeaderPicCircle}>
<Text style={{fontSize: 25, color: '#307ecc'}}>
{'About React'.charAt(0)}
</Text>
</View>
<Text style={stylesSidebar.profileHeaderText}>AboutReact</Text>
</View>
<View style={stylesSidebar.profileHeaderLine} />
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
label={({color}) => <Text style={{color: '#d8d8d8'}}>Logout</Text>}
onPress={
//props.navigation.toggleDrawer();
logout
}
/>
</DrawerContentScrollView>
</View>
);
};
export default CustomSidebarMenu;

stacknavigator react native set title of top menu

i have a menu created like that :
import {createStackNavigator} from 'react-navigation';
const stackNav = createStackNavigator({
Main: {
screen: JourneeService,
navigationOptions: ({navigation}) => ({
headerTitle: <StackNavTitle title="Journée de Service " />,
headerStyle: {
backgroundColor: '#0088CE',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerLeft: (
<TouchableOpacity
onPress={() => navigation.openDrawer()}
style={{width: '150%'}}>
<Icon name="ios-menu" size={35} color="#fff" style={{padding: 10}} />
</TouchableOpacity>
),
}),
}
with StackNavTitle :
class StackNavTitle extends Component {
constructor(props){
super(props);
}
render() {
return <Text style={{fontWeight: 'bold', color:'#fff', fontSize:20}}>
{this.props.title}.
</Text>;
}
}
on code i retrieve a title by callback i want to set title dynamically how can i do that ?
thanks in advance for your responses
You can provide a function to the header which accepts three parameters as per the docs and one of them contains the dynamic title. Here is an example I took from the docs and update with your header component
import {createStackNavigator} from 'react-navigation';
const stackNav = createStackNavigator({
Main: {
screen: JourneeService,
navigationOptions: ({navigation}) => ({
headerTitle: ({allowFontScaling, style, children})=> <StackNavTitle title={children.title} />,
headerStyle: {
backgroundColor: '#0088CE',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerLeft: (
<TouchableOpacity
onPress={() => navigation.openDrawer()}
style={{width: '150%'}}>
<Icon name="ios-menu" size={35} color="#fff" style={{padding: 10}} />
</TouchableOpacity>
),
}),
}
You can find more info here https://reactnavigation.org/docs/4.x/stack-navigator#headertitle

React navigation v5, add a stack navigation to my application header

I'm using react navigation 5 to build my app navigation system.
I want to add a link to open Notifications scree:
I created a RenderHeaderRight component to override the right component of all my stacks
navigation :
const RenderHeaderRight = ({navigation}) => {
return (
<View style={{flexDirection: 'row-reverse'}}>
<TouchableHighlight
underlayColor={COLORS.DEFAULT}
style={styles.iConMenuContainer}
onPress={() => navigation.openDrawer()}>
<Image source={menu} style={styles.iConMenu} />
</TouchableHighlight>
<TouchableHighlight
underlayColor={COLORS.DEFAULT}
style={styles.notificationsIconContainer}
onPress={() => navigation.navigate('Notifications')}>
<>
<Image source={notifications} style={styles.notificationsIcon} />
<Image source={notifMark} style={styles.badge} />
</>
</TouchableHighlight>
</View>
);
};
In my HomeStackScreen i'm using the RenderHeaderRight :
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator
initialRouteName="Home"
headerMode="screen"
mode="modal"
screenOptions={{
headerStyle: {
backgroundColor: COLORS.WHITE,
elevation: 0, // remove shadow on Android
shadowOpacity: 0, // remove shadow on iOS
borderBottomWidth: 0,
},
headerTintColor: COLORS.GREY,
headerTitleStyle: {
fontFamily: 'Montserrat-SemiBold',
fontWeight: '600',
fontSize: 18,
},
}}>
<HomeStack.Screen
name="Home"
component={Home}
options={{
title: 'Expanded',
headerLeft: () => <RenderHeaderLeft />,
headerRight: () => <RenderHeaderRight navigation={navigation} />,
headerTitleAlign: 'left',
}}
/>
<HomeStack.Screen name="HomeDetails" component={HomeDetails} />
</HomeStack.Navigator>
);
When i click on the Header right button to open the Notifications screen i got an error :
The action 'NAVIGATE' with payload {"name":"Notifications"} was not handled by any navigator.
Where shoud i create the stack navigation of Notifications screen ?
I triend to add the notifications like this :
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator
initialRouteName="Home"
headerMode="screen"
mode="modal"
screenOptions={{
headerStyle: {
backgroundColor: COLORS.WHITE,
elevation: 0, // remove shadow on Android
shadowOpacity: 0, // remove shadow on iOS
borderBottomWidth: 0,
},
headerTintColor: COLORS.GREY,
headerTitleStyle: {
fontFamily: 'Montserrat-SemiBold',
fontWeight: '600',
fontSize: 18,
},
}}>
<HomeStack.Screen
name="Home"
component={Home}
options={{
title: 'Expanded',
headerLeft: () => <RenderHeaderLeft />,
headerRight: () => <RenderHeaderRight navigation={navigation} />,
headerTitleAlign: 'left',
}}
/>
<HomeStack.Screen name="HomeDetails" component={HomeDetails} />
<HomeStack.Screen
name="Notifications". // add the screen here
component={Notifications}
options={{headerShown: false}}
/>
</HomeStack.Navigator>
);
Removed the unnecessary styling / images
From my understanding you need to have a root Drawer.Navigator and from inside your Home screen, you need a Stack.Navigator there
This article explains the details of combining react-native-navigators
import React from "react"
import { TouchableHighlight, View, Text } from "react-native"
import { NavigationContainer } from "#react-navigation/native"
import { createDrawerNavigator } from "#react-navigation/drawer"
import { createStackNavigator } from "#react-navigation/stack"
const RenderHeaderRight = ({ navigation }) => {
return (
<View style={{ flexDirection: "row-reverse" }}>
<TouchableHighlight onPress={() => navigation.openDrawer()}>
<View>
<Text>Menu</Text>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={() => navigation.navigate("Notifications")}>
<>
<View>
<Text>Image 1</Text>
</View>
<View>
<Text>Image 2</Text>
</View>
</>
</TouchableHighlight>
</View>
)
}
const Stack = createStackNavigator()
const Drawer = createDrawerNavigator()
const Notifications = () => (
<View>
<Text>Notifications</Text>
</View>
)
const Home = () => (
<View>
<Text>Home</Text>
</View>
)
const NotificationsScreen = () => (
<View>
<Text>Notifications Screen</Text>
</View>
)
const HomeScreen = () => (
<View>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={({ navigation }) => ({
title: "Home",
headerRight: () => <RenderHeaderRight navigation={navigation} />,
})}
navigationOptions={({ navigation }) => ({
headerTitleAlign: "left",
})}
/>
<Stack.Screen name="Notifications" component={Notifications} />
</Stack.Navigator>
</View>
)
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
)
}

React Native drawer navigation screen header title and buttons

I am trying to add title and buttons to my home screen that is opened from drawer navigation. The following does not work(screen loads but no header) and i cant find documentation or sample on this that uses React Navigation v5. Did i miss something? This is the doc i am following.
<Drawer.Screen
name="Home"
component={HomeScreen}
title="Home Screen"
options={{
headerRight: () => (
<Button
onPress={() => alert("This is a button!")}
title="Info"
color="#fff"
/>
),
}}
/>
UPDATE: doing this on the screen didn't work as well.
const HomeScreen = (props) => {
return (
<Container>
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Screen2</Text>
</View>
</Container>
);
};
HomeScreen.navigationOptions = (props) => ({
title: "Home",
headerStyle: {
backgroundColor: "rgb(0, 145, 234)",
},
headerTintColor: "white",
headerTitleStyle: {
fontWeight: "bold",
color: "white",
},
});
export default HomeScreen;
From the option you put in, I guess you may want to add a Stack inside your Drawer navigation.
From the below example, when you go to the HomeStack, it will have a navigation bar and you can custom it using the option you put in.
(I also created a simple snack here: https://snack.expo.io/#gie3d/insane-ice-cream)
import React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer, DrawerActions } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import { createDrawerNavigator } from '#react-navigation/drawer';
import { Ionicons } from '#expo/vector-icons';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const HomeStack = () => (
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} options={({navigation}) => ({
title: "Home",
headerStyle: {
backgroundColor: "rgb(0, 145, 234)",
},
headerTintColor: "white",
headerTitleStyle: {
fontWeight: "bold",
color: "white",
},
headerLeft: () => (
<Ionicons
name={'md-menu'}
size={24}
style={{ marginLeft: 10 }}
onPress={() =>
navigation.dispatch(DrawerActions.toggleDrawer())
}
/>
),
})} />
</Stack.Navigator>
);
const Home = () => {
return (
<View>
<Text>This is Home</Text>
</View>
)}
export default () => {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="HomeStack">
<Drawer.Screen name="HomeStack" component={HomeStack} />
<Drawer.Screen name="HomeNoStack" component={Home} />
</Drawer.Navigator>
</NavigationContainer>
);
}
You need to create the button on your screen too, like this.
import React from "react";
import {Text, View} from 'react-native';
export default class News extends React.Component {
static navigationOptions = ({navigation}) => {
return {
//headerLeft: --- PUT HERE YOU CUSTOM BUTTON (Use navigation.goBack() in onPress)
headerLeft:(<HeaderBackButton size={20} onPress={()=>{navigation.navigate('Home')}} color="#fff" tintColor="#fff"/>),
headerStyle: {
backgroundColor: 'rgb(0, 145, 234)',
},
headerTintColor: 'white',
headerTitleStyle:
{
fontWeight: 'bold',
color:'white' ,
//paddingTop:"2%",
},
}
}
render() {
return (
<View>
<Text> Here Leave the News!! </Text>
</View>
);
}
}

React native navigation 5 stackNavigator not working on production

I'm using ReactNavigation for tab navigator and stackNavigator. It's working 100% on development, mode but the stacNavigator is not working on production builds. The app is not crashing, it just isn’t navigating through pages. But the tab navigator is working fine.
Anyone having this issue?
I have opened an issue.
App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import AdminHome from './AdminScr/AdminHome
import AdmLogin from './AdminScr/AdminLogin';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
function App() {
return (
<View style={styles.container} >
<Stack.Navigator style={{ backgroundColor: '#e91e63' }}>
<Stack.Screen name="AdmHome" component={AdminHome} options={{
title: 'Admin Home',
headerStyle: {
//backgroundColor: '#1e90ff',
backgroundColor: '#E66E2F'
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
/>
<Stack.Screen name="AdmLogin" component={AdmLogin} options={{
title: 'Admin Login',
headerStyle: {
backgroundColor: '#E66E2F',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
/>
</Stack.Navigator>
</View>
);
}
export default () => {
return (
<NavigationContainer>
<App />
</NavigationContainer>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#e91e63',
},
});
Calling in AdminLogin.js page.
//For Arrow Function
const AdmLogin=(props)=> { //Passing props in fat area like (props).
return (
<View>
<TouchableOpacity style={styles.signinbutton} onPress={() => props.navigation.navigate("AdmHome")} >
<Text style={styles.buttonText}> Sign In</Text>
</TouchableOpacity>
</View>
)}
//For Class Method
<TouchableOpacity style={styles.signinbutton} onPress={() => this.props.navigation.navigate("AdmHome")} >
<Text style={styles.buttonText}> Sign In</Text>
</TouchableOpacity>