1
1
'use strict' ;
2
2
3
3
var React = require ( 'react-native' ) ;
4
- var superagent = require ( 'superagent' ) ;
5
- var RefreshableListView = require ( 'react-native-refreshable-listview' ) ;
6
- var apilist = require ( '../apilist' ) ;
4
+ var styles = require ( './a-TopicStyle' ) ;
7
5
8
6
var {
9
- StyleSheet,
10
7
Text,
11
8
View,
12
- ListView,
13
9
Image,
14
- ActivityIndicatorIOS,
15
10
TouchableOpacity
16
11
} = React ;
17
12
18
13
19
14
var TopicCard = React . createClass ( {
20
15
getInitialState ( ) {
21
16
return {
22
- dataSource : new ListView . DataSource ( {
23
- rowHasChanged : ( row1 , row2 ) => row1 !== row2
24
- } ) ,
25
- loaded : false ,
26
- currentOffset : 0
17
+ cardId : this . props . cardId ,
18
+ topicItem : this . props . topicItem
27
19
} ;
28
20
} ,
29
21
30
22
componentDidMount ( ) {
31
- this . fetchTopicsData ( ) ;
23
+
32
24
} ,
33
-
25
+
34
26
_avatarFilter ( topic ) {
35
27
let avatar = topic . user &&
36
28
topic . user . avatar_url &&
@@ -73,96 +65,34 @@ var TopicCard = React.createClass({
73
65
return num . toString ( ) ;
74
66
}
75
67
} ,
76
-
77
- _loadMore ( ) {
78
- this . fetchTopicsData (
79
- apilist . fetchResourceWithPage (
80
- apilist [ this . props . currentReqName ] ,
81
- this . state . currentOffset + 20
82
- ) ,
83
- 20
84
- ) ;
85
- } ,
86
-
87
- _reload ( ) {
88
- this . fetchTopicsData (
89
- apilist . fetchResourceWithPage (
90
- apilist [ this . props . currentReqName ]
91
- )
92
- ) ;
93
- } ,
94
68
95
69
_onPressTopicItem ( ) {
96
- // 详情页
97
- console . log ( this . refs . INDEX_NAV ) ;
98
- } ,
99
-
100
- fetchTopicsData ( api = this . props . resourceApi , more = 0 ) {
101
- superagent . get ( api )
102
- . set ( 'Accept' , 'application/json' )
103
- . end ( ( err , res ) => {
104
- this . setState ( {
105
- dataSource : this . state . dataSource . cloneWithRows ( res . body . topics ) ,
106
- loaded : true ,
107
- currentOffset : this . state . currentOffset + more
108
- } ) ;
109
- } ) ;
70
+ console . log ( this . state . cardId ) ;
110
71
} ,
111
72
112
73
render ( ) {
113
- return (
114
- ! this . state . loaded ?
115
- < View style = { styles . loading } >
116
- < ActivityIndicatorIOS
117
- size = "small"
118
- color = "#333333"
119
- />
120
- < Text style = { styles . loadingTip } > 加载中...</ Text >
121
- </ View > :
122
- < RefreshableListView
123
- initialListSize = { 20 }
124
- pageSize = { 20 }
125
- onEndReached = { this . _loadMore }
126
- dataSource = { this . state . dataSource }
127
- renderRow = { this . renderTopicItem }
128
- style = { styles . topicListView }
129
- removeClippedSubviews = { true }
130
- onEndReachedThreshold = { 0 }
131
- loadData = { this . _reload }
132
- refreshDescription = '正在刷新...'
133
- refreshingIndictatorComponent = {
134
- < RefreshableListView . RefreshingIndicator stylesheet = { indicatorStylesheet } />
135
- }
136
- minDisplayTime = { 500 }
137
- minPulldownDistance = { 80 }
138
- minBetweenTime = { 2000 }
139
- />
140
- ) ;
141
- } ,
142
-
143
- renderTopicItem ( topic ) {
144
74
return (
145
75
< TouchableOpacity onPress = { this . _onPressTopicItem } activeOpacity = { 0.8 } >
146
76
< View style = { styles . topicCard } >
147
77
< View style = { styles . avatar } >
148
78
< Image
149
79
style = { styles . avatarImg }
150
- source = { { uri :this . _avatarFilter ( topic ) } }
80
+ source = { { uri :this . _avatarFilter ( this . state . topicItem ) } }
151
81
resizeMode = 'cover'
152
82
/>
153
83
</ View >
154
84
155
85
< View style = { styles . titleMeta } >
156
- < Text style = { styles . topicTitle } > { topic . title } </ Text >
86
+ < Text style = { styles . topicTitle } > { this . state . topicItem . title } </ Text >
157
87
< View style = { styles . metaarea } >
158
- < Text style = { styles . metainfo } > { this . _checkUser ( topic ) } </ Text >
88
+ < Text style = { styles . metainfo } > { this . _checkUser ( this . state . topicItem ) } </ Text >
159
89
< Text style = { styles . metainfo } > 刚刚更新</ Text >
160
90
</ View >
161
91
162
92
< View style = { styles . metaareatag } >
163
- < Text style = { styles . nodename } > { topic . node_name } </ Text >
93
+ < Text style = { styles . nodename } > { this . state . topicItem . node_name } </ Text >
164
94
< View style = { styles . replieCountBg } >
165
- < Text style = { styles . replieCount } > { this . _countRate ( topic . replies_count ) } </ Text >
95
+ < Text style = { styles . replieCount } > { this . _countRate ( this . state . topicItem . replies_count ) } </ Text >
166
96
</ View >
167
97
</ View >
168
98
</ View >
@@ -172,110 +102,4 @@ var TopicCard = React.createClass({
172
102
}
173
103
} ) ;
174
104
175
- var indicatorStylesheet = StyleSheet . create ( {
176
- wrapper : {
177
- height : 80 ,
178
- marginTop : 10 ,
179
- marginBottom : 10
180
- } ,
181
- content : {
182
- marginTop : 10 ,
183
- marginBottom : 10 ,
184
- height : 60
185
- }
186
- } ) ;
187
-
188
- var styles = StyleSheet . create ( {
189
- loading : {
190
- flex : 1 ,
191
- backgroundColor : '#ffffff' ,
192
- alignItems : 'center' ,
193
- justifyContent : 'center'
194
- } ,
195
- loadingTip : {
196
- color : '#333333' ,
197
- fontSize : 14 ,
198
- fontWeight : 'bold' ,
199
- letterSpacing : 2 ,
200
- marginTop : 12
201
- } ,
202
- topicListView : {
203
- flex : 1 ,
204
- backgroundColor : '#f0f0f0' ,
205
- padding : 5 ,
206
- overflow : 'hidden'
207
- } ,
208
- topicCard : {
209
- flex : 1 ,
210
- flexDirection : 'row' ,
211
- padding : 10 ,
212
- backgroundColor : '#ffffff' ,
213
- marginBottom : 5 ,
214
- borderColor : '#f0f0f0' ,
215
- borderStyle : 'solid' ,
216
- borderWidth : 1 ,
217
- borderRadius : 0
218
- } ,
219
- avatarImg : {
220
- width : 48 ,
221
- height : 48 ,
222
- borderRadius : 24
223
- } ,
224
- metainfo : {
225
- color : '#999999' ,
226
- fontSize : 12 ,
227
- lineHeight : 16 ,
228
- letterSpacing : 1 ,
229
- marginRight : 5
230
- } ,
231
- avatar : {
232
- flex : 2
233
- } ,
234
- titleMeta : {
235
- flex : 7 ,
236
- justifyContent : 'center'
237
- } ,
238
- replieCount : {
239
- fontSize : 12 ,
240
- lineHeight : 12 ,
241
- color : '#ffffff' ,
242
- fontWeight : 'bold'
243
- } ,
244
- replieCountBg : {
245
- backgroundColor : '#e74c3c' ,
246
- position : 'absolute' ,
247
- bottom : 0 ,
248
- right : 0 ,
249
- paddingBottom : 5 ,
250
- paddingTop : 5 ,
251
- paddingLeft : 10 ,
252
- paddingRight : 10 ,
253
- borderRadius : 11
254
- } ,
255
- nodename : {
256
- color : '#999999' ,
257
- fontSize : 12 ,
258
- lineHeight : 16
259
- } ,
260
- metaarea : {
261
- flexDirection : 'row' ,
262
- marginTop : 10 ,
263
- justifyContent : 'flex-start' ,
264
- flexWrap : 'wrap'
265
- } ,
266
- metaareatag : {
267
- flexDirection : 'row' ,
268
- marginTop : 2 ,
269
- justifyContent : 'flex-start' ,
270
- flexWrap : 'wrap'
271
- } ,
272
- topicTitle : {
273
- fontSize : 16 ,
274
- lineHeight : 20 ,
275
- fontWeight : 'bold' ,
276
- letterSpacing : 1 ,
277
- color : '#333333'
278
- }
279
- } ) ;
280
-
281
- module . exports = TopicCard ;
105
+ module . exports = TopicCard ;
0 commit comments