Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 92c9503

Browse files
committed
girls page finish
1 parent 6ebdfae commit 92c9503

File tree

2 files changed

+110
-39
lines changed

2 files changed

+110
-39
lines changed

js/components/ListViewForGirls.js

Lines changed: 107 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* Created by wangdi on 7/12/16.
33
*/
44
import 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';
66
import {connect} from 'react-redux';
7+
import Icon from 'react-native-vector-icons/Ionicons';
78
import theme from '../constants/theme';
89
import px2dp from '../utils/px2dp';
910
import 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

js/containers/DiscoveryTab/GirlsPage.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ class GirlsPage extends BackPageComponent{
7171
var dataBlob = [];
7272

7373
for(let i=0; i<dataSource.length; i=i+2) {
74-
const leftWidth = this._randomWidth();
7574
let rowData = {
75+
leftOriginalUrl: dataSource[i].url,
76+
rightOriginalUrl: dataSource[i+1].url,
7677
leftUrl: this._handleImageToSmallSize(dataSource[i].url),
77-
rightUrl: this._handleImageToSmallSize(dataSource[i+1].url),
78-
leftWidth: leftWidth-3-6,
79-
rightWidth: theme.screenWidth - leftWidth - 3 -6
78+
rightUrl: this._handleImageToSmallSize(dataSource[i+1].url)
8079
}
8180
dataBlob.push(rowData);
8281
}
@@ -94,10 +93,6 @@ class GirlsPage extends BackPageComponent{
9493
}
9594
}
9695

97-
_randomWidth(){
98-
return Math.floor((Math.random() * theme.screenWidth/5) + theme.screenWidth/5*2);
99-
}
100-
10196
_handleImageToSmallSize(url){
10297
return url.replace('large','small');
10398
}

0 commit comments

Comments
 (0)