/
index.android.js
116 lines (110 loc) · 3.03 KB
/
index.android.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Navigator,
Text,
View,
ToolbarAndroid,
} from 'react-native';
import StoriesView from './views/StoriesView';
import CommentsView from './views/CommentsView';
import AboutView from './views/AboutView';
import StoryActions from './actions/StoryActions';
import colors from './colors';
const styles = StyleSheet.create({
container: {
flex: 1,
},
wrapper: {
backgroundColor: colors.viewBackgroundColor,
},
toolbar: {
backgroundColor: colors.toolbarBackgroundColor,
height: 56,
elevation: 4,
},
});
class HackerWeb extends Component {
_navigatorRenderScene(route, navigator){
switch (route.id){
case 'Stories':
return <View style={styles.container}>
<ToolbarAndroid
title="HackerWeb"
titleColor={colors.primaryTextColor}
style={styles.toolbar}
actions={[
{
title: 'Reload',
icon: require('./images/refresh-icon.png'),
show: 'always',
},
{ title: 'About' },
]}
onActionSelected={(position) => {
switch (position){
case 0:
StoryActions.fetchStories();
break;
case 1:
navigator.push({
id: 'About',
});
break;
}
}}
/>
<StoriesView navigator={navigator} />
</View>;
case 'Comments':
const { component, title, passProps, rightButtonIcon, onRightButtonPress } = route;
const TheComponent = component;
return <View style={[styles.container, styles.wrapper]}>
<ToolbarAndroid
title={title}
titleColor={colors.primaryTextColor}
style={styles.toolbar}
navIcon={require('./images/arrow-back.png')}
onIconClicked={navigator.pop}
actions={[{
title: 'Share',
icon: rightButtonIcon,
show: 'always'
}]}
onActionSelected={onRightButtonPress}
/>
<TheComponent navigator={navigator} {...passProps}/>
</View>;
case 'About':
return <View style={[styles.container, styles.wrapper]}>
<ToolbarAndroid
title="About"
titleColor={colors.primaryTextColor}
style={styles.toolbar}
/>
<AboutView />
</View>;
}
}
render(){
return (
<Navigator
initialRoute={{id: 'Stories'}}
renderScene={this._navigatorRenderScene}
configureScene={(route) => {
if (route.id == 'About'){
return Navigator.SceneConfigs.FloatFromBottom;
}
return Navigator.SceneConfigs.PushFromRight;
}}
/>
);
}
}
AppRegistry.registerComponent('HackerWeb', () => HackerWeb);