2

I have been a lot of time searching and trying different stuff to disable going back once the "user" is logged in but it seams that NavigationActions does not work. This is the code:

import { NavigationActions } from 'react-navigation';

const actionToDispatch = NavigationActions.reset({
    index: 0,
    actions: [NavigationActions.navigate('DrawerNavigator')] // Array!
  })

export default class LoginScreen extends React.Component {
    constructor(props) {
        super(props);
      }


  render() {

    return (
        <RkAvoidKeyboard
        style={styles.screen}
        onStartShouldSetResponder={ (e) => true}
        onResponderRelease={ (e) => Keyboard.dismiss()}>
        <View style={styles.content}>
            <Button title="Complete Login" onPress={()=>this.props.navigation.dispatch(actionToDispatch)}/>
          </View>
      </RkAvoidKeyboard>
    );
  }
}

I shrinked a little bit the code. What happens is that the dispatch actions does not work. And also I get the error: undefined is not a function(evaluating '_reactNavigation.NavigationActions .......) so it does not even compile. I have the last version of React-navigation(2.12.0).

1 Answer 1

4

First of all, reset action is not inside NavigationActions, so you have to change your NavigationActions.reset to StackActions.reset (docs here).

What I do in that case is to StackActions.replace instead of NavigationActions.navigate. What replace do is like unmount current view and mount the given one, so when user wants to goBack() from first screen (logged in) it quits the app instead of navigating back to Login.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.