React Native FlatList 不滚动

React Native FlatList is not scrolling

我正在开发一个用于学习目的的 React Native 应用程序。现在我在我的应用程序中使用 FlatList。但我遇到了问题。我的平面列表没有滚动查看所有项目。当我试图将它滚动到屏幕尺寸之外时,它会弹回来。我使用了网上找到的解决方案,在根目录上将 flex 添加到 1,但它不起作用。

这是我的代码:

class Events extends React.Component {
  static navigationOptions = {
    title: "Events"
  };

  constructor(props) {
    super(props);
    this.state = {
      data: [
        {
          id: 1,
          name: "Name 1"
        },
        {
          id: 2,
          name: "Name 2"
        },
        {
          id: 3,
          name: "Name 3"
        },
        {
          id: 4,
          name: "Name 4"
        },
        {
          id: 5,
          name: "Name 5"
        },
        {
          id: 6,
          name: "Name 6"
        },
        {
          id: 7,
          name: "Name 7"
        },
        {
          id: 8,
          name: "Name 8"
        },
        {
          id: 9,
          name: "Name 9"
        },
        {
          id: 10,
          name: "Name 10"
        },
        {
          id: 11,
          name: "Name 11"
        },
        {
          id: 12,
          name: "Name 12"
        },
        {
          id: 13,
          name: "Name 13"
        },
        {
          id: 14,
          name: "Name 14"
        },
        {
          id: 15,
          name: "Name 15"
        },
        {
          id: 16,
          name: "Name 16"
        },
        {
          id: 17,
          name: "Name 17"
        },
        {
          id: 18,
          name: "Name 18"
        },
        {
          id: 19,
          name: "Name 19"
        },
        {
          id: 20,
          name: "Name 20"
        },
        {
          id: 21,
          name: "Name 21"
        },
        {
          id: 22,
          name: "Name 22"
        },
        {
          id: 23,
          name: "Name 23"
        },
        {
          id: 24,
          name: "Name 24"
        }
      ]
    };
  }

  _handleLoadMore() {}

  renderItem(item) {
    return (
      <Card>
        <CardItem>
          <Left>
            <Thumbnail source={{ uri: "https://www.vkguy.co.uk/images/slideshow/05.jpg" }} />
            <Body>
              <Text>NativeBase</Text>
              <Text note>GeekyAnts</Text>
            </Body>
          </Left>
        </CardItem>
        <CardItem cardBody>
          <Image
            source={{ uri: "https://www.vkguy.co.uk/images/slideshow/05.jpg" }}
            style={{ height: 200, width: null, flex: 1 }}
          />
        </CardItem>
        <CardItem>
          <Left>
            <Button transparent>
              <Icon active name="thumbs-up" />
              <Text>12 Likes</Text>
            </Button>
          </Left>
          <Body>
            <Button transparent>
              <Icon active name="chatbubbles" />
              <Text>4 Comments</Text>
            </Button>
          </Body>
          <Right>
            <Text>11h ago</Text>
          </Right>
        </CardItem>
      </Card>
    );
  }

  render() {
    return (
        <FlatList
        contentContainerStyle={{
          flex: 1,
          flexDirection: "column",
          height: "100%",
          width: "100%"
        }}
        data={this.state.data}
        keyExtractor={item => item.id.toString()}
        renderItem={({ item }) => this.renderItem(item)}
        onEndReached={this._handleLoadMore}
      />
    );
  }
}

export default Events;

但不是滚动查看屏幕外的项目。我该如何解决?

这是截图。我不能再向下滚动了。

更改 FlatList 视图中的一些样式并添加 View 作为主容器

render() {
    return (
        <View style={{ flex: 1, width: '100%' }}>
            <FlatList 
                data={this.state.data}
                keyExtractor={item => item.id.toString()}
                renderItem={({ item }) => this.renderItem(item)}
                onEndReached={this._handleLoadMore}
            />
        </View>
    );
  }

试试

<FlatList
    contentContainerStyle={{ flexGrow: 1, paddingBottom: 5 }}
    data={this.state.data}
    keyExtractor={item => item.id.toString()}
    renderItem={({ item }) => this.renderItem(item)}
    onEndReached={this._handleLoadMore}
    onEndReachedThreshold={0.5}
  />