[英]Mistake to render data on FlatList(native) - React Native
I've an application in react native that receive data from API and render to FlastList.我有一个反应原生的应用程序,它从 API 接收数据并渲染到 FlastList。 However is happening a trouble like a image.
然而正在发生一个像图像一样的麻烦。
<ScrollView>
<FlatList
data={MyAPIData}
renderItem={({ item, index }) => (
<ContainerFlatList
style={{
backgroundColor: index % 2 === 0 ? '#F4F4F4' : '#ffff',
}}
>
<TextKey>
{item.data1}
</TextKey>
<TextFlatList>
</ ScrollView>
Someone has gone through this situation?有人经历过这种情况吗?
Some things that may help you.一些可能对你有帮助的事情。
1- Using ScrollView requires to wrap parent container into {flex: 1}
1- 使用 ScrollView 需要将父容器包装到
{flex: 1}
2- following the flatlist react-native's doc we see that you need to wrap it inside a SafeAreaView, not a ScrollView, here is a example from an App i've developed: 2-在flatlist react-native 的文档之后,我们看到您需要将其包装在 SafeAreaView 中,而不是 ScrollView 中,这是我开发的应用程序的示例:
<SafeAreaView style={styles.safeView}>
<FlatList
numColumns={2}
columnWrapperStyle={styles.list}
ItemSeparatorComponent={() => <Text></Text>}
data={this.state.arrEstab}
renderItem={({ item }) => <CardComponent style={styles.card}
navigation= {this.props.navigation} nome={item.nome} imgUrl=
{this.props.selectedType.url} estab={item} parent="porTipo"/>}
keyExtractor={item => item._id}
/>
</SafeAreaView>
...,safeView: {
height: '80%',
width: '100%'
},...
3- for avoiding errors, supply a keyExtractor
if you dont have an ID, just pass the index of the item. 3-为避免错误,如果您没有 ID,请提供
keyExtractor
,只需传递项目的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.