【发布时间】:2021-10-07 18:11:38
【问题描述】:
我知道这些问题以前在 stackoverflow 中有。但是我找不到这个问题的正确解决方案。
有什么解决方案可以将 <FlatList/> 放在 react-native 中的 <ScrollView></ScrollView> 内吗?
这是我的代码...
<ScrollView
onScroll={(e) => {
onScroll(e);
}}
stickyHeaderIndices={[1]}
contentContainerStyle={{ flexGrow: 1, justifyContent: 'center' }}
style={{ width: '100%' }}
>
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}}>
{isLoading ? (
<DotIndicator color="#4cd137" style={{ marginBottom: 200 }} />
) : (
<FlatList
data={data}
keyExtractor={(item, index) => String(index)}
renderItem={({ item }) => (
<View
style={{
flex: 0,
padding: 5,
}}>
<Card style={styles.card}>
<CardItem header style={styles.cardText}>
<Title style={styles.textSign}>{item.question}</Title>
</CardItem>
<CardItem style={styles.cardText1}>
<Body>
<Paragraph>{item.answer}</Paragraph>
</Body>
</CardItem>
</Card>
</View>
)}
/>
)}
</View>
</ScrollView>
报错如下:
错误 VirtualizedLists 不应该嵌套在plain 中 具有相同方向的滚动视图,因为它可以打破窗口 和其他功能 - 使用另一个 VirtualizedList 支持的容器 而是。
【问题讨论】:
-
发生这种情况是因为在 FlatList 内部也有一个 ScrollView,您可以做的是将您的 FlatList 包装在一个 View 中以分隔 Scroll 的
标签: react-native react-native-android react-native-flatlist react-native-scrollview