44'use strict' ;
55
66import React , { Component } from 'react' ;
7- import { StyleSheet , View , Text , ListView , Image , Platform , TouchableNativeFeedback , TouchableOpacity , RefreshControl } from 'react-native' ;
7+ import { StyleSheet , View , Text , ListView , Image , Platform , TouchableNativeFeedback , TouchableOpacity , RefreshControl , ActivityIndicator } from 'react-native' ;
88import { connect } from 'react-redux' ;
99import { bindActionCreators } from 'redux' ;
1010import * as Actions from '../../actions/requestRandomData' ;
@@ -26,12 +26,21 @@ class DiscoveryFragment extends Component{
2626 this . ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } ) ;
2727 }
2828
29- componentDidMount ( ) {
29+ _fetchData ( ) {
3030 this . props . actions . fetchRandomData ( ) ;
3131 }
3232
33+ componentDidMount ( ) {
34+ this . _fetchData ( ) ;
35+ }
36+
3337 _onRefresh ( ) {
34- this . props . actions . fetchRandomData ( ) ;
38+ this . _fetchData ( ) ;
39+ }
40+
41+ _onEndReached ( ) {
42+ if ( ! this . props . isRenderFooter )
43+ this . props . actions . fetchMoreRandomData ( ) ;
3544 }
3645
3746 render ( ) {
@@ -47,8 +56,8 @@ class DiscoveryFragment extends Component{
4756 renderFooter = { this . _renderFooter . bind ( this ) }
4857 initialListSize = { 10 }
4958 pageSize = { 10 }
50- // onEndReached={this.props.onEndReached }
51- // onEndReachedThreshold={5}
59+ onEndReached = { this . _onEndReached . bind ( this ) }
60+ onEndReachedThreshold = { 5 }
5261 refreshControl = {
5362 < RefreshControl
5463 refreshing = { this . props . loading }
@@ -62,26 +71,26 @@ class DiscoveryFragment extends Component{
6271
6372 _renderHeader ( ) {
6473 return (
65- < View style = { styles . btnPanel } >
66- { this . tabNames . map ( ( item , i ) => {
67- return (
68- < View style = { styles . btnRow } key = { i } >
69- { this . tabNames [ i ] . map ( ( subItem , index ) => {
70- return (
71- < View style = { styles . btnCell } key = { subItem } >
72- < TouchableOpacity
73- onPress = { this . _itemPressCallback . bind ( this , subItem ) }
74- activeOpacity = { theme . touchableOpacityActiveOpacity } >
75- { this . _renderBtnContent ( i , index ) }
76- </ TouchableOpacity >
77- < Text style = { styles . btnCellLabel } > { subItem } </ Text >
78- </ View >
79- ) ;
80- } ) }
81- </ View >
82- ) ;
83- } ) }
84- </ View >
74+ < View style = { styles . btnPanel } >
75+ { this . tabNames . map ( ( item , i ) => {
76+ return (
77+ < View style = { styles . btnRow } key = { i } >
78+ { this . tabNames [ i ] . map ( ( subItem , index ) => {
79+ return (
80+ < View style = { styles . btnCell } key = { subItem } >
81+ < TouchableOpacity
82+ onPress = { this . _itemPressCallback . bind ( this , subItem ) }
83+ activeOpacity = { theme . touchableOpacityActiveOpacity } >
84+ { this . _renderBtnContent ( i , index ) }
85+ </ TouchableOpacity >
86+ < Text style = { styles . btnCellLabel } > { subItem } </ Text >
87+ </ View >
88+ ) ;
89+ } ) }
90+ </ View >
91+ ) ;
92+ } ) }
93+ </ View >
8594 )
8695 }
8796
@@ -124,13 +133,6 @@ class DiscoveryFragment extends Component{
124133 _renderRowContent ( rowData ) {
125134 return (
126135 < View style = { styles . itemContainer } >
127- < View style = { styles . imgPart } >
128- { rowData . images ?
129- < Image style = { styles . image } source = { { uri : getCorrectImageSizeUrl ( rowData . images [ 0 ] ) } } />
130- :
131- < Image style = { styles . image } source = { require ( '../../assets/user_article_no_data.png' ) } />
132- }
133- </ View >
134136 < View style = { styles . txtPart } >
135137 < View style = { styles . titlePart } >
136138 < Text style = { styles . title } numberOfLines = { 2 } > { rowData . desc } </ Text >
@@ -144,13 +146,23 @@ class DiscoveryFragment extends Component{
144146 < Text style = { styles . detailsTxt } > { this . _handleCreateTime ( rowData . publishedAt ) } </ Text >
145147 </ View >
146148 </ View >
149+ < View style = { styles . imgPart } >
150+ { rowData . images ?
151+ < Image style = { styles . image } source = { { uri : getCorrectImageSizeUrl ( rowData . images [ 0 ] ) } } />
152+ :
153+ < Image style = { styles . image } source = { require ( '../../assets/user_article_no_data.png' ) } />
154+ }
155+ </ View >
147156 </ View >
148157 ) ;
149158 }
150159
151160 _renderSeparator ( sectionID , rowID , adjacentRowHighlighted ) {
152161 return (
153- < View key = { rowID } style = { { height : theme . segment . width , backgroundColor : theme . segment . color } } />
162+ < View key = { rowID } style = { { height : theme . segment . width , width : theme . screenWidth , flexDirection : 'row' } } >
163+ < View style = { { flex : 77 , backgroundColor : theme . segment . color } } />
164+ < View style = { { flex : 23 , backgroundColor : '#fff' } } />
165+ </ View >
154166 ) ;
155167 }
156168
@@ -195,6 +207,7 @@ const styles = StyleSheet.create({
195207 height : px2dp ( 215 ) ,
196208 width : theme . screenWidth ,
197209 marginTop : px2dp ( 12 ) ,
210+ marginBottom : px2dp ( 15 ) ,
198211 borderBottomColor : theme . segment . color ,
199212 borderBottomWidth : theme . segment . width ,
200213 borderTopColor : theme . segment . color ,
@@ -219,23 +232,25 @@ const styles = StyleSheet.create({
219232 backgroundColor : '#fff' ,
220233 flexDirection : 'row' ,
221234 width : theme . screenWidth ,
222- height : px2dp ( 75 )
235+ height : px2dp ( 73 )
223236 } ,
224237 imgPart : {
225238 flex : 20 ,
226239 alignItems : 'center' ,
227- justifyContent : 'center'
240+ justifyContent : 'center' ,
241+ paddingRight : px2dp ( 5 )
228242 } ,
229243 image : {
230- width : px2dp ( 52 ) ,
231- height : px2dp ( 52 ) ,
244+ width : px2dp ( 60 ) ,
245+ height : px2dp ( 60 ) ,
232246 resizeMode : 'cover' ,
233247 backgroundColor : '#f1f1f1' ,
234248 } ,
235249 txtPart : {
236250 flex : 80 ,
237251 paddingTop : px2dp ( 10 ) ,
238- paddingRight : px2dp ( 10 ) ,
252+ paddingLeft : px2dp ( 12 ) ,
253+ paddingRight : px2dp ( 5 ) ,
239254 paddingBottom : px2dp ( 10 )
240255 } ,
241256 titlePart : {
0 commit comments