Después de actualizar a react-native 0.61, recibo muchas advertencias como esa:
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead. ¿Cuál es el otro VirtualizedList-backed container que debo usar y por qué ahora se recomienda no usarlo así?
Si alguien todavía está buscando una sugerencia para el problema que @Ponleu y @David Schilling han descrito aquí (con respecto al contenido que va por encima de FlatList), entonces este es el enfoque que tomé:
<SafeAreaView style={{flex: 1}}> <FlatList data={data} ListHeaderComponent={ContentThatGoesAboveTheFlatList} ListFooterComponent={ContentThatGoesBelowTheFlatList} /></SafeAreaView>Puede leer más sobre esto aquí: https://facebook.github.io/react-native/docs/flatlist#listheadercomponent
Espero que ayude a alguien. :)
Si esta es la solucion con SafeAreaView
En caso de que esto ayude a alguien, así es como solucioné el error en mi caso.
Tenía una FlatList anidada dentro de ScrollView :
render() { return ( <ScrollView> <Text>{'My Title'}</Text> <FlatList data={this.state.myData} renderItem={({ item }) => { return <p>{item.name}</p>; }} /> {this.state.loading && <Text>{'Loading...'}</Text>} </ScrollView> ); } y me deshice de ScrollView usando FlatList para representar todo lo que necesitaba, lo que eliminó la advertencia:
render() { const getHeader = () => { return <Text>{'My Title'}</Text>; }; const getFooter = () => { if (this.state.loading) { return null; } return <Text>{'Loading...'}</Text>; }; return ( <FlatList data={this.state.myData} renderItem={({ item }) => { return <p>{item.name}</p>; }} ListHeaderComponent={getHeader} ListFooterComponent={getFooter} /> ); }La mejor manera es deshabilitar esa advertencia porque, a veces Flatlist debe estar en ScrollView .
YellowBox ahora se cambia y reemplaza con LogBox
FUNCIONAL
import React, { useEffect } from 'react'; import { LogBox } from 'react-native'; useEffect(() => { LogBox.ignoreLogs(['VirtualizedLists should never be nested']); }, [])BASADO EN CLASE
import React from 'react'; import { LogBox } from 'react-native'; componentDidMount() { LogBox.ignoreLogs(['VirtualizedLists should never be nested']); }FUNCIONAL
import React, { useEffect } from 'react'; import { YellowBox } from 'react-native'; useEffect(() => { YellowBox.ignoreWarnings(['VirtualizedLists should never be nested']); }, [])BASADO EN CLASE
import React from 'react'; import { YellowBox } from 'react-native'; componentDidMount() { YellowBox.ignoreWarnings(['VirtualizedLists should never be nested']); }