-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
141 lines (127 loc) · 3.3 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import Icon from 'react-native-vector-icons/Ionicons';
import List from './app/creation/index';
import Edit from './app/edit/index';
import Account from './app/account/index';
import Login from './app/account/login'
import {
AppRegistry,
StyleSheet,
Text,
View,
TabBarIOS,
Navigator,
AsyncStorage
} from 'react-native';
export default class imoocApp extends Component {
constructor(props){
super(props);
this.state = {
selectedTab: 'edit',
isLogin: false
}
this._asyncAppStatus = this._asyncAppStatus.bind(this);
this._afterLogin = this._afterLogin.bind(this);
this._logout = this._logout.bind(this);
}
_asyncAppStatus() {
var _this = this;
AsyncStorage.getItem('user')
.then((data) => {
var user = null;
var newState = {};
if(data) {
user = JSON.parse(data)
}
if(user && user.accessToken) {
newState.user = user;
newState.isLogin = true
}else {
newState.isLogin = false
}
_this.setState(newState)
})
}
componentDidMount() {
this._asyncAppStatus()
}
_afterLogin(user) {
var _this = this;
console.log(user);
AsyncStorage.setItem('user', JSON.stringify(user))
.then((data) => {
_this.setState({
user: user,
isLogin: true
})
})
}
_logout() {
AsyncStorage.removeItem('user');
this.setState({
isLogin: false,
user: null
})
}
render() {
if(!this.state.isLogin) {
return <Login afterLogin={this._afterLogin}/>
}
return (
<TabBarIOS tintColor="#ee735c">
<Icon.TabBarItem
iconName="ios-videocam-outline"
selectedIconName="ios-videocam"
selected={this.state.selectedTab === 'list'}
onPress={() => {
this.setState({
selectedTab: 'list',
});
}}>
<Navigator
logout={this._logout}
initialRoute={{
name: 'list',
component: List
}}
configureScene={(route) => {
return Navigator.SceneConfigs.FloatFromRight
}}
renderScene={(route, navigator) => {
var Component = route.component
return <Component {...route.params} navigator={navigator} />
}}
/>
</Icon.TabBarItem>
<Icon.TabBarItem
iconName="ios-recording-outline"
selectedIconName="ios-recording"
selected={this.state.selectedTab === 'edit'}
onPress={() => {
this.setState({
selectedTab: 'edit'
});
}}>
<Edit />
</Icon.TabBarItem>
<Icon.TabBarItem
iconName="ios-more-outline"
selectedIconName="ios-more"
selected={this.state.selectedTab === 'account'}
onPress={() => {
this.setState({
selectedTab: 'account'
});
}}>
<Account user={this.state.user} logout={this._logout}/>
</Icon.TabBarItem>
</TabBarIOS>
);
}
}
AppRegistry.registerComponent('imoocApp', () => imoocApp);