import React, { Component } from "react";
import { View, Text, AsyncStorage, Button } from "react-native";
import { createSwitchNavigator } from "react-navigation";
import Demo3_1 from "./Demo3_1";
import Demo3_2 from "./Demo3_2";
class Demo extends Component {
constructor(props) {
super(props);
this.state = {};
this.show(); //自定义方法
}
show = async () => {
const shows = await AsyncStorage.getItem("name");
this.props.navigation.navigation(shows ? "Demo3_2" : ""); //判断是否为空,不为空跳转显示信息,为空不跳转
};
render() {
return (
<View style={{ flexDirection: "row", alignItems: "center" }}>
<View style={{ margin: 10, width: 80 }}>
<Button
title="未登录"
onPress={() => {
this.props.navigation.navigate("Demo3_1");
}}
/>
</View>
<Text> textInComponent </Text>
</View>
);
}
}
const Demo3 = createSwitchNavigator({
Demo: { screen: Demo },
Demo3_2: { screen: Demo3_2 },
Demo3_1: { screen: Demo3_1 }
});
export default Demo3;
网友评论