ios - 使用 FlatList 可滚动的本机独立视图组件?
问题描述
有没有办法用 FlatList 滚动一个单独的组件?
<View>
<View>
<Text>Some component outside of FlatList</Text>
<Text>Porfile Information Above FlatList</Text>
<Text>How to scroll with flatlist</Text>
</View>
<FlatList
data={DATA}
renderItem={({item}) => (
<View>
<Text>a bunch of list that will scroll</Text>
</View>
)}
/>
<View>
因此,如果您渲染整个组件,在 FlatList 上方会有一个部分,它会一直留在那里,而只有 FlatList 是可滚动的。
你是怎么做到的,所以顶部可以与 FlatList 一起滚动?
解决方案
您可以将组件放在ListHeaderComponent
FlatList 提供的道具中,例如:
<FlatList
data={DATA}
renderItem={({ item }) => (
<View>
<Text>a bunch of list that will scroll</Text>
</View>
)}
ListHeaderComponent={
<View>
<Text>Some component outside of FlatList</Text>
<Text>Porfile Information Above FlatList</Text>
<Text>How to scroll with flatlist</Text>
</View>
}/>
或者把所有东西都放在 aScrollView
中,记得在周围放一个 ViewFlatList
否则FlatList
滚动可能不起作用:
<ScrollView>
<View>
<Text>Some component outside of FlatList</Text>
<Text>Porfile Information Above FlatList</Text>
<Text>How to scroll with flatlist</Text>
</View>
<View>
<FlatList
data={DATA}
renderItem={({item}) => (
<View>
<Text>a bunch of list that will scroll</Text>
</View>
)}/>
</View>
</ScrollView>
推荐阅读
- json - 如何在颤动中更改对地图的响应类型
- python - Python - 将数据保存在已经存在的大 xlsx 文件中的最快方法
- linux - 通过 ssh 跳转主机和目标主机的不同公钥
- r - 如何建立模型来预测缺失值。?
- java - 如何在按钮 ActionListener 中到达外部 int?
- vue.js - 未捕获的 TypeError:Bootstrap 的 JavaScript 需要 jQuery。在使用 vujs2 时,必须在 Bootstrap 的 JavaScript 之前包含 jQuery
- reporting-services - SSRS 中的级联问题
- c++ - 包含在 2 个 gtest 文件中的静态内联关联集合引发读取访问冲突
- google-apps-script - 基于给定参考格式化单元格的更有效方法
- json - @ 符号在这个 [@][] ansible 代码中做了什么?