我的ReactNative FlatList没有使用这个简单的实现进行渲染 .
<FlatList style={{flex:1, backgroundColor:'red'}}
data = {this.state.users}
keyExtractor={item => item.key.toString()}
renderItem={({item}) => {
return (
<ChatUserCard key={item.uid} username={item.username} />
)
}}
/>
ChatUserCard
<View style={styles.cardStyle}>
<Text style={styles.itemStyle}>{this.props.username}</Text>
<Button style={styles.buttonStyle}
title='Chat'
onPress={this.startChat} />
</View>
2 回答
我'm thinking what'正在进行的是你没有将
FlatList
包裹在flex: 1
中设置了flex: 1
. 此外,您可以使用uid
作为键,而不是在对象数据中设置key
演示
https://snack.expo.io/@anonymoussb/so53688423
尝试在平面列表下方的视图中添加注释,并从平面列表中的样式中删除flex 1 . 尝试检查它是否与样式相关