@@ -17,11 +17,12 @@ class GirlsPage extends BackPageComponent{
1717 const ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } ) ;
1818 this . state = {
1919 dataSource : ds ,
20- dataBlob1 : [ ] ,
21- dataBlob2 : [ ] ,
22- imageHeight : 200 ,
20+ dataBlob : [ ] ,
21+ imageHeight : 20 ,
22+ imageWidth : 20 ,
23+ load : false
2324 } ;
24- this . flag = true ;
25+ this . url = 'http://ww4.sinaimg.cn/large/610dc034gw1fa0ppsw0a7j20u00u0thp.jpg' ;
2526 }
2627
2728 render ( ) {
@@ -36,66 +37,59 @@ class GirlsPage extends BackPageComponent{
3637 leftBtnPress = { this . _handleBack . bind ( this ) } />
3738 </ View >
3839
39- < View style = { { flexDirection : 'row' } } >
40+ { this . state . load ?
4041 < ListView
41- ref = { ( ref ) => this . listView1 = ref }
42- renderRow = { this . _renderRow . bind ( this ) }
4342 enableEmptySections = { true }
44- dataSource = { this . state . dataSource . cloneWithRows ( this . state . dataBlob1 ) }
45- onScroll = { this . _onScroll . bind ( this ) }
46- //scrollEventThrottle={200}
47- onScrollBeginDrag = { ( ) => this . flag = true }
48- showsVerticalScrollIndicator = { false }
49- onEndReached = { ( ) => ToastAndroid . show ( 'end' , ToastAndroid . SHORT ) }
50- onEndReachedThreshold = { 5 }
51- />
52- < ListView
53- ref = { ( ref ) => this . listView2 = ref }
43+ dataSource = { this . state . dataSource . cloneWithRows ( this . state . dataBlob ) }
5444 renderRow = { this . _renderRow . bind ( this ) }
55- enableEmptySections = { true }
56- dataSource = { this . state . dataSource . cloneWithRows ( this . state . dataBlob2 ) }
57- onScroll = { this . _onScroll . bind ( this ) }
58- scrollEventThrottle = { 200 }
59- onScrollBeginDrag = { ( ) => this . flag = false }
60- onEndReached = { ( ) => ToastAndroid . show ( 'end' , ToastAndroid . SHORT ) }
61- onEndReachedThreshold = { 5 }
6245 />
63- </ View >
46+ :
47+ null
48+ }
6449 </ View >
6550 ) ;
6651 }
6752
68- _onScroll ( event ) {
69- var offsetY = event . nativeEvent . contentOffset . y ;
70- if ( this . flag )
71- this . listView2 . scrollTo ( { y : offsetY , animated : false } ) ;
72- else
73- this . listView1 . scrollTo ( { y : offsetY , animated : false } ) ;
74- }
75-
7653 _renderRow ( rowData ) {
7754 return (
78- < View >
79- < Image style = { { width : theme . screenWidth / 2 , height : this . _randomHeight ( ) } }
80- source = { { uri : this . _handleImageToSmallSize ( rowData . url ) } } />
55+ < View style = { styles . rowItem } >
56+ < Image style = { { width : rowData . leftWidth , height : theme . screenWidth / 2 , marginRight : 3 } }
57+ source = { { uri : rowData . leftUrl } } />
58+ < Image style = { { width : rowData . rightWidth , height : theme . screenWidth / 2 , marginLeft : 3 } }
59+ source = { { uri : rowData . rightUrl } } />
8160 </ View >
8261 ) ;
8362 }
8463
8564 componentDidMount ( ) {
8665 InteractionManager . runAfterInteractions ( ( ) => {
87- fetch ( 'http://gank.io/api/data/%E7%A6%8F%E5%88%A9/20 /1' ) . then ( response => response . json ( ) )
66+ fetch ( 'http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10 /1' ) . then ( response => response . json ( ) )
8867 . then ( json => {
68+ var results = json . results ;
69+ var dataBlob = [ ] ;
70+
71+ for ( let i = 0 ; i < results . length ; i = i + 2 ) {
72+ const leftWidth = this . _randomWidth ( ) ;
73+ let rowData = {
74+ leftUrl : this . _handleImageToSmallSize ( results [ i ] . url ) ,
75+ rightUrl : this . _handleImageToSmallSize ( results [ i + 1 ] . url ) ,
76+ leftWidth : leftWidth - 3 - 6 ,
77+ rightWidth : theme . screenWidth - leftWidth - 3 - 6
78+ }
79+ dataBlob . push ( rowData ) ;
80+ }
81+
8982 this . setState ( {
90- dataBlob1 : json . results . slice ( 0 , 10 ) ,
91- dataBlob2 : json . results . slice ( 10 )
83+ dataBlob : dataBlob ,
84+ load : true
9285 } ) ;
9386 } ) ;
87+
9488 } ) ;
9589 }
9690
97- _randomHeight ( ) {
98- return Math . floor ( ( Math . random ( ) * 100 ) + 150 ) ;
91+ _randomWidth ( ) {
92+ return Math . floor ( ( Math . random ( ) * theme . screenWidth / 5 ) + theme . screenWidth / 5 * 2 ) ;
9993 }
10094
10195 _handleImageToSmallSize ( url ) {
@@ -109,17 +103,17 @@ const styles = StyleSheet.create({
109103 paddingTop : theme . toolbar . paddingTop
110104 } ,
111105 toolbar : {
112- position : 'absolute' ,
113- width : theme . screenWidth ,
114- zIndex : 1
115- } ,
116- img1 : {
117- width : theme . screenWidth / 2 ,
118- height : 200
106+ // position: 'absolute',
107+ // width: theme.screenWidth,
108+ // zIndex: 1
119109 } ,
120- img2 : {
121- width : theme . screenWidth / 2 ,
122- height : 170
110+ rowItem : {
111+ flexDirection : 'row' ,
112+ width : theme . screenWidth ,
113+ height : theme . screenWidth / 2 + 6 ,
114+ paddingLeft : 6 ,
115+ paddingRight : 6 ,
116+ paddingBottom : 6
123117 }
124118} ) ;
125119
0 commit comments