Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import React, {
  2. Component
  3. } from 'react';
  4.  
  5. import {
  6. AppRegistry,
  7. AsyncStorage,
  8. } from 'react-native';
  9.  
  10. var SignIn = require('./signin');
  11. var Home = require('./home');
  12.  
  13. var STORAGE_KEY = "0";
  14.  
  15. module.exports = React.createClass({
  16. getInitialState(){
  17. return{
  18. logStatus: 0
  19. }
  20. },
  21.  
  22. componentDidMount(){
  23. this._loadInitialState().done();
  24. },
  25.  
  26. async _loadInitialState(){
  27. try{
  28. console.log('load initial state');
  29.  
  30. var value = await AsyncStorage.getItem(STORAGE_KEY);
  31. console.log('STORAGE_KEY value: ' + value);
  32.  
  33. if (value != null){
  34. this.setState({logStatus: value})
  35. } else {
  36. console.log('undefined error');
  37. }
  38. }catch(error){
  39. console.log('error:' + error.message);
  40. }
  41. },
  42.  
  43. render(){
  44. var value = this.state.logStatus;
  45. console.log(value);
  46. if(value == 0){
  47. return(
  48. <Home />
  49. );
  50. } else if(value == 1){
  51. return(
  52. <SignIn />
  53. )
  54. } else {
  55. console.log('logStatus null');
  56. }
  57. },
  58. });
  59.  
  60. var STORAGE_KEY = "0";
  61.  
  62. var SignIn = require('./../signin');
  63.  
  64. module.exports = React.createClass({
  65. getInitialState(){
  66. return{
  67. logStatus: 0
  68. }
  69. },
  70. render() {
  71. var value = this.state.logStatus;
  72. if (value == 0){
  73. return (
  74. <View style={styles.container}>
  75. <TouchableHighlight
  76. underlayColor="gray"
  77. onPress={this._onPressButton}
  78. style={styles.button}>
  79. <Text>Sign out</Text>
  80. </TouchableHighlight>
  81. </View>
  82. );
  83. } else if(value == 1){
  84. return(
  85. <SignIn />
  86. )
  87. }
  88.  
  89. },
  90. _onPressButton(){
  91. AsyncStorage.setItem(STORAGE_KEY, "1");
  92. this.setState({logStatus: 1});
  93. }
  94. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement