22 * Created by wangdi on 7/12/16.
33 */
44import React , { Component , PropTypes } from 'react' ;
5- import { StyleSheet , View , Text , Image , ListView , Platform , ActivityIndicator , TouchableNativeFeedback , TouchableHighlight , ToastAndroid } from 'react-native' ;
5+ import { StyleSheet , View , Text , Image , ListView , Platform , ActivityIndicator , TouchableOpacity , Modal } from 'react-native' ;
66import { connect } from 'react-redux' ;
7+ import Icon from 'react-native-vector-icons/Ionicons' ;
78import theme from '../constants/theme' ;
89import px2dp from '../utils/px2dp' ;
910import Footer from './ListViewFooter' ;
@@ -12,6 +13,13 @@ class ListViewForGirls extends Component{
1213 constructor ( props ) {
1314 super ( props ) ;
1415 this . ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } ) ;
16+ this . state = {
17+ modalVisible : false ,
18+ imageWidth : 0 ,
19+ imageHeight : 0 ,
20+ imageUrl : '' ,
21+ loadedHD : false
22+ } ;
1523 }
1624
1725 static propTypes = {
@@ -23,16 +31,40 @@ class ListViewForGirls extends Component{
2331
2432 render ( ) {
2533 return (
26- < ListView
27- dataSource = { this . ds . cloneWithRows ( this . props . dataSource ) }
28- renderRow = { this . _renderRow . bind ( this ) }
29- renderFooter = { this . _renderFooter . bind ( this ) }
30- renderSeparator = { this . _renderSeparator . bind ( this ) }
31- initialListSize = { 10 }
32- pageSize = { 10 }
33- onEndReached = { this . props . onEndReached }
34- onEndReachedThreshold = { 5 }
35- />
34+ < View >
35+ < ListView
36+ dataSource = { this . ds . cloneWithRows ( this . props . dataSource ) }
37+ renderRow = { this . _renderRow . bind ( this ) }
38+ renderFooter = { this . _renderFooter . bind ( this ) }
39+ renderSeparator = { this . _renderSeparator . bind ( this ) }
40+ initialListSize = { 10 }
41+ pageSize = { 10 }
42+ onEndReached = { this . props . onEndReached }
43+ onEndReachedThreshold = { 5 }
44+ />
45+ < Modal
46+ visible = { this . state . modalVisible }
47+ onRequestClose = { this . _triggerModal . bind ( this ) }
48+ transparent = { true } >
49+ < View style = { styles . modalBackground } >
50+ < View style = { styles . closeBtn } >
51+ < TouchableOpacity
52+ onPress = { this . _triggerModal . bind ( this ) }
53+ activeOpacity = { theme . touchableOpacityActiveOpacity } >
54+ < Icon name = "ios-close-circle-outline" color = "#fff" size = { px2dp ( 30 ) } />
55+ </ TouchableOpacity >
56+ </ View >
57+ { this . state . loadedHD ?
58+ < View >
59+ < Image style = { { width : this . state . imageWidth , height : this . state . imageHeight } }
60+ source = { { uri : this . state . imageUrl } } />
61+ </ View >
62+ :
63+ < ActivityIndicator size = "large" />
64+ }
65+ </ View >
66+ </ Modal >
67+ </ View >
3668 ) ;
3769 }
3870
@@ -51,32 +83,59 @@ class ListViewForGirls extends Component{
5183
5284 _renderRow ( rowData , sectionID , rowID , highlightRow ) {
5385 return (
54- < TouchableHighlight
86+ < View
87+ style = { styles . rowItem }
5588 overflow = "hidden"
56- key = { rowID }
57- onPress = { this . _itemOnPress . bind ( this , rowData ) }
58- underlayColor = { theme . touchableHighlightUnderlayColor } >
59- { this . _renderRowContent ( rowData ) }
60- </ TouchableHighlight >
89+ key = { rowID } >
90+ { this . _renderRowContent ( rowData , true ) }
91+ { this . _renderRowContent ( rowData , false ) }
92+ </ View >
6193 ) ;
6294 }
6395
64- _renderRowContent ( rowData ) {
96+ _renderRowContent ( rowData , isLeft ) {
97+ var url = '' ;
98+ if ( isLeft ) url = rowData . leftUrl ;
99+ else url = rowData . rightUrl ;
65100 return (
66- < View style = { styles . rowItem } >
67- < Image style = { { width : theme . screenWidth / 2 - px2dp ( 9 ) , height : theme . screenWidth / 2 , marginRight : 3 } }
68- source = { { uri : rowData . leftUrl } } / >
69- < Image style = { { width : theme . screenWidth / 2 - px2dp ( 9 ) , height : theme . screenWidth / 2 , marginLeft : 3 } }
70- source = { { uri : rowData . rightUrl } } />
71- </ View >
101+ < TouchableOpacity
102+ onPress = { this . _itemOnPress . bind ( this , rowData , isLeft ) }
103+ activeOpacity = { theme . touchableOpacityActiveOpacity } >
104+ < Image style = { { width : theme . screenWidth / 2 - px2dp ( 9 ) , height : theme . screenWidth / 2 , marginLeft : px2dp ( 3 ) , marginRight : px2dp ( 3 ) } }
105+ source = { { uri : url } } />
106+ </ TouchableOpacity >
72107 ) ;
73108 }
74109
75- _itemOnPress ( rowData ) {
76- // this.props.navigator.push({
77- // component: WebViewPage,
78- // args: {rowData: rowData}
79- // });
110+ _itemOnPress ( rowData , isLeft ) {
111+ this . _triggerModal ( ) ;
112+ this . setState ( {
113+ imageUrl : isLeft ? rowData . leftUrl : rowData . rightUrl
114+ } ) ;
115+ this . _fetchHDImage ( isLeft ? rowData . leftOriginalUrl : rowData . rightOriginalUrl ) ;
116+ }
117+
118+ _triggerModal ( ) {
119+ this . setState ( { modalVisible : ! this . state . modalVisible , loadedHD : false } ) ;
120+ }
121+
122+ _fetchHDImage ( url ) {
123+ var correctWidth = theme . screenWidth ;
124+ var correctHeight = theme . screenWidth ;
125+ Image . getSize ( url , ( width , height ) => {
126+ const ratioWidth = theme . screenWidth / width ;
127+ const ratioHeight = theme . screenHeight / height ;
128+ if ( ratioWidth > ratioHeight ) {
129+ correctWidth = ratioHeight * width ;
130+ correctHeight = theme . screenHeight ;
131+ } else {
132+ correctWidth = theme . screenWidth ;
133+ correctHeight = ratioWidth * height ;
134+ }
135+ this . setState ( { imageUrl : url , imageWidth : correctWidth , imageHeight : correctHeight , loadedHD : true } ) ;
136+ } , ( error ) => {
137+ this . setState ( { imageUrl : url , imageWidth : correctWidth , imageHeight : correctHeight , loadedHD : true } ) ;
138+ } )
80139 }
81140}
82141
@@ -85,15 +144,32 @@ const styles = StyleSheet.create({
85144 flexDirection : 'row' ,
86145 width : theme . screenWidth ,
87146 height : theme . screenWidth / 2 ,
88- paddingLeft : px2dp ( 6 ) ,
89- paddingRight : px2dp ( 6 )
147+ paddingLeft : px2dp ( 3 ) ,
148+ paddingRight : px2dp ( 3 )
90149 } ,
91150 footer : {
92151 flexDirection : 'row' ,
93152 width : theme . screenWidth ,
94153 height : px2dp ( 60 ) ,
95154 alignItems : 'center' ,
96155 justifyContent : 'center' ,
156+ } ,
157+ modalBackground : {
158+ width : theme . screenWidth ,
159+ height : theme . screenHeight ,
160+ backgroundColor : 'rgba(0,0,0,0.9)' ,
161+ justifyContent : 'center' ,
162+ alignItems : 'center'
163+ } ,
164+ closeBtn : {
165+ position : 'absolute' ,
166+ top : 0 ,
167+ width : theme . screenWidth ,
168+ height : px2dp ( 50 ) ,
169+ alignItems : 'flex-end' ,
170+ justifyContent : 'flex-start' ,
171+ paddingTop : px2dp ( 20 ) ,
172+ paddingRight : px2dp ( 20 )
97173 }
98174} ) ;
99175
0 commit comments