欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react native之ScrollView下拉刷新效果

 更新時(shí)間:2021年09月09日 15:51:13   作者:創(chuàng)客未來  
這篇文章主要為大家詳細(xì)介紹了react native之ScrollView下拉刷新效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了react native之ScrollView下拉刷新效果的具體代碼,供大家參考,具體內(nèi)容如下

ScrollView的refreshControl屬性用于下拉刷新,只能用于垂直視圖,即horizontal不能為true。

1.創(chuàng)建自定義CKRefresh.js刷新組件

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:'初始化數(shù)據(jù)'+index
            })),
            //是否顯示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="正在加載中..."
                    />
                }
            >
                {rowsArr}
            </ScrollView>
        )
    }

    _onRefresh(){
        //1.顯示指示器
        this.setState({
            isRefreshing:true
        });
        //2.模擬加載數(shù)據(jù)
        setTimeout(()=>{
            let newDataArr=Array.from(new Array(5)).map((value,index)=>({
                title:'我是拉下來的數(shù)據(jù)'+(this.state.loaded+index)
            })).concat(this.state.rowDataArr);
            //更新狀態(tài)機(jī)
            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.在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.結(jié)果如圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Ant Design組件庫的使用教程

    Ant Design組件庫的使用教程

    AntDesign ,簡稱antd是基于 Ant Design 設(shè)計(jì)體系的 React UI 組件庫,主要用于研發(fā)企業(yè)級中后臺產(chǎn)品,這篇文章主要介紹了Ant Design組件庫的使用教程,需要的朋友可以參考下
    2023-12-12
  • 一文帶你搞懂React中的useReducer

    一文帶你搞懂React中的useReducer

    useReducer 是除useState之外另一個與狀態(tài)管理相關(guān)的 hook,這篇文章主要為大家介紹了useReducer應(yīng)用的相關(guān)知識,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-06-06
  • 淺析React 對state的理解

    淺析React 對state的理解

    state狀態(tài)是組件實(shí)例對象身上的狀態(tài),不是組件類本身身上的,是由這個類締造的實(shí)例身上的。這篇文章主要介紹了React 對state的理解,需要的朋友可以參考下
    2021-09-09
  • React組件通信實(shí)現(xiàn)方式詳解

    React組件通信實(shí)現(xiàn)方式詳解

    這篇文章主要介紹了React組件通信,在開發(fā)中組件通信是React中的一個重要的知識點(diǎn),本文通過實(shí)例代碼給大家講解react中常用的父子、跨組件通信的方法,需要的朋友可以參考下
    2023-03-03
  • 采用React編寫小程序的Remax框架的編譯流程解析(推薦)

    采用React編寫小程序的Remax框架的編譯流程解析(推薦)

    這篇文章主要介紹了采用React編寫小程序的Remax框架的編譯流程解析(推薦),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • React高階組件使用詳細(xì)介紹

    React高階組件使用詳細(xì)介紹

    高階組件就是接受一個組件作為參數(shù)并返回一個新組件(功能增強(qiáng)的組件)的函數(shù)。這里需要注意高階組件是一個函數(shù),并不是組件,這一點(diǎn)一定要注意,本文給大家分享React高階組件使用小結(jié),一起看看吧
    2023-01-01
  • react-three/postprocessing庫的參數(shù)中文含義使用解析

    react-three/postprocessing庫的參數(shù)中文含義使用解析

    這篇文章主要介紹了react-three/postprocessing庫的參數(shù)中文含義使用總結(jié),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • React中useTransition鉤子函數(shù)的使用詳解

    React中useTransition鉤子函數(shù)的使用詳解

    React?18的推出標(biāo)志著React并發(fā)特性的正式到來,其中useTransition鉤子函數(shù)是一個重要的新增功能,下面我們就來學(xué)習(xí)一下useTransition鉤子函數(shù)的具體使用吧
    2024-02-02
  • 詳解React Native 屏幕適配(炒雞簡單的方法)

    詳解React Native 屏幕適配(炒雞簡單的方法)

    React Native 可以開發(fā) ios 和 android 的 app,在開發(fā)過程中,勢必會遇上屏幕適配,這篇文章主要介紹了詳解React Native 屏幕適配(炒雞簡單的方法),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • React組件通信實(shí)現(xiàn)流程詳解

    React組件通信實(shí)現(xiàn)流程詳解

    這篇文章主要介紹了React組件通信,在開發(fā)中組件通信是React中的一個重要的知識點(diǎn),本文通過實(shí)例代碼給大家講解react中常用的父子、跨組件通信的方法,需要的朋友可以參考下
    2022-12-12

最新評論