-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.js
129 lines (116 loc) · 3.62 KB
/
main.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
/**
* This is the entry point for your experience that you will run on Exponent.
*
* Start by looking at the render() method of the component called
* FirstExperience. This is where the text and example components are.
*/
'use strict';
let React = require('react-native');
let {
AppRegistry,
BackAndroid,
Image,
Navigator,
ScrollView,
StatusBarIOS,
StyleSheet,
Text,
View,
} = React;
let TabNavigator = require('react-native-tab-navigator').default;
let NavBar = require('./components/NavBar');
let Screen = require('./components/Screen');
let Schedule = require('./components/Schedule');
let TalkDetails = require('./components/TalkDetails');
let Venue = require('./components/Venue');
let Tweets = require('./components/Tweets');
let globals = require('./globals');
let ICON_SIZE = 24;
let routes = {
list: { name: 'list', title: 'Schedule' },
details: { name: 'details', title: 'Talk Details' }
};
class App extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
selectedTab: 'schedule'
};
}
componentDidMount() {
if (StatusBarIOS) {
StatusBarIOS.setStyle('light-content', true);
StatusBarIOS.setHidden(false, 'fade');
}
if (BackAndroid) {
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress.bind(this));
}
}
render() {
return (
<View style={styles.container}>
<TabNavigator>
<TabNavigator.Item
title="Schedule"
renderIcon={() => <Image source={{uri: `${globals.serverUrl}/images/reactjs-conf/schedule-icon.png`}} style={styles.icon} />}
selected={this.state.selectedTab === 'schedule'}
onPress={() => { this.setState({selectedTab: 'schedule'}); }}>
<Navigator
style={[styles.container, styles.navigator]}
initialRoute={routes.list}
renderScene={this.renderScene.bind(this)}
navigationBar={NavBar}
ref={component => this._navigator = component} />
</TabNavigator.Item>
<TabNavigator.Item
title="Venue"
renderIcon={() => <Image source={{uri: `${globals.serverUrl}/images/reactjs-conf/venue-icon.png`}} style={styles.icon} />}
selected={this.state.selectedTab === 'venue'}
onPress={() => { this.setState({selectedTab: 'venue'}); }}>
<Screen title="Venue">
<Venue />
</Screen>
</TabNavigator.Item>
<TabNavigator.Item
title="Tweets"
renderIcon={() => <Image source={{uri: `${globals.serverUrl}/images/reactjs-conf/tweets-icon.png`}} style={styles.icon} />}
selected={this.state.selectedTab === 'tweets'}
onPress={() => { this.setState({selectedTab: 'tweets'}); }}>
<Screen title="Tweets">
<Tweets />
</Screen>
</TabNavigator.Item>
</TabNavigator>
</View>
);
}
renderScene(route, navigator) {
if(route.name === 'list') {
return <Schedule navigator={navigator} />
} else if(route.name === 'details') {
return <TalkDetails navigator={navigator} talk={route.talkInfo} />
}
}
_handleBackButtonPress() {
if (this._navigator.getCurrentRoutes().length > 1) {
this._navigator.pop();
return true;
}
return false;
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
navigator: {
paddingTop: 64
},
icon: {
width: ICON_SIZE,
height: ICON_SIZE,
resizeMode: 'contain'
}
});
AppRegistry.registerComponent('main', () => App);