-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.android.js
149 lines (143 loc) · 3.77 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
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
142
143
144
145
146
147
148
149
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
import React, { Component } from 'react';
import {
AppRegistry,
Navigator,
BackAndroid,
Text,
StyleSheet,
TouchableHighlight,
Image,
View
} from 'react-native';
import TopStories from './app/components/TopStories'
import NewsItemWebView from './app/components/NewsItemWebView'
import SideMenu from './app/components/SideMenu'
class nytimes_topstories extends Component {
constructor(){
super()
this.state = {
section : 'home',
sectionName : 'Top Stories',
}
this._renderScene = this._renderScene.bind(this)
}
render() {
return (
<SideMenu ref="drawer" onItemClick={this.handleItemClick.bind(this)}>
<Navigator
ref = "navigator"
initialRoute={{id:"LandingPage",name: this.state.sectionName, passProps: {section:this.state.section, sectionName : this.state.sectionName}}}
renderScene={this._renderScene}
configureScene = {(route) => {return Navigator.SceneConfigs.FloatFromRight}}
navigationBar = {this._navigationBar()}
sceneStyle = {styles.navSceneStyle}
/>
</SideMenu>
)
}
handleItemClick(section,sectionName){
this.setState({
section : section,
sectionName : sectionName,
})
this.refs["navigator"].replace({id:"LandingPage",name: this.state.sectionName, passProps: {section:this.state.section,sectionName : this.state.sectionName}})
}
_navigationBar(){
return (
<Navigator.NavigationBar
routeMapper = {this._routeMapper}
style = {styles.navBarStyle}
/>
)
}
_routeMapper = {
Title : (route,navigator,index,state) => {
return (
<Text
style={[styles.navBarText,styles.navBarTitleText]}
numberOfLines={2}
>
{route.name}
</Text>
)
},
LeftButton : (route,navigator,index,state) => {
let imgsrc = require("./images/ic_arrow_back_black_24dp.png")
let onPress = () => {navigator.pop()}
if(index === 0){
imgsrc = require("./images/ic_menu_black_24dp.png")
onPress = () => {this.refs["drawer"].openDrawer()}
}
return (
<TouchableHighlight
onPress = {onPress}
>
<Image
source={imgsrc}
style={styles.navBarLeftItemStyle}
/>
</TouchableHighlight>
)
},
RightButton : (route,navigator,index,state) => {
return null
}
}
_renderScene(route,navigator){
const routeId = route.id
if(routeId === "LandingPage"){
return (
<TopStories
navigator = {navigator}
{... route.passProps}
/>
)
}
if(routeId === "NewsItemPage"){
return ( <NewsItemWebView
navigator={navigator}
{... route.passProps}
/>
)
}
}
componentDidMount(){
BackAndroid.addEventListener('hardwareBackPress', () => {
const navigator = this.refs["navigator"]
if(navigator && navigator.getCurrentRoutes().length > 1){
navigator.pop()
return true
}
return false
})
}
}
const styles = StyleSheet.create({
navBarText : {
fontSize : 16,
marginVertical : 9,
},
navBarTitleText : {
fontWeight : "500",
},
navBarLeftItemStyle : {
height : 25,
width : 25,
marginLeft : 10,
marginTop : 10,
},
navBarStyle :{
justifyContent : 'center',
alignItems : 'center',
backgroundColor : 'white',
},
navSceneStyle : {
paddingTop : 45,
marginBottom : 25,
}
})
AppRegistry.registerComponent('nytimes_topstories', () => nytimes_topstories);