【问题标题】:Why does ScrollView throw me a warning message?为什么 ScrollView 会向我抛出警告消息?
【发布时间】:2020-03-11 13:47:46
【问题描述】:

我在使用 React Native ScrollView 时遇到问题,它会向我抛出一个危险信息 它应该与设计相同,但我无法想象它

消息: WARNING-VirtualizedLists 永远不应该嵌套在具有相同方向的普通 ScrollView 中,而是使用另一个 VirtualizedLists-Backed conintainer

设计:

代码:

  <View>
                    <SearchBar
                        term={term}
                        onTermChange={setTerm}
                        onTermSubmit={() => searchApi(term)}
                    />
                    {errorMessage ? <Text>{errorMessage}</Text> : null}

                    <ScrollView>
                        <ResultList
                            title=''
                            results={results}
                        />
                    </ScrollView>
                </View>

【问题讨论】:

  • 可能是因为 ResultList 使用了嵌入的 ScrollView?因此,您无需将其包装到另一个中。 (只是说,我对 react native 了解不多)
  • @user12979570 你的ResultList 组件很可能是FlatList
  • @HendEl-Sahli ResultList 有 FlatList 所以¿我删除了 scrollView 吗?
  • @MatPag np,我会试试你的解决方案
  • @NicolásCabeza 是的,看看我的答案:) ...并尝试应用它

标签: javascript android react-native scrollview


【解决方案1】:

问题在这里:

<ScrollView>
  <ResultList title="" results={results} />
</ScrollView>

如果您的ScrollView 中没有任何可滚动内容...那么您可以删除包裹您的&lt;ResultList /&gt;ScrollView,然后您就可以开始了...

但如果您确实有其他 scollable-content -> 然后尝试将它们包含为您的 FlatListListHeaderComponentListFooterComponent ...

【讨论】:

    猜你喜欢
    • 2015-05-07
    • 1970-01-01
    • 2014-09-25
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多