[Solved]-"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."


This warning is related to the use of nested VirtualizedList components inside plain ScrollView components with the same orientation. The warning suggests that this configuration can cause issues with windowing and other functionalities in React Native.

Warning: VirtualizedLists Nested Inside Plain ScrollViews

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:

  1. Avoid Nesting VirtualizedLists Inside ScrollView: Refactor your component structure to avoid nesting `VirtualizedList` components inside a plain `ScrollView` with the same orientation. This nesting can lead to performance issues and unexpected behavior.
// Example structure to avoid

    
    


// Refactored structure

    
    
  1. Use Another VirtualizedList-Backed Container: Instead of using a plain `ScrollView` to wrap your `VirtualizedList` components, consider using another `VirtualizedList`-backed container such as `FlatList` or `SectionList`. These components are optimized for rendering large lists efficiently.
// 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.

Above code provides example on resolving the warning about nesting VirtualizedList components inside plain ScrollView components in React Native. The solution involves restructuring your components and using dedicated list components like FlatList or SectionList for improved performance.

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>