【发布时间】:2019-10-29 08:19:52
【问题描述】:
我正在使用 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 的性能非常好,因此您的代码可能可以优化。
-
更新了我上面的代码
-
你能添加整个组件代码吗?
-
添加了我正在使用的组件
-
您是否在发布版本上运行过它。有时其他因素,尤其是在开发人员/调试版本中会导致列表运行缓慢。尝试在发布版本上运行它,看看它是否仍然很慢
标签: react-native react-native-flatlist