我有 4 FlatList
s 与 maxHeight
设置为 200
在 ScrollView
内
<ScrollView>
<FlatList/>
<FlatList/>
<FlatList/>
<FlatList/>
</ScrollView>
当我尝试滚动 FlatList
时,它不会滚动,但 ScrollView
滚动。我该如何解决这个问题?
完整的源代码
import { Component, default as React } from 'react';
import { FlatList, ScrollView, Text } from 'react-native';
export class LabScreen extends Component<{}> {
render() {
return (
<ScrollView>
{this.renderFlatList('red')}
{this.renderFlatList('green')}
{this.renderFlatList('purple')}
{this.renderFlatList('pink')}
</ScrollView>
);
}
getRandomData = () => {
return new Array(100).fill('').map((item, index) => {
return { title: 'Title ' + (index + 1) };
});
};
renderFlatList(color: string) {
return (
<FlatList
data={this.getRandomData()}
backgroundColor={color}
maxHeight={200}
marginBottom={50}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => <Text>{item.title}</Text>}
/>
);
}
}
原文由 theapache64 发布,翻译遵循 CC BY-SA 4.0 许可协议
我们可以为子 FlatList/ScrollView 组件使用内置的 nestedscrollenabled 属性。
这仅对 Android 是必需的(iOS 默认支持嵌套滚动)。