React-native ListView pull-down refresh and pull the load implementation code,

Source: Internet
Author: User

React-native ListView pull-down refresh and pull the load implementation code,

This article describes how to pull and load a react-native ListView pull-down refresh. Share it with you as follows:

First look

Pull-down refresh

React Native provides a component to implement the RefreshControl method of pull-down refresh.

Usage

<ListView refreshControl={ <RefreshControl refreshing={this.state.refreshing} onRefresh={this._onRefresh.bind(this)} /> } //...</ListView>

When loading a view, set refreshing to true and set data loading to false.

Pull up and load

The onEndReached method in ListView is used. When ListView is rolled to the last Cell, the onEndReached method is triggered.

First add a Footer in ListView

Render () {const FooterView = this. state. loadMore? <View style = {styles. footer}> <Text style => load more... </Text> </View>: null; return <ListView refreshControl = {<RefreshControl refreshing = {this. state. refreshing} onRefresh = {this. _ onRefresh. bind (this)}/>}style = {[styles. listView]} dataSource = {ds. cloneWithRows (this. state. dataSource)} enableEmptySections = {true} renderRow = {this. _ renderRow. bind (this)} onEndReachedThreshold = {5} onEndReached = {this. _ onEndReached. bind (this)} renderFooter = {() => FooterView}/>}

Display Footer in method _ onEndReached. After the data is loaded, hide Footer.

_onEndReached() { this.setState({ loadMore: true, pageNo: this.state.pageNo + 1 }); this._fetchData(); }

Description

The ListView also sets the onEndReachedThreshold parameter to be used with onEndReached, which means that the critical value of the pixel is used with onEndReached, this is because the onEndReached sliding end flag uses this value as the judgment condition.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.