我在ScrollView里有4个FlatListmaxHeight设置为200.

<ScrollView>
  <FlatList/>
  <FlatList/>
  <FlatList/>
  <FlatList/>
</ScrollView>

当我try 滚动FlatList时,它不会滚动,而是滚动ScrollView.如何解决此问题?

Full Source Code

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>}
      />
    );
  }
}

snack.expo link

推荐答案

我们可以为 children 平面列表/滚动视图组件使用内置的nestedscrollenabledprops .

<FlatList nestedScrollEnabled />

这仅适用于Android(iOS默认支持嵌套滚动).

React-native相关问答推荐

expo 日历应用因权限问题而崩溃

无法设置文本输入参考

如何在 React Navigation 5 中将父函数传递给子屏幕?

如何获取 iOS 版本?

在 React Native Paper 中更改 TextInput 的文本 colored颜色

如何通过 node ID 获取真实元素?

NativeBase + Exponent Header

如何使用功能组件向 ref 公开功能?

自定义标签栏react Navigation 5

如何在 Text ReactNative 中包含 TouchableOpacity

加载远程图像失败后加载本map像

是否需要使用 StyleSheet.create?

react-navigation模式高度

如何在react-native中显示toast消息

INSTALL_FAILED_INSUFFICIENT_STORAGE 运行 npm run android 命令时出错

React-native google 登录给开发人员错误

降级 react-native 的适当机制

React 本机矢量图标在当前版本 0.60 上不起作用

react-native:0.41 app.json

未找到 React/RCTBridgeDelegate.h' 文件