-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabBar.js
62 lines (54 loc) · 1.77 KB
/
TabBar.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
import React from 'react-native';
const { TabBarIOS, AsyncStorage } = React;
import Challenges from './Challenges';
import Friends from './Friends';
import Welcome from './Welcome';
import { STATUS_LOGGEDIN_KEY } from './constants/storage.js';
import challengeIco from './img/challenge2.png';
import friendsIco from './img/friends2.png';
export default class TabBar extends React.Component {
static propTypes = {
style: React.PropTypes.number,
};
state = {
selectedTab: 'welcomeTab',
};
componentDidMount() {
this._loadState().done();
}
async _loadState() {
try {
const status = await AsyncStorage.getItem(STATUS_LOGGEDIN_KEY);
if (status !== null && status === 'yes') {
this.setState({ isLoggedIn: status, selectedTab: 'challengesTab' });
}
} catch (error) {
alert(`AsyncStorage error: ${error.message}`);
}
}
/* eslint react/jsx-no-bind: 0 */
render() {
return (
<TabBarIOS tintColor="black" style={this.props.style}>
<TabBarIOS.Item icon={challengeIco} title="Challenges"
selected={this.state.selectedTab === 'challengesTab'}
onPress={() => { this.setState({ selectedTab: 'challengesTab' }); }}
>
<Challenges/>
</TabBarIOS.Item>
<TabBarIOS.Item icon={friendsIco} title="Friends"
selected={this.state.selectedTab === 'friendsTab'}
onPress={() => { this.setState({ selectedTab: 'friendsTab' }); }}
>
<Friends/>
</TabBarIOS.Item>
<TabBarIOS.Item icon={friendsIco} title="Welcome"
selected={this.state.selectedTab === 'welcomeTab'}
onPress={() => { this.setState({ selectedTab: 'welcomeTab' }); }}
>
<Welcome/>
</TabBarIOS.Item>
</TabBarIOS>
);
}
}