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

Commit 2339f5b

Browse files
committed
random data
1 parent f0c1ec7 commit 2339f5b

File tree

5 files changed

+82
-79
lines changed

5 files changed

+82
-79
lines changed

js/actions/requestRandomData.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import fetchWithTimeout from '../utils/fetchWithTimeout';
1010
function fetchSuccess(json) {
1111
return {
1212
type: TYPES.FETCH_RANDOM_DATA_SUCCESS,
13-
dataSource: json.results
13+
dataSource: json
1414
};
1515
}
1616

@@ -29,7 +29,7 @@ function fetchRequest() {
2929
function fetchMoreDataSuccess(json) {
3030
return {
3131
type: TYPES.FETCH_RANDOM_MORE_DATA_SUCCESS,
32-
dataSource: json.results
32+
dataSource: json
3333
};
3434
}
3535

@@ -45,30 +45,39 @@ function fetchMoreDataFailure() {
4545
};
4646
}
4747

48-
export function fetchRandomData() {
49-
var url = fetchUrl.random + 'Android/10';
50-
return (dispatch) => {
51-
dispatch(fetchRequest());
52-
fetchWithTimeout(5000, fetch(url))
48+
export function fetchRandomData(isMoreData=false) {
49+
var results = [];
50+
const randomCategory = ['Android/1','iOS/1','前端/1','休息视频/1','拓展资源/1','App/1','瞎推荐/1'];
51+
var index = 0;
52+
53+
function fetchCategoryData(dispatch) {
54+
fetchWithTimeout(5000, fetch(fetchUrl.random + randomCategory[Math.floor(Math.random()*7)]))
5355
.then((response)=> response.json())
5456
.then((json) => {
55-
dispatch(fetchSuccess(json));
57+
index++;
58+
results = results.concat(json.results);
59+
60+
if(index >= 10) {
61+
if (isMoreData)
62+
dispatch(fetchMoreDataSuccess(results));
63+
else
64+
dispatch(fetchSuccess(results));
65+
}else
66+
fetchCategoryData(dispatch);
5667
}).catch((error) => {
68+
if(isMoreData)
69+
dispatch(fetchMoreDataFailure());
70+
else
5771
dispatch(fetchFailure());
58-
});
59-
};
60-
}
72+
});
73+
}
6174

62-
export function fetchMoreRandomData() {
63-
var url = fetchUrl.random + 'Android/10';
6475
return (dispatch) => {
65-
dispatch(fetchMoreDataRequest());
66-
fetchWithTimeout(5000, fetch(url))
67-
.then((response)=> response.json())
68-
.then((json) => {
69-
dispatch(fetchMoreDataSuccess(json));
70-
}).catch((error) => {
71-
dispatch(fetchMoreDataFailure());
72-
});
73-
};
76+
if(isMoreData)
77+
dispatch(fetchMoreDataRequest());
78+
else
79+
dispatch(fetchRequest());
80+
81+
fetchCategoryData(dispatch);
82+
}
7483
}

js/containers/DiscoveryTab/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import React, {Component} from 'react';
7-
import {StyleSheet, View, Text, ListView, Image, Platform, TouchableNativeFeedback, TouchableOpacity, RefreshControl, ActivityIndicator} from 'react-native';
7+
import {StyleSheet, View, Text, ListView, Image, Platform, TouchableNativeFeedback, TouchableHighlight, TouchableOpacity, RefreshControl, ActivityIndicator} from 'react-native';
88
import {connect} from 'react-redux';
99
import {bindActionCreators} from 'redux';
1010
import * as Actions from '../../actions/requestRandomData';
@@ -40,7 +40,7 @@ class DiscoveryFragment extends Component{
4040

4141
_onEndReached(){
4242
if(!this.props.isRenderFooter && !this.props.loading)
43-
this.props.actions.fetchMoreRandomData();
43+
this.props.actions.fetchRandomData(true);
4444
}
4545

4646
render(){

js/containers/MoreTab/GirlsPage.js

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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

js/containers/MoreTab/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MoreFragment extends Component{
6060
</View>
6161
<View style={[styles.block, {borderTopColor: segmentColor, borderBottomColor: segmentColor}]}>
6262
<RowItem title="首页内容展示顺序" icon="md-reorder" iconColor='lightskyblue' onPress={this._itemClickCallback.bind(this, 2)}/>
63-
<RowItem title="主题颜色" icon="md-brush" iconColor={colors.orange} onPress={this._itemClickCallback.bind(this, 3)}/>
63+
<RowItem title="主题颜色" icon="ios-color-palette" iconColor={colors.orange} onPress={this._itemClickCallback.bind(this, 3)}/>
6464
{/*<RowItem title="选择语言 / Language" icon="md-globe" iconColor={colors.purple} onPress={this._itemClickCallback.bind(this, 3)}/>*/}
6565
<RowItemWithSwitcher title="夜间模式" icon="md-moon" iconColor="#7b68ee" switcherValue={isOpenNightMode} onValueChange={(value) => actions.changeNightMode(value)}/>
6666
<RowItemWithSwitcher title="显示列表缩略图" icon="md-browsers" iconColor='plum' switcherValue={isOpenThumbnail} onValueChange={(value) => actions.changeShowThumbnail(value)} renderSegment={false}/>

js/containers/WebViewPage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class WebViewPage extends BackPageComponent{
5454
onRequestClose={this._btnOnPressCallback.bind(this, 9)}>
5555
<View style={[styles.moreContentContainerBackground, {backgroundColor: 'rgba(0,0,0,0.1)'}]}>
5656
<View style={[styles.moreContentContainer, {backgroundColor: this.props.rowItemBackgroundColor}]}>
57-
{this._renderModalItem(0, 'ios-bowtie-outline', '查看完整标题')}
58-
{this._renderModalItem(4, 'ios-copy-outline', '复制链接')}
59-
{this._renderModalItem(5, 'ios-browsers-outline', '在浏览器中打开')}
57+
{this._renderModalItem(0, 'ios-paper-outline', '查看完整标题')}
58+
{this._renderModalItem(4, 'ios-clipboard-outline', '复制链接')}
59+
{this._renderModalItem(5, 'ios-open-outline', '在浏览器中打开')}
6060
{this._renderModalItem(6, 'ios-share-outline', '分享此内容')}
6161
{this._renderModalItem(9, 'ios-close-circle-outline', '关闭')}
6262
</View>

0 commit comments

Comments
 (0)