From beb5c0ec2144b17b7c1ad525777cbe4021589ac9 Mon Sep 17 00:00:00 2001 From: xuwenyang Date: Sat, 18 May 2019 15:06:41 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=8E=BB=E6=8E=89customedList=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A2=9E=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=A4=8D=E6=9D=82=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/customedList.js | 97 --------------------- src/component/follow/followUserList.js | 112 ++++++++++++++++++++----- 2 files changed, 90 insertions(+), 119 deletions(-) delete mode 100644 src/component/customedList.js diff --git a/src/component/customedList.js b/src/component/customedList.js deleted file mode 100644 index d1b6caf..0000000 --- a/src/component/customedList.js +++ /dev/null @@ -1,97 +0,0 @@ -import React, {Component} from 'react'; -import {StyleSheet, Text, View, InteractionManager, FlatList} from 'react-native'; - - -export default class CustomedList extends Component { - - constructor(props) { - super(props); - - this.listType = props.listType || 'undefined'; - this.dataSource = props.dataSource; - - this.state = { - listData: [], - hasMore: false, - - refreshing: false, - refreshFailed: false - }; - } - - componentDidMount() { - InteractionManager.runAfterInteractions(() => { - this.refresh(); - }); - } - - refresh(loadMore = false) { - if (this.state.refreshing) { - return; - } - - this.setState({hasMore: false, refreshing: true, refreshFailed: false}); - this.dataSource.refresh(loadMore) - .then(result => { - if(!result) { - throw { - message: 'refresh ' + this.listType + ' no result' - } - - } else { - console.log('refresh ' + this.listType + ' result:', result); - - this.setState({ - listData: result.list ? result.list : [], - hasMore: result.more, - refreshFailed: false - }); - } - - }).catch(e => { - this.setState({ - listData: [], - hasMore: false, - refreshFailed: true - }); - - }).done(() => { - this.setState({ - refreshing: false - }); - }); - } - - loadMore() { - if (this.state.refreshing) { - return; - } - - this.refresh(true); - } - - render() { - return ( - { - return item.id ? item.id.toString() : index; - }} - - renderItem={this.props.renderItem} - - refreshing={this.state.refreshing} - onRefresh={this.refresh.bind(this)} - - onEndReachedThreshold={5} - onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null} - /> - ); - } -} - -const localStyle = StyleSheet.create({ - -}); diff --git a/src/component/follow/followUserList.js b/src/component/follow/followUserList.js index 7d5c5b9..bc3ffe7 100644 --- a/src/component/follow/followUserList.js +++ b/src/component/follow/followUserList.js @@ -6,7 +6,6 @@ import Touchable from '../touchable'; import Color from '../../style/color'; import UserIcon from '../userIcon'; -import CustomedList from '../customedList'; export default class FollowUserList extends Component { @@ -15,33 +14,102 @@ export default class FollowUserList extends Component { super(props); this.dataSource = props.dataSource; - this.listType = props.listType; + this.listType = props.listType || 'undefined'; + + this.state = { + users: [], + hasMore: false, + + refreshing: false, + refreshFailed: false + }; + } + + componentDidMount() { + InteractionManager.runAfterInteractions(() => { + this.refresh(); + }); + } + + refresh(loadMore = false) { + if (this.state.refreshing) { + return; + } + + this.setState({hasMore: false, refreshing: true, refreshFailed: false}); + this.dataSource.refresh(loadMore) + .then(result => { + if(!result) { + throw { + message: 'refresh ' + this.listType + ' no result' + } + + } else { + console.log('refresh ' + this.listType + ' result:', result); + + this.setState({ + users: result.list ? result.list : [], + hasMore: result.more, + refreshFailed: false + }); + } + + }).catch(e => { + this.setState({ + users: [], + hasMore: false, + refreshFailed: true + }); + + }).done(() => { + this.setState({ + refreshing: false + }); + }); + } + + loadMore() { + if (this.state.refreshing) { + return; + } + + this.refresh(true); } render() { return ( - - + { - return ( - {}}> - - - {item.name} - {}}> - - - - - ); - }} - /> - + keyExtractor={(item, index) => { + return item.id ? item.id.toString() : index; + }} + + renderItem={({item}) => { + return ( + {}}> + + + {item.name} + {}}> + + + + + ); + }} + + refreshing={this.state.refreshing} + onRefresh={this.refresh.bind(this)} + + onEndReachedThreshold={5} + onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null} + /> + ); } }