react-native 笔记-下拉刷新-scrollView

叁歲伎倆 2023-06-29 05:38 20阅读 0赞

笔记-下拉刷新

  1. import React, { Component } from 'react';
  2. import {
  3. View,
  4. Text,
  5. StyleSheet,
  6. ScrollView,
  7. Dimensions,
  8. RefreshControl,
  9. StatusBar,
  10. SafeAreaView,
  11. } from 'react-native'
  12. const width = Dimensions.get('window').width;
  13. class DemoRefresh extends Component {
  14. constructor(){
  15. super();
  16. this.state = {
  17. rowDataArr: Array.from( new Array(30)).map( (value, index) => ({
  18. title: '初始化数据' + index
  19. })),
  20. isRefreshing: false,
  21. loaded: 0,
  22. }
  23. }
  24. onRefreshHandle() {
  25. this.setState({
  26. isRefreshing: true
  27. })
  28. setTimeout(() => {
  29. let newDataArr = Array.from( new Array(5)).map( (value, index) => ({
  30. title: '我是下拉数据' + (index + this.state.loaded)
  31. })).concat( this.state.rowDataArr );
  32. this.setState({
  33. rowDataArr: newDataArr,
  34. isRefreshing: false,
  35. loaded: this.state.loaded + 5
  36. })
  37. }, 2000);
  38. }
  39. render() {
  40. const rowArr = this.state.rowDataArr.map((row, index) => (<Row data={row} key={index}></Row>))
  41. return (
  42. <>
  43. <StatusBar barStyle="dark-content"></StatusBar>
  44. <SafeAreaView>
  45. <ScrollView
  46. refreshControl = {
  47. <RefreshControl
  48. refreshing={ this.state.isRefreshing }
  49. onRefresh = {() => this.onRefreshHandle()}
  50. />
  51. }
  52. >
  53. {rowArr}
  54. </ScrollView>
  55. </SafeAreaView>
  56. </>
  57. )
  58. }
  59. }
  60. const styles = StyleSheet.create({
  61. })
  62. class Row extends Component {
  63. render() {
  64. return(
  65. <View style={
  66. {
  67. width: width,
  68. height: 40,
  69. borderBottomColor: 'red',
  70. borderBottomWidth: 1,
  71. justifyContent: 'center'
  72. }}>
  73. <Text>{this.props.data.title}</Text>
  74. </View>
  75. )
  76. }
  77. }
  78. export default DemoRefresh;

Ios

在这里插入图片描述

android

在这里插入图片描述
(完)

发表评论

表情:
评论列表 (有 0 条评论,20人围观)

还没有评论,来说两句吧...

相关阅读