React-native FlatList项目未达到正确的高度

时间:2018-05-07 08:25:41

标签: reactjs react-native react-native-android react-native-flatlist

我在FlatList中有不同高度(250或150)的物品, 当迭代每个项目并为FlatList附加dataSrouce的状态时,所有渲染都没问题,但是如果我想避免"追加"一次影响并将dataSrouce设置为所有项目,看起来FlatList有一个奇怪的错误,其中项目没有达到正确的高度(项目假设填充它的底部有一个空白区域。)

尝试过" flexGrow:1 "在FlatList上,尝试了" initialNumToRender "属性, 试图修复视图中每个项目的高度。

FlatList的容器是" flex:1"。

enter image description here

我的FlatList:

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

HomeCard:

  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

1 个答案:

答案 0 :(得分:0)

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

相关问题