📜  在 react-native-router-flex 上设置初始状态 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:58.879000             🧑  作者: Mango

代码示例1
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
      }
    });
  }

// HELPER FUNCTION FOR AUTH
  authenticate = () => {
    this.state.isUserLogin ? true : false
  }

  render() {
    return {
       Actions.pop()}
        sceneStyle={styles.sceneStyle}
        >
          
            
            
            
            
          
      
    }
  }
}

export default Routes;