How to set initial scene in react-native-router-flux based upon the user logged in state. Here is my code that I want to achieve this functionality. I want scene 2 if user logged in and scene 1 if user not logged in.
I'm facing an issue with this code it always return a first screen rather than scene 2 I have the user logged in state.
import React, { Component } from 'react';
import { Router, Scene } from 'react-native-router-flux';
import Scene1 from '../Scene1';
import Scene2 from '../Scene2';
// localization strings
import strings from '../config/localization';
import styles from './Styles';
class Routes extends Component {
state = {
isUserLogin: false
}
async componentDidMount() {
await AsyncStorage.getItem('user', (err, result) => {
if (result != null) {
this.setState({ isUserLogin: JSON.parse(result).isUserLoggedIn });
}
if (__DEV__) {
console.log('routes', this.state); // return trur or false if user logged in or not
}
});
}
render() {
return {
<Router
backAndroidHandler={() => Actions.pop()}
sceneStyle={styles.sceneStyle}
>
<Scene key="root">
<Scene
key="merchants"
component={Scene1}
title={strings.selectBusiness}
navigationBarStyle={styles.navigationBarStyle}
navBarButtonColor={styles.navBarButtonColor}
titleStyle={styles.titleStyle}
initial={!this.state.isUserLogin}
/>
<Scene
key="initializeStore"
component={Scene2}
hideNavBar
initial={this.state.isUserLogin}
/>
<Scene
key="login"
component={Login}
navigationBarStyle={styles.navigationBarStyle}
navBarButtonColor={styles.navBarButtonColor}
titleStyle={styles.titleStyle}
back
renderBackButton={renderBackButton}
/>
</Scene>
</Router>
}
}
}
export default Routes;