Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatList inside ScrollView doesn't scroll #19971

Closed
theapache64 opened this issue Jun 29, 2018 · 13 comments
Closed

FlatList inside ScrollView doesn't scroll #19971

theapache64 opened this issue Jun 29, 2018 · 13 comments
Labels
Bug Component: FlatList Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.

Comments

@theapache64
Copy link

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

@pentarex
Copy link
Contributor

see this comment
#1966 (comment)

@yasir-netlinks
Copy link

Hi there, have you found a solution for this problem, I am having the same issue

@theapache64
Copy link
Author

@yasir-netlinks Did you check this

@stale
Copy link

stale bot commented Dec 10, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 10, 2018
@rjalkuino
Copy link

I tried this. The scrollview rendered all items in flatlist and adjusting its size and made the page laggy so i think because of too much data made it not unscrollable.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 15, 2018
@Voliki
Copy link

Voliki commented 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>
   );
}

@ghost
Copy link

ghost commented Jan 15, 2019

I got same issue. Any update?

@sophialittlejohn
Copy link

sophialittlejohn commented Feb 1, 2019

@Voliki thanks, your solution worked for me! Warning: if you have a position: absolute on one of the FlatLists the scroll on android breaks again.

@alexpchin
Copy link

alexpchin commented Feb 12, 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>
   );
}

@alloy
Copy link
Contributor

alloy commented Mar 19, 2019

Hello there 👋 this issue seems to have been inactive for the past few weeks and, moreover, people appear to have working solutions based on this comment. Because of this, it's likely that the issue is not a high priority anymore or it has been solved by OP; for these reasons, we'll close it. But please, if you think this is a different issue that needs to be addressed in React Native itself, please comment below and we can reopen it or please send us a Pull Request with a fix 😊

@christopher-18
Copy link

I faced the similar issue where I had FlatList inside the ScrollView.
It looked something like this:-

<ScrollView>
<View style={{paddingHorizontal: "4.3"}}>
                            <FlatList
                                contentContainerStyle={{ flexGrow: 1, justifyContent: "center" }}
                                ref={(ref) => { this.flatListRef = ref; }}
                                data={this.state.propertiesToShow}
                                extraData={this.state}
                                keyExtractor={(item, index) => index.toString()}
                                renderItem={({ item, index }) => this.renderHotelView(item, index)}
                                ItemSeparatorComponent={this.renderSeparator}
                                getItemLayout={(data, index) => (
                                    {length: moderateScale(200), offset: moderateScale(200) * index, index}
                                  )}
                            />
    </View></ScrollView>

Then I tried setting the scroll of flatlist as false, since I have already enclosed my flatlist to scrollview.
scrollEnabled={Platform.OS == 'ios' ? false : true}

I added the condition since, I was facing this issue only in IPhone 7 Plus.
Note: Doing the otherway round i.e. scroll of scrollview to false, was still giving me the same issue.

@itsgauravjain22
Copy link

Any official update. It's an important aspect of UI when designing. Some workarounds are there but they make the process complicated when there are multiple flatlist inside scrollview. And we want to achieve scrolling depending on where the users touch.
UI should scroll that flatlist when touched inside that flatlist and scroll scrollview when touched inside scrollview.

@Naturalclar
Copy link
Contributor

@itsgauravjain22
there is a nestedScrollEnabled prop in both ScrollView and FlatList will using that prop solve your problem?
https://facebook.github.io/react-native/docs/scrollview#nestedscrollenabled

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: FlatList Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests