import { createSwitchNavigator } from "react-navigation";
import Auth from "./Auth";
import Login from "./Login";
import Zhu from "./Zhu";
const Route5 = createSwitchNavigator({
? Login: {
? ? screen: Login
? },
? Auth: {
? ? screen: Auth
? },
? Zhu: {
? ? screen: Zhu
? }
});
export default Route5;
------------------------------------------22----------------------------------------------------------------
import React, { Component } from "react";
import {
? Platform,
? StyleSheet,
? Text,
? View,
? Button,
? AsyncStorage,
? TextInput
} from "react-native";
export default class Login extends Component {
? aa = text => {
? ? this.setState({
? ? ? name: text
? ? });
? };
? render() {
? ? return (
? ? ? <View style={styles.container}>
? ? ? ? <Text style={styles.welcome}>Welcome to React Native!</Text>
? ? ? ? <TextInput onChangeText={this.aa} />
? ? ? ? <Button
? ? ? ? ? title="登錄"
? ? ? ? ? onPress={async () => {
? ? ? ? ? ? await AsyncStorage.setItem("username", this.state.name);
? ? ? ? ? ? this.props.navigation.navigate("Zhu");
? ? ? ? ? }}
? ? ? ? />
? ? ? </View>
? ? );
? }
}
const styles = StyleSheet.create({
? container: {
? ? flex: 1,
? ? justifyContent: "center",
? ? alignItems: "center",
? ? backgroundColor: "#F5FCFF"
? },
? welcome: {
? ? fontSize: 20,
? ? textAlign: "center",
? ? margin: 10
? },
? instructions: {
? ? textAlign: "center",
? ? color: "#333333",
? ? marginBottom: 5
? }
});
--------------------------------------33----------------------------------------------
import React, { Component } from "react";
import {
? Platform,
? StyleSheet,
? Text,
? View,
? Button,
? AsyncStorage
} from "react-native";
export default class Zhu extends Component {
? constructor(props) {
? ? super(props);
? ? this.state = {
? ? ? name: ""
? ? };
? }
? componentDidMount() {
? ? this.bb();
? }
? bb = async () => {
? ? var cc = await AsyncStorage.getItem("username");
? ? this.setState({
? ? ? name: cc
? ? });
? };
? render() {
? ? return (
? ? ? <View style={styles.container}>
? ? ? ? <Text style={styles.welcome}>Welcome to React Native!</Text>
? ? ? ? <Text>{this.state.name}</Text>
? ? ? ? <Button
? ? ? ? ? title="注銷"
? ? ? ? ? onPress={async () => {
? ? ? ? ? ? await AsyncStorage.clear();
? ? ? ? ? ? this.props.navigation.navigate("Login");
? ? ? ? ? }}
? ? ? ? />
? ? ? </View>
? ? );
? }
}
const styles = StyleSheet.create({
? container: {
? ? flex: 1,
? ? justifyContent: "center",
? ? alignItems: "center",
? ? backgroundColor: "#F5FCFF"
? },
? welcome: {
? ? fontSize: 20,
? ? textAlign: "center",
? ? margin: 10
? },
? instructions: {
? ? textAlign: "center",
? ? color: "#333333",
? ? marginBottom: 5
? }
});
--------------------------44--------------------------------------------
import React, { Component } from "react";
import { Platform, StyleSheet, Text, View, AsyncStorage } from "react-native";
export default class Auth extends Component {
? constructor(props) {
? ? super(props);
? ? this.auth();
? }
? auth = async () => {
? ? const username = await AsyncStorage.getItem("username");
? ? this.props.navigation.navigate(username ? "Zhu" : "Login");
? };
? render() {
? ? return (
? ? ? <View style={styles.container}>
? ? ? ? <Text style={styles.welcome}>Welcome to React Native!</Text>
? ? ? </View>
? ? );
? }
}
const styles = StyleSheet.create({
? container: {
? ? flex: 1,
? ? justifyContent: "center",
? ? alignItems: "center",
? ? backgroundColor: "#F5FCFF"
? },
? welcome: {
? ? fontSize: 20,
? ? textAlign: "center",
? ? margin: 10
? },
? instructions: {
? ? textAlign: "center",
? ? color: "#333333",
? ? marginBottom: 5
? }
});