question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlatList inside ScrollView doesn't scroll

See original GitHub issue

Environment

Environment:
  OS: Linux 4.15
  Node: 8.11.2
  Yarn: 1.7.0
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: N/A
  Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: 0.55.4 => 0.55.4

Description

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>}
      />
    );
  }
}

Reproducible Demo

snack.expo link

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

25reactions
Volikicommented, Dec 20, 2018

Hi, this solution worked for me.

this.state = {
   enableScrollViewScroll: true,
};

onEnableScroll= (value: boolean) => {
    this.setState({
      enableScrollViewScroll: value,
    });
  };

render() {
   return (
      <View>
         ...
        <ScrollView
           scrollEnabled={this.state.enableScrollViewScroll}
        >
           ...
           <FlatList
              ...
              onTouchStart={() => {
                 this.onEnableScroll( false );
              }}
              onMomentumScrollEnd={() => {
                 this.onEnableScroll( true );
              }}
            />
            ...
         </ScrollView>
         ...
     </View>
   );
}
9reactions
alexpchincommented, Feb 13, 2019

Does this mean that the Flatlist should be able to scroll if the ScrollView scrollEnabled is hardcoded as false? I can’t seem to get this to work still… i.e

render() {
   return (
      <View style={{flex: 1}}>
         ...
        <ScrollView
           style={{flexGrow: 1}}  
           scrollEnabled={false}
        >
           ...
           <FlatList
              ...
              // DOESN'T SCROLL...
            />
            ...
         </ScrollView>
         ...
     </View>
   );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

FlatList inside ScrollView doesn't scroll - Stack Overflow
The issue is that the parent component is the only one registering the scroll event. The solution is to contextually decide which component ......
Read more >
How to embed a Flatlist inside a ScrollView?? : r/reactnative
You're not supposed to put a FlatList in a ScrollView. If you have a fixed height for your FlatList, it's okay, but Android...
Read more >
How to Fix 'VirtualizedLists should never be nested inside ...
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead. While this ...
Read more >
[Solved]-FlatList inside ScrollView doesn't scroll-React Native
Coding example for the question FlatList inside ScrollView doesn't scroll-React Native.
Read more >
React-native – FlatList inside ScrollView doesn't scroll
I've 4 FlatList s with maxHeight set to 200 inside a ScrollView . ... and when I try to scroll a FlatList ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found