Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {
- Component
- } from 'react';
- import {
- AppRegistry,
- AsyncStorage,
- } from 'react-native';
- var SignIn = require('./signin');
- var Home = require('./home');
- var STORAGE_KEY = "0";
- module.exports = React.createClass({
- getInitialState(){
- return{
- logStatus: 0
- }
- },
- componentDidMount(){
- this._loadInitialState().done();
- },
- async _loadInitialState(){
- try{
- console.log('load initial state');
- var value = await AsyncStorage.getItem(STORAGE_KEY);
- console.log('STORAGE_KEY value: ' + value);
- if (value != null){
- this.setState({logStatus: value})
- } else {
- console.log('undefined error');
- }
- }catch(error){
- console.log('error:' + error.message);
- }
- },
- render(){
- var value = this.state.logStatus;
- console.log(value);
- if(value == 0){
- return(
- <Home />
- );
- } else if(value == 1){
- return(
- <SignIn />
- )
- } else {
- console.log('logStatus null');
- }
- },
- });
- var STORAGE_KEY = "0";
- var SignIn = require('./../signin');
- module.exports = React.createClass({
- getInitialState(){
- return{
- logStatus: 0
- }
- },
- render() {
- var value = this.state.logStatus;
- if (value == 0){
- return (
- <View style={styles.container}>
- <TouchableHighlight
- underlayColor="gray"
- onPress={this._onPressButton}
- style={styles.button}>
- <Text>Sign out</Text>
- </TouchableHighlight>
- </View>
- );
- } else if(value == 1){
- return(
- <SignIn />
- )
- }
- },
- _onPressButton(){
- AsyncStorage.setItem(STORAGE_KEY, "1");
- this.setState({logStatus: 1});
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement