forked from bradoyler/newswatch-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopics.js
More file actions
98 lines (83 loc) · 2.18 KB
/
Topics.js
File metadata and controls
98 lines (83 loc) · 2.18 KB
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
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
ListView,
PixelRatio,
TouchableHighlight,
View
} = React;
var MainScreen = require('./MainScreen');
var TOPICS = [
{name:'Sports'},{name:'Entertainment'}, {name:'Music'},{name:'Science'},
{name:'Technology'}, {name:'Business'},{name:'World'},{name:'Politics'}];
var TopicsListView = React.createClass({
getInitialState: function() {
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
return {
dataSource: ds.cloneWithRows(TOPICS),
};
},
render: function () {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
/>
);
},
renderRow: function(topic: Object) {
return (
<NavButton
onPress={() => this.selectTopic(topic)}
text={topic.name}
/>
);
},
selectTopic: function(topic: Object) {
this.setState({filter:topic.name.toLowerCase()});
this.props.navigator.push({
title: topic.name,
component: MainScreen,
passProps: {
filter: topic.name.toLowerCase(),
}
});
},
});
var NavButton = React.createClass({
render: function() {
return (
<TouchableHighlight
style={styles.button}
activeOpacity={1}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
onPress={this.props.onPress}>
<Text style={styles.buttonText}>
{this.props.text}
</Text>
</TouchableHighlight>
)
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
},
button: {
backgroundColor: 'white',
padding: 9,
borderBottomWidth: 1 / PixelRatio.get(),
borderBottomColor: '#CDCDCD',
},
buttonText: {
fontSize: 17,
fontWeight: '500',
marginTop: 5,
padding: 7,
marginLeft: 55,
},
});
module.exports = TopicsListView;