React Native:当它被 ScrollView 包围时如何制作一个粘性的 SectionList header
React Native : How to make a sticky SectionList header when it is surrounded by ScrollView
我知道 SectionList
默认情况下将其 header 粘贴在 iOS 中。
但是,当SectionList
被ScrollView
包围时,就不再粘header了。
我的基本结构是这样的
<ScrollView>
<Text style={styles.paragraph}>...</Text>
<SectionList />
</ScrollView>
( 实时测试代码是 here )
如果我删除 ScrollView
和 Text
,那么粘贴 header 效果很好。但我想在 SectionList
开始之前显示文本(或 Image
、View
等等)。
有办法解决吗?
谢谢。
您可以使用ListHeaderComponent
Rendered at the very beginning of the list. Can be a React Component
Class, a render function, or a rendered element.
<SectionList
ListHeaderComponent={<View><Text>Header</Text></View>}
/>
我知道 SectionList
默认情况下将其 header 粘贴在 iOS 中。
但是,当SectionList
被ScrollView
包围时,就不再粘header了。
我的基本结构是这样的
<ScrollView>
<Text style={styles.paragraph}>...</Text>
<SectionList />
</ScrollView>
( 实时测试代码是 here )
如果我删除 ScrollView
和 Text
,那么粘贴 header 效果很好。但我想在 SectionList
开始之前显示文本(或 Image
、View
等等)。
有办法解决吗?
谢谢。
您可以使用ListHeaderComponent
Rendered at the very beginning of the list. Can be a React Component Class, a render function, or a rendered element.
<SectionList
ListHeaderComponent={<View><Text>Header</Text></View>}
/>