简体   繁体   English

在 ScrollView 问题中反应 Native FlatList

[英]React Native FlatList inside ScrollView issue

I have the following issue, FlatList is rendered inside ScrollView, and everything seems to fine except that while FlatList scrolling the buttons in ScrollView are not responding.我有以下问题,FlatList 在 ScrollView 中呈现,一切似乎都很好,除了当 FlatList 滚动时 ScrollView 中的按钮没有响应。

Structure is something like this:结构是这样的:

ScrollView - vertical Button ListView - horizontal ScrollView ScrollView - 垂直 Button ListView - 水平 ScrollView

The issue with using a FlatList inside a ScrollView is that the FlatList will not be able to scroll independently of the ScrollView.在 ScrollView 中使用 FlatList 的问题在于 FlatList 将无法独立于 ScrollView 进行滚动。 This is because the ScrollView will intercept the touch events intended for the FlatList and prevent the FlatList from scrolling.这是因为 ScrollView 会拦截用于 FlatList 的触摸事件并阻止 FlatList 滚动。

On solution is to enable nestedScrollEnabled prop on the ScrollView, and set it to true.解决方案是在 ScrollView 上启用nestedScrollEnabled 属性,并将其设置为 true。 This will allow the FlatList to receive the touch events and scroll independently of the ScrollView.这将允许 FlatList 接收触摸事件并独立于 ScrollView 滚动。

<FlatList nestedScrollEnabled />

Another You can also try this solution另一个你也可以试试这个解决方案

<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<View>
    <Text>Some fixed content</Text>
  </View>
  <FlatList
    data={data}
    keyExtractor={item => item.id}
    renderItem={({ item }) => <Text>{item.name}</Text>}
  />
</ScrollView>

Or you can try this solution of using map instead of flatlist或者您可以尝试使用 map 而不是 flatlist 的解决方案

<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
    <View>
      {data.map(item => (
        <View key={item.id}>
          <Text>{item.name}</Text>
        </View>
      ))}
    </View>
    </ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM