在反应本机应用程序中滚动拉格列表时,平面列表滚动工作不顺畅并显示空白区域

2024-03-28

我正在使用react-native-flatlist网格滚动来自服务器的最大数据并获取并显示在我的屏幕上。但我的应用程序中的滚动并不流畅。

有什么解决办法吗?

滚动屏幕时我也面临着空白。列表消失并在 UI 中显示空白区域。

有什么解决办法吗?

import React, { Component } from 'react';
import {
  ActivityIndicator,
  Image,
  Platform,
  StyleSheet,
  Text,
  FlatList,
  Button,
  View,
  SafeAreaView,
  ScrollView,
  TouchableOpacity,
  PixelRatio,
  Dimensions,
  StatusBar
} from 'react-native';
import _ from 'lodash';
import ImageCropPicker from 'react-native-image-crop-picker';
import Orientation from 'react-native-orientation';
import FastImage from 'react-native-fast-image';

class MyShowroom extends Component {
  constructor() {
    super();
    this.state = {
      index: 0,
      section: 0,
      width: 0,
      height: 0,
      isPageLoaded: false,
      loadingMoreItems: false,
      lastItemIndex: 0,
      page: 0,
    }
    Orientation.addOrientationListener(this._updateOrientation.bind(this))
  }


        renderList(item) {
            return(
              <TouchableOpacity>
                <View style={{backgroundColor: 'white', alignItems: 'center'}}>
                  <FastImage style={{width: gridWidth, height: gridHeight}}
                    resizeMode={FastImage.resizeMode.contain}
                    source={item.uri}/>
                </View>
              </TouchableOpacity>
            );
          }

    // extra data is rendering from the  redux 
        render(){
          return(
            <FlatList
                          ref={(ref) => { this.flatListRef = ref; }}
                          data={Items}
                          renderItem={({ item }) => this.renderList(item)}
                          numColumns={2}
                          extraData={this.props.pagination}
                          keyExtractor={item => item.id}
                          onEndReached={this._handleMoreItems}
                          onEndReachedThreshold={0.001}
                          ListFooterComponent={this._renderFooter}
                          legacyImplementation = {true}
                          bounces = {false}
                          onMomentumScrollEnd={e => this.scroll(e.nativeEvent.contentOffset)}
                        />
          )
        }

这是由于 FlatList 组件的性能问题造成的,但您可以将以下道具添加到 FlatList 组件中,这将有助于解决问题。 他们是: 我。删除ClippedSubviews。将其设置为 true,默认值为 false。 二.窗口大小。将其设置为一个数字,例如 30 三. maxToRenderPerBatch。这控制每批渲染的项目数量, 这是每个滚动条上渲染的下一个项目块。

<FlatList
            data={this.state.contacts}
            removeClippedSubviews={true}
            maxToRenderPerBatch={60}
            windowSize={30}
            ListHeaderComponent={headerComponent}
            contentContainerStyle={{ paddingBottom: 10 }}
            renderItem={({ item }) => (
              <View>
                {item}
              </View>
            )}
            numColumns={1}
            keyExtractor={(item, index) => String(index)}
          />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在反应本机应用程序中滚动拉格列表时,平面列表滚动工作不顺畅并显示空白区域 的相关文章

随机推荐