If you receive the warning "VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing and other functionality - use another VirtualizedList-backed container instead," in your React Native application, it indicates a potential issue with the nested structure of your list components. Here's how you can resolve it:
// Example structure to avoid
// Refactored structure
// Example usage of FlatList
}
keyExtractor={(item) => item.id.toString()}
/>
By using `FlatList` or `SectionList`, you benefit from optimized rendering and scrolling behavior for large datasets, without the need for manual handling of windowing issues.
In my case, the issue was occurring due to the nesting of ScrollView components.
Try replacing some of the ScrollView instances in the children components with React.Fragment.
If the ScrollView is vertical, change the FlatList to horizontal as shown below:
<ScrollView>
<FlatList
horizontal
data={lenders}
keyExtractor={(_, index) => index}
renderItem={(item) => {
return <Text>item</Text>
}}
/>
</ScrollView>
I resolved this issue by setting scrollEnabled={false}
in the internal VirtualizedLists. This prevents the list from being scrollable via touch interactions. By default, it is set to scrollEnabled={true}
, which results in two scrollable lists in the same orientation. However, if you have two lists with different orientations, this issue doesn't occur.
<ScrollView>
<ListView
scrollEnabled={false} />
</ScrollView>
To avoid using FlatList with the same orientation, consider restructuring your code as follows:
<ScrollView contentContainerStyle={style}>
Other components
{
data.map((item) => <Somthing item={item}/>)
}
Other components
</ScrollView>