This article shares the specific code of the pull-down refresh effect of react native ScrollView for your reference. The specific content is as follows The refreshControl property of ScrollView is used for pull-down refresh and can only be used for vertical views, that is, horizontal cannot be true. 1. Create a custom CKRefresh.js refresh component import React,{Component} from 'react'; import { View, Text, StyleSheet, ScrollView, RefreshControl, Dimensions } from 'react-native'; const screenW=Dimensions.get('window').width; export default class CKRefresh extends Component{ constructor(){ super(); this.state={ rowDataArr:Array.from(new Array(30)).map((value,index)=>({ title:'Initialize data'+index })), //Whether to display loading isRefreshing:false, loaded:0 } } render(){ const rowsArr=this.state.rowDataArr.map((row,index)=>(<Row data={row} key={index}/>)) return( <ScrollView refreshControl={ <RefreshControl refreshing={this.state.isRefreshing} onRefresh={()=>this._onRefresh()} colors={['red','green','blue']} title="Loading..." /> } > {rowsArr} </ScrollView> ) } _onRefresh(){ //1. Display indicator this.setState({ isRefreshing:true }); //2. Simulate loading data setTimeout(()=>{ let newDataArr=Array.from(new Array(5)).map((value,index)=>({ title:'I am the data pulled down'+(this.state.loaded+index) })).concat(this.state.rowDataArr); //Update state machine this.setState({ rowDataArr:newDataArr, isRefreshing:false, loaded:this.state.loaded+5 }); },2000); } } class Row extends Component { static defaultProps = { data:{} }; render(){ return( <View style={{ width:screenW, height:40, borderBottomWidth:1, borderBottomColor:'red', justifyContent:'center' }}> <Text>{this.props.data.title}</Text> </View> ) } } const styles = StyleSheet.create({ }) 2. Reference in App.js /** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import React from 'react'; import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, } from 'react-native'; import { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; import CKRefresh from './components/CKRefresh'; const App: () => React$Node = () => { return ( <> <StatusBar barStyle="dark-content" /> <SafeAreaView style={styles.mainViewStyle}> <CKRefresh/> </SafeAreaView> </> ); }; const styles = StyleSheet.create({ mainViewStyle:{ flex:1, backgroundColor:'#fff', } }); export default App; 3. The results are as shown in the figure The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to use Gitlab-ci to continuously deploy to remote machines (detailed tutorial)
1. Introduction Earlier we talked about the front...
What is CN2 line? CN2 stands for China Telecom Ne...
Table of contents 1. Specify different packaging ...
Here are some common MySQL commands for you: -- S...
Table of contents Preparation Install VMware Work...
Table of contents Preface 1. Routing lazy loading...
Table of contents Preface Descriptors Detailed ex...
1. To build a PPTP VPN, you need to open port 172...
Here are 10 tips on how to design better-usable w...
Theoretically, the memory used by MySQL = global ...
1. Two properties of table reset: ①border-collaps...
Native JS implements the click number game for yo...
Table of contents EffectList Collection EffectLis...
Table of contents 1. What is a calculated propert...
Table of contents Integrity constraints Definitio...