【问题标题】:Warning while using ListItem, FlatList inside ScrollView在 ScrollView 中使用 ListItem、FlatList 时出现警告
【发布时间】:2020-07-03 05:12:27
【问题描述】:

当我尝试在 View 中使用 Flatlist 时收到此警告,但出现同样的错误:

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.

我在里面使用 FlatList 的组件是:

class About extends Component
{
    constructor(props)
    {
        super(props);
        this.state = {
            leaders: LEADERS
        };
    }

    render(){
        const renderLeaders = ({item,index}) => {
            return(
                <ListItem 
                    key = {index}
                    title = {item.name}
                    subtitle = {item.description}
                    hideChevron = {true}
                    leftAvatar = {{ source: require('./images/alberto.png') }}
                />
            );
        };

        return(
            <ScrollView>
                <History />
                <Card title = "Corporate Leadership">
                    <FlatList 
                        data = {this.state.leaders}
                        renderItem = {renderLeaders}
                        keyExtractor = {item => item.id.toString()}
                    />
                </Card>          
            </ScrollView>
        );
    }
}

我可以在这里使用leader 代替item 吗?我尝试使用它,但出现错误。

【问题讨论】:

    标签: react-native scrollview react-native-android react-native-flatlist


    【解决方案1】:

    破解此问题的一种方法是使用 react-native-gesture-handler flatlist 如果您绝对需要嵌套滚动条,它会接管您的育儿 ScrollView,至少当我遇到同样的问题时这对我有用。

    根据第二部分,无需深入研究什么是什么,请尝试阅读此https://www.barrymichaeldoyle.com/destructuring/#:~:text=Renaming%20Variables%20while%20Destructuring&text=In%20order%20to%20rename%20a,rename%20the%20destructured%20variable%20to 或谷歌任何其他关于“解构重命名”的理论 如果您绝对需要重命名“项目”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      相关资源
      最近更新 更多