Reactjs 反应本机平面列表项未达到正确高度
我在平面列表中有不同高度(250或150)的项目, 当迭代每个项目并为FlatList附加dataSrouce的状态时,一切都呈现正常,但如果我想避免“附加”影响并将dataSrouce一次性设置为所有项目,FlatList似乎有一个wierd bug,其中项目没有获得正确的高度(在底部有一个空白处,物品本应填充) 尝试将“flexGrow:1”放在平面列表上,尝试“initialNumToRender”属性, 试图固定视图中每个项目的高度 扁平列表的容器是“flex:1” 我的公寓名单:Reactjs 反应本机平面列表项未达到正确高度,reactjs,react-native,react-native-android,react-native-flatlist,Reactjs,React Native,React Native Android,React Native Flatlist,我在平面列表中有不同高度(250或150)的项目, 当迭代每个项目并为FlatList附加dataSrouce的状态时,一切都呈现正常,但如果我想避免“附加”影响并将dataSrouce一次性设置为所有项目,FlatList似乎有一个wierd bug,其中项目没有获得正确的高度(在底部有一个空白处,物品本应填充) 尝试将“flexGrow:1”放在平面列表上,尝试“initialNumToRender”属性, 试图固定视图中每个项目的高度 扁平列表的容器是“flex:1” 我的公寓名单:
render() {
const _this = this;
const { loading } = this.state;
return (
<Components.ViewContainer>
{this.printTopHeader()}
{loading ? (
<ActivityIndicator size={25} />
) : (
<FlatList
style={{ flex: 1 }}
removeClippedSubviews={true} //tried with and without
data={this.state.posts}
extraData={this.state.posts} //tried with and without
renderItem={({ item }) => (
<HomeCard
post={item}
/>
)}
keyExtractor={(item, index) => item.key}
/>
)}
</Components.ViewContainer>
);
家庭卡:
render() {
const { theme, showActions } = this.props;
const {
imageUrl,
user,
title,
selectedPlace,
textColor,
backgroundColor
} = this.props.post;
return (
<Components.ContainerView>
...
</Components.ContainerView>
);
}
export default withTheme(HomeCard); // styled-components implementation
render(){
const{theme,showActions}=this.props;
常数{
imageUrl,
用户,
标题
选定地点,
textColor,
背景色
}=this.props.post;
返回(
...
);
}
导出默认主题(HomeCard);//样式化组件实现
该问题是由应用于子元素的错误样式引起的,
通过更好地理解FlexBox的工作原理,我发现列表元素中缺少了
flex:1
属性,因此项目样式没有正确计算。您需要添加代码来演示此行为。请尝试将代码片段添加到您的问题中,并生成一个示例FlatList
代码。@anhtu添加了代码段。@PritishVaidya我没有设法减少错误,因此您尝试了行的显式高度吗?
render() {
const { theme, showActions } = this.props;
const {
imageUrl,
user,
title,
selectedPlace,
textColor,
backgroundColor
} = this.props.post;
return (
<Components.ContainerView>
...
</Components.ContainerView>
);
}
export default withTheme(HomeCard); // styled-components implementation