mirror of
https://github.com/wu736139669/RN_AWord.git
synced 2026-08-05 06:24:39 +00:00
首页优化
This commit is contained in:
@@ -68,7 +68,6 @@ export default class CollectListView extends Component{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return (
|
return (
|
||||||
<MyListView
|
<MyListView
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import React, {
|
|||||||
import MyListView from './MyListView'
|
import MyListView from './MyListView'
|
||||||
var isPromise = require('is-promise')
|
var isPromise = require('is-promise')
|
||||||
var REQUEST_URL = 'http://127.0.0.1:3000/users/list';
|
var REQUEST_URL = 'http://127.0.0.1:3000/users/list';
|
||||||
|
var page = 1;
|
||||||
|
var dataSource = [];
|
||||||
export default class RandListView extends Component{
|
export default class RandListView extends Component{
|
||||||
|
|
||||||
//初始化。
|
//初始化。
|
||||||
@@ -36,7 +37,7 @@ export default class RandListView extends Component{
|
|||||||
title: {
|
title: {
|
||||||
component: (
|
component: (
|
||||||
<Text style={styles.title}>
|
<Text style={styles.title}>
|
||||||
随机
|
首页
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -48,8 +49,7 @@ export default class RandListView extends Component{
|
|||||||
}
|
}
|
||||||
//数据查询.
|
//数据查询.
|
||||||
fetchData(){
|
fetchData(){
|
||||||
var page = Math.random() * 1000;
|
|
||||||
page = Math.floor(page);
|
|
||||||
var url = REQUEST_URL + '?page=' + page;
|
var url = REQUEST_URL + '?page=' + page;
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
fetch(url)
|
fetch(url)
|
||||||
@@ -58,11 +58,19 @@ export default class RandListView extends Component{
|
|||||||
reject(error);
|
reject(error);
|
||||||
})
|
})
|
||||||
.then((responseData) => {
|
.then((responseData) => {
|
||||||
|
|
||||||
if(responseData){
|
if(responseData){
|
||||||
|
var movieArr = dataSource;
|
||||||
|
for (var i in responseData.datas) {
|
||||||
|
movieArr.push(responseData.datas[i]);
|
||||||
|
};
|
||||||
|
if(page === 1){
|
||||||
|
dataSource = responseData.datas;
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
dataSource: this.state.dataSource.cloneWithRows(responseData.datas),
|
dataSource: this.state.dataSource.cloneWithRows(dataSource),
|
||||||
});
|
});
|
||||||
resolve(responseData.datas);
|
resolve(responseData.datas);
|
||||||
}else{
|
}else{
|
||||||
reject('none');
|
reject('none');
|
||||||
}
|
}
|
||||||
@@ -72,14 +80,22 @@ export default class RandListView extends Component{
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
loadMore(){
|
||||||
|
page++;
|
||||||
|
return this.fetchData();
|
||||||
|
}
|
||||||
|
refreshData(){
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
render(){
|
render(){
|
||||||
return (
|
return (
|
||||||
<MyListView
|
<MyListView
|
||||||
dataSource={this.state.dataSource}
|
dataSource={this.state.dataSource}
|
||||||
refreshTitle={'随机刷新'}
|
refreshTitle={'刷新'}
|
||||||
{...this.props}
|
{...this.props}
|
||||||
fetchData={this.fetchData.bind(this)}/>
|
fetchData={this.fetchData.bind(this)}
|
||||||
|
loadMore={this.loadMore.bind(this)}
|
||||||
|
refreshData={this.refreshData.bind(this)}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ export default class MyListView extends Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
onRefresh(){
|
onRefresh(){
|
||||||
|
if (typeof this.props.refreshData === 'function') {
|
||||||
|
console.log('shuaxing')
|
||||||
|
this.props.refreshData()
|
||||||
|
}
|
||||||
this.myfetchData();
|
this.myfetchData();
|
||||||
}
|
}
|
||||||
//数据查询.
|
//数据查询.
|
||||||
@@ -76,6 +80,15 @@ export default class MyListView extends Component{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
onEndReached(){
|
||||||
|
if (typeof this.props.loadMore === 'function') {
|
||||||
|
this.props.loadMore().then((responseData)=>{
|
||||||
|
},(error)=>{
|
||||||
|
AlertIOS.alert('没有更多数据');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
// return this.renderLoadingView();
|
// return this.renderLoadingView();
|
||||||
@@ -88,10 +101,11 @@ export default class MyListView extends Component{
|
|||||||
dataSource={this.props.dataSource}
|
dataSource={this.props.dataSource}
|
||||||
renderRow={this.renderMovie.bind(this)}
|
renderRow={this.renderMovie.bind(this)}
|
||||||
renderSeparator={this.renderMovieRow}
|
renderSeparator={this.renderMovieRow}
|
||||||
|
onEndReached={this.onEndReached.bind(this)}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={this.state.isLoading}
|
refreshing={this.state.isLoading}
|
||||||
onRefresh={this.myfetchData.bind(this)}
|
onRefresh={this.onRefresh.bind(this)}
|
||||||
tintColor="#61BFA9"
|
tintColor="#61BFA9"
|
||||||
title={this.props.refreshTitle}
|
title={this.props.refreshTitle}
|
||||||
colors={['#ff0000', '#00ff00', '#0000ff']}
|
colors={['#ff0000', '#00ff00', '#0000ff']}
|
||||||
|
|||||||
Reference in New Issue
Block a user