aksonov / aksonov/react-native-router-flux

How to set initial scene while checking the state of the user is login or not?

未关闭
#3,419 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
8.9k
派生
2.1k
PR 合并指标
30 天内没有已合并 PR

描述

### Version
- react-native-router-flux : "^4.0.6"
- react: "16.6.3",
- react-native: "0.58.4",

### Expected behaviour
I am using this module it's working fine. I am storing a login value in **AsyncStorage**. I have 2 screens **Login** and **Home** after login i am checking value in initial screen and it returns home screen initially.

### Actual behaviour
I'm facing an issue with this code it always firstly returns login screen after it returns home screen.
The screen looks like glitches.

### Code
```
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
AsyncStorage,
ActivityIndicator
} from "react-native";
import { Scene, Router, Stack } from "react-native-router-flux";
import Login from "./Src/Initial.js";
import Home from "./Src/Home.js";

type Props = {};
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
initial: true,
homeRouting: false
};
}
async componentWillMount() {
await AsyncStorage.getItem("TokenDetails", (err, result) => {
if (result) {
this.setState({
initial: false,
homeRouting: true
});
} else {
this.setState({
initial: true,
homeRouting: false
});
}
});
}
render() {
return (



{this.state.homeRouting ? (

) : (

)}




);
}
}

```
Here is my screenshot:
![navigation](https://user-images.githubusercontent.com/31063894/52519599-87ab5000-2c83-11e9-9251-2e3db3498cd4.gif)

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。