简体   繁体   English

如何在 React Native 中处理多个 FlatList

[英]How to handle multiple FlatLists in React Native

在此处输入图像描述

These red marks areas are 3 FlatLists .这些红色标记区域是 3 个FlatLists The first and Second are horizontally scrolling FlatLists while the last FlatList is scrolling vertically.My problem arise when scrolling the last FlatList .第一个和第二个是水平滚动的FlatLists ,而最后一个FlatList是垂直滚动的。我的问题出现在滚动最后一个FlatList时。 It not going to the bottom it stays in the same position but scrolls (Like it has a fixed height).它不会到达底部,而是保持在相同的 position 中,但会滚动(就像它具有固定的高度一样)。 How to get rid of such thing.如何摆脱这样的事情。 I'm trying a way to scroll the whole page.我正在尝试一种滚动整个页面的方法。 I have attached a GIF too to make sense.我也附上了一个 GIF 以说明问题。 Thanks.谢谢。

<SafeAreaView style={{flex:1}}/>
//Top FLatList
<View>
  <FlatList
     showsHorizontalScrollIndicator={false}
     horizontal
     data={articles}
     ...
  />
 </View>
//Middle FLatList
<View>
  <FlatList
     showsHorizontalScrollIndicator={false}
     horizontal
     data={options}
     ...
  />
 </View>
 //Bottom FLatList
 <View>
  <FlatList
     data={articles}
     ...
  />
 </View>
</SafeAreaView>

在此处输入图像描述

The problem is typically caused by the custome style to the bottom tab.该问题通常是由底部选项卡的自定义样式引起的。 You may fix it by adding the footer component prop to the last flatList.您可以通过将 footer 组件属性添加到最后一个 flatList 来修复它。

//The total height including the bottom tab height and the space
   let bottomMargin = 110

 <SafeAreaView style={{flex:1}}/>
//Top FLatList
<View>
  <FlatList
     showsHorizontalScrollIndicator={false}
     horizontal
     data={articles}
     ...
  />
 </View>
//Middle FLatList
<View>
  <FlatList
     showsHorizontalScrollIndicator={false}
     horizontal
     data={options}
     ...
  />
 </View>
 //Bottom FLatList
 <View>
  <FlatList
     data={articles}
     ListFooterComponent={()=>(
      <FooterComponent/>
     )}
     ...
  />
 </View>
</SafeAreaView>


  const FooterComponent = () => {

    return (
        <View style={{marginBottom: bottomMargin}} />
    )
  }

To scroll the whole page滚动整个页面

To scroll the entire page, pass the above code from the third flatlist as the Header component to the third flatlist like the following:要滚动整个页面,请将上述代码作为 Header 组件从第三个平面列表传递到第三个平面列表,如下所示:

 <SafeAreaView style={{flex:1}}/>
//Top FLatList

 //Bottom FLatList
 <View>
  <FlatList
     data={articles}
     ListHeaderComponent={()=>(
      <HeaderComponent/>
     )}
     ...
  />
 </View>
</SafeAreaView>


  const HeaderComponent= () => {
    return (
      <View>
        <FlatList
         showsHorizontalScrollIndicator={false}
         horizontal
         data={articles}
          />

         <FlatList
         showsHorizontalScrollIndicator={false}
         horizontal
         data={options}
         />
     </View>
    )
  }

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

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