【问题标题】:FlatList inside ScrollView not scrollingScrollView中的FlatList不滚动
【发布时间】:2021-01-05 13:46:57
【问题描述】:

我有一个要求,个人资料数据将位于顶部,而提要将在其后出现。在滚动提要时,配置文件部分也应该滚动。表示整个页面需要滚动。

所以我在 ScrollView 中实现了 FlatList。

<ScrollView
        contentContainerStyle={{ flex: 1 }}>
        <FlatList
          showsVerticalScrollIndicator={false}
          showsHorizontalScrollIndicator={false}
          data={this.state.feed}
          keyExtractor={(item, index) => item.id}
          refreshControl={this.refreshControl()}
          renderItem={({ item, index }) => this.renderItem(item, index)}
          numColumns={2}
          ListFooterComponent={this.renderFooter.bind(this)}
          onEndReachedThreshold={0.4}
          onEndReached={this.handleLoadMore.bind(this)} />
</ScrollView> 

但我无法滚动页面。

如果我删除 contentContainerStyle={{ flex: 1 }},那么 handleLoadMore 函数会不断地调用自己。

感谢您的任何建议!

【问题讨论】:

    标签: react-native scrollview react-native-flatlist nestedscrollview


    【解决方案1】:

    试试这个

      <ScrollView
        contentContainerStyle={{flexGrow:1}}
            scrollEventThrottle={200}
            directionalLockEnabled={true}
        >
     <FlatList
              showsVerticalScrollIndicator={false}
              showsHorizontalScrollIndicator={false}
              data={this.state.feed}
              keyExtractor={(item, index) => item.id}
              refreshControl={()=>this.refreshControl()}
              renderItem={({ item, index }) => this.renderItem(item, index)}
              numColumns={2}
              ListFooterComponent={(e)=>this.renderFooter.bind(e)}
              onEndReachedThreshold={0.4}
              onEndReached={(e)=>this.handleLoadMore.bind(e)} />
    
    
    
    use Callback like this. //
    
    ()=>this.yourFUNC()
    
    or
    
    this.yourFUNC()
    

    【讨论】:

    • 在这种情况下,启用滚动。但是 handleLoadMore() 已经被连续调用了。因为没有 flex: 1
    • 使用箭头函数和 bind(),handleLoadMore() 甚至没有被调用一次。没有绑定,它已经调用了多次。
    • 你可以尝试在这些函数中调用 alert() 并尝试
    • 嘿,谢谢!但是如果我们也添加一个警报,同样的行为也会发生。警报会出现多次。
    • 好的你能添加你的文件和JSON数据吗,我会在这里告诉你什么问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    相关资源
    最近更新 更多