-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathHomeScreen.js
149 lines (134 loc) · 3.27 KB
/
HomeScreen.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
'use strict';
var Api = require('../Api/RssFeedApi');
var AppActions = require('../Actions/AppActions');
var FeedStore = require('../Stores/FeedStore');
var FeedDetail = require('./FeedDetail');
var React = require('react-native');
var _ = require('lodash');
var {
ActivityIndicatorIOS,
ActionSheetIOS,
AsyncStorage,
ScrollView,
StyleSheet,
Text,
TouchableHighlight,
View,
} = React;
var ActionSheetIOS = require('ActionSheetIOS');
var BUTTONS = [
'Remove Feed',
'Back',
];
var DESTRUCTIVE_INDEX = 0;
var CANCEL_INDEX = 1;
class HomeScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
feeds: [],
loading: true,
}
}
componentWillMount() {
FeedStore.addChangeListener(this._updateFeedsFromStore.bind(this));
this._updateFeedsFromStore();
}
componentWillUnmount() {
FeedStore.removeChangeListener(this._updateFeedsFromStore.bind(this));
}
_updateFeedsFromStore() {
this.setState({feeds: FeedStore.getState()});
}
_showFeedActionSheet(feed) {
ActionSheetIOS.showActionSheetWithOptions({
options: BUTTONS,
cancelButtonIndex: CANCEL_INDEX,
destructiveButtonIndex: DESTRUCTIVE_INDEX
},
(buttonIndex) => {
switch(buttonIndex) {
case 0:
AppActions.removeFeed(feed);
this.props.navigator.pop();
break;
}
});
}
_showFeedDetails(feed:any) {
Api.fetchRss(feed.feedUrl)
.then((res) => {
if(res.responseStatus == 200) {
var entries = res.responseData.feed.entries;
this.props.navigator.push ({
component: FeedDetail,
title: feed.title,
rightButtonIcon: require('image!NavBarButtonSettings'),
onRightButtonPress: () => {this._showFeedActionSheet(feed)},
passProps: {
entries: entries
}
})
} else {
AlertIOS.alert(res.responseDetails);
}
});
}
_renderFeed(feed:any) {
return (
<TouchableHighlight
underlayColor="rgba(0,0,0,.1)"
onPress={() => { this._showFeedDetails(feed) }}
key={feed.length}>
<View style={styles.wrapper}>
<View style={styles.header}>
<Text style={styles.title}>{feed.title}</Text>
</View>
<View style={styles.footer}>
<Text style={styles.description}>{feed.description}</Text>
<Text style={styles.smallText}>{feed.feedUrl}</Text>
</View>
</View>
</TouchableHighlight>
);
}
render() {
return (
<ScrollView style={styles.scrollView}>
{this.state.feeds.map((feed) => { return this._renderFeed(feed) })}
</ScrollView>
);
}
};
var styles = StyleSheet.create({
scrollView: {
flex: 1,
backgroundColor: '#F5FCFF'
},
wrapper: {
paddingTop: 20,
paddingBottom: 15,
paddingLeft: 10,
paddingRight: 10,
borderBottomWidth: 1,
borderBottomColor: '#e9e9e9',
},
title: {
paddingTop: 2,
paddingBottom: 3,
paddingRight: 15,
fontWeight: 'bold',
fontSize: 16,
},
description: {
color: "#B4AEAE",
fontSize: 12,
marginBottom: 5,
},
smallText: {
fontSize: 11,
textAlign: 'right',
color: "#B4AEAE",
}
});
module.exports = HomeScreen;