gpt4 book ai didi

reactjs - React-native FlatList 项目没有达到正确的高度

转载 作者:行者123 更新时间:2023-12-04 13:03:00 28 4
gpt4 key购买 nike

我在 FlatList 中有不同高度(250 或 150)的项目,
当迭代每个项目并为 FlatList 附加 dataSrouce 的状态时,一切都正常,但是如果我想避免“附加”影响并将 dataSrouce 一次设置为所有项目,似乎 FlatList 有一个奇怪的错误,其中项目没有得到正确的高度(底部有一个空白区域,该项目应该填充它)。

尝试将“flexGrow:1”放在 FlatList 上,尝试“initialNumToRender”属性,
试图固定 View 中每个项目的高度。

FlatList 的容器是“flex:1”。

enter image description here

我的平面列表:

  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>
);

}

Components.ViewContainer:
const ViewContainer = styled.View`
flex:1;
`;

家庭卡:
  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

最佳答案

该问题是由应用于子元素的错误样式引起的,
通过更好地了解 FlexBox 的工作原理,我设法发现我缺少一个 flex: 1属性,因此项目样式计算不正确。

关于reactjs - React-native FlatList 项目没有达到正确的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50209963/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com