栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

反应原生无限滚动

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

反应原生无限滚动

您总是使用相同的数据克隆数据源,因此不会出现新的情况。这是一个有效的示例(通过添加新数据

concat
):

var React = require('react-native');var {    StyleSheet,    View,    Image,    ListView,    } = React;var data = [    {        "id": 1,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    },    {        "id": 2,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    },    {        "id": 3,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    },    {        "id": 4,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    },    {        "id": 5,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    },    {        "id": 6,        "profile_picture": { "href": "//like1.r.worldssl.net/ui_big/1305634.jpg"        }    }];var InfiniteScreen = React.createClass({    getInitialState: function () {        return { isLoadingTail: false, dataSource: new ListView.DataSource({     rowHasChanged: (row1, row2) => row1 !== row2, })        };    },    componentDidMount: function () {        this._data = [];        this.setState({ dataSource: this.getDataSource(data)        });    },    renderRow: function (item) {        return ( <View>     <Image style={{width: 80, height: 80}} source={{uri: 'http:' + item.profile_picture.href}}/> </View>        );    },    onEndReached: function () {        console.log('onEndReached', this.state.isLoadingTail);        if (this.state.isLoadingTail) { // We're already fetching return;        }        this.setState({ isLoadingTail: true        });        this.setState({ isLoadingTail: false, dataSource: this.getDataSource(data)        });    },    getDataSource: function (users):ListView.DataSource {        this._data = this._data.concat(users);        return this.state.dataSource.cloneWithRows(this._data);    },    render: function () {        return ( <View style={styles.container}>     <ListView         dataSource={this.state.dataSource}         renderRow={this.renderRow}         onEndReached={this.onEndReached}     /> </View>);    }});var styles = StyleSheet.create({  container: {    flex: 1,    justifyContent: 'center',    backgroundColor: '#F5FCFF',  },});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/608891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号