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)
Table of contents illustrate 1. Blob object 2. Fr...
Table of contents 1. The writing order of a compl...
Copy code The code is as follows: <form method...
Table of contents Initialization of echart app-ba...
This article example shares the specific code of ...
1. Introduction I have taken over a project of th...
html <div > <button type="button&qu...
Table of contents 1. Installation 2. There is no ...
Table of contents 1. Three functions of toString ...
Written in the opening: Absolute said: "Rela...
Table of contents Overview File Descriptors Synch...
The <marquee> tag is a tag that appears in ...
Docker Compose can realize the orchestration of D...
Table of contents 1. Introduction to Nginx 2. Ima...
Table of contents Why understand the life cycle W...