I have problem with navigation in RN, so I thought you could help me. I can't find any way to navigate from my "settings" tab to my "SignedOut", this is my repo, code is not complicated, all you have to look is in "navigation" and "screens" folder. Thing is my "settings" file is in one file "MainTabNavigator" and SignedOut is in "RootNavigation", and when i try something like this:
this.props.navigation.navigate("SignedOut");
nothing happend, here is my function for this:
onSignOut()
.then(() => {
console.log('Logout!');
this.props.navigation.navigate("SignedOut");
})
.catch(e => {
console.log(e);
})
I do get this log printed out so it should call this navigation method successfully. Do you have any ideas why? I mean, I think that this is the reason maybe I am missing something here?
This is what my MainTabNavigator looks like:
import React from 'react';
import { Platform } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { TabNavigator, TabBarBottom, DrawerNavigator } from 'react-navigation';
import Colors from '../constants/Colors';
import HomeScreen from '../screens/HomeScreen';
import ListScreen from '../screens/ListScreen';
import SettingsScreen from '../screens/SettingsScreen';
import WordDetails from '../screens/WordDetails';
import DrawerMenu from './drawerDesign/Drawer';
export default DrawerNavigator(
{
Home: {
screen: HomeScreen,
},
List: {
screen: ListScreen,
},
Settings: {
screen: SettingsScreen,
},
WordDetails: {
screen: WordDetails,
},
}, {
contentComponent: DrawerMenu,
drawerWidth: 200,
drawerPosition: "right",
contentOptions: {
activeTintColor: '#e91e63',
itemsContainerStyle: {
marginVertical: 0,
opacity: 0.6
},
iconContainerStyle: {
opacity: 0.6
},
style: {
flex: 1,
paddingTop: 35,
},
}
}
);
SingedOutNavigator:
import React from 'react';
import { Platform, StatusBar, Easing, Animated } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { StackNavigator } from 'react-navigation';
import Colors from '../constants/Colors';
import SignIn from '../screens/SignInScreen';
import Register from '../screens/RegisterScreen';
const headerStyle = {
marginTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
backgroundColor: '#2b303b',
};
export default StackNavigator(
{
SignIn: {
screen: SignIn,
navigationOptions: {
title: "Prijavi se",
headerStyle,
headerTitleStyle: {
color: '#f5f5f5'
},
},
},
Register: {
screen: Register,
navigationOptions: {
title: "Prijavi se",
headerStyle,
headerTitleStyle: {
color: '#f5f5f5'
},
},
}
},
{
headerMode: "none",
transitionConfig: () => ({
transitionSpec: {
duration: 1000,
easing: Easing.step0,
timing: Animated.timing,
},
screenInterpolator: sceneProps => {
const { layout, position, scene } = sceneProps
const { index } = scene
const height = layout.initHeight
const translateY = position.interpolate({
inputRange: [index - 1, index, index + 1],
outputRange: [height, 0, 0],
})
const opacity = position.interpolate({
inputRange: [index - 1, index - 0.99, index],
outputRange: [0, 1, 1],
})
return { opacity, transform: [{ translateY }] }
},
}),
}
);
And from this "Settings" Screen i want to go on this "SignIn" from "SignedOutNavigator"..
From what I understand you are building an application that some of it's screens are only available when the user is singed in.
So when the user logout you should clear the history of the navigation, in order for the user to become unable to navigate back using the back hardware button.
You should do something like:
this.props.navigation.dispatch(NavigationActions.reset({
index: 0, key: null, actions: [ NavigationActions.navigate({ routeName: "SignedOut" }) ]
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With