3
votes

Using react-native-router-flux, after user was success login, I would like to disable the back button from going back to the login screen. But I can not seem to find a way of getting the current "Scene" or "Stack" and then make some login as:

backAndroidHandler={() => {
                        if (currentScene === afterLoginScreeen) {
                         return true;   
                        }
                    }}

Did any one manage to deal with this issue?

3

3 Answers

14
votes

As my experience on react-native-router-flux i had use

type={ActionConst.RESET} in Scene

<Scene duration={0} key="main" component={Main} title="Some Title" type={ActionConst.RESET} />

It should what you need to avoid back to Login Screen

ActionConst and Scene.type explaination

1
votes

use this

<Scene key="Screen1" type="replace" component={Screen1} /> 
1
votes

This is what worked for me

import {BackHandler} from 'react-native';

UNSAFE_componentWillMount() {
    BackHandler.addEventListener("hardwareBackPress", this.handleBackButton);        
  }

handleBackButton = () => {
             // Do nothing
             return true;
  };

Update: as componentWillMount has been deprecated useEffect hook should be used instead