1234

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 (

     

        Welcome to React Native!

       

       

          title="登录"

          onPress={async () => {

            await AsyncStorage.setItem("username", this.state.name);

            this.props.navigation.navigate("Zhu");

          }}

        />

     

    );

  }

}

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 (

     

        Welcome to React Native!

        {this.state.name}

       

          title="注销"

          onPress={async () => {

            await AsyncStorage.clear();

            this.props.navigation.navigate("Login");

          }}

        />

     

    );

  }

}

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 (

     

        Welcome to React Native!

     

    );

  }

}

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

  }

});

你可能感兴趣的:(1234)