Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlatList inside ScrollView doesn't scroll

Tags:

react-native

I've 4 FlatLists with maxHeight set to 200 inside a ScrollView.

<ScrollView>   <FlatList/>   <FlatList/>   <FlatList/>   <FlatList/> </ScrollView> 

and when I try to scroll a FlatList, it doesn't scroll but the ScrollView scrolls. How do I fix this issue ?

Full Source Code

import { Component, default as React } from 'react'; import { FlatList, ScrollView, Text } from 'react-native';  export  class LabScreen extends Component<{}> {   render() {     return (       <ScrollView>         {this.renderFlatList('red')}         {this.renderFlatList('green')}         {this.renderFlatList('purple')}         {this.renderFlatList('pink')}       </ScrollView>     );   }    getRandomData = () => {     return new Array(100).fill('').map((item, index) => {       return { title: 'Title ' + (index + 1) };     });   };    renderFlatList(color: string) {     return (       <FlatList         data={this.getRandomData()}         backgroundColor={color}         maxHeight={200}         marginBottom={50}         keyExtractor={(item, index) => index.toString()}         renderItem={({ item }) => <Text>{item.title}</Text>}       />     );   } } 

snack.expo link

like image 489
theapache64 Avatar asked Jun 29 '18 09:06

theapache64


People also ask

Can FlatList be inside ScrollView?

Under the hood, FlatList uses the ScrollView component to render scrollable elements. However, unlike generic ScrollView, FlatList displays data lazily to save memory and processing time.

How do I fix Virtualizedlists should never be nested inside plain Scrollviews warning?

The fix to this warning is more straightforward than you think: get rid of the ScrollView, and places all the components that surround the FlatList inside ListFooterComponent and ListHeaderComponent. ); }; Both props only accept one component, so we wrapped the components in the ListHeaderComponent with Fragments.

Which is better FlatList or ScrollView?

ScrollView renders all its react child components at once, but this has a performance downside. FlatList renders items lazily, when they are about to appear, and removes items that scroll way off-screen to save memory and processing time.

How do I turn off FlatList scrolling?

To enable or disable scrolling on FlatList with React Native, we can set the scrollEnabled prop. to set the scrollEnabled prop to false to disable scrolling on the FlatList.


1 Answers

We can use the built-in nestedscrollenabled prop for the children FlatList/ScrollView components.

<FlatList nestedScrollEnabled /> 

This is only required for Android (Nested scrolling is supported by default on iOS).

like image 135
rnk Avatar answered Sep 30 '22 13:09

rnk