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.

Listview doesn't scroll when inside a scrollview

See original GitHub issue

Noticed this after upgrading to 0.7.1 from 0.6.

Below is a simple example to reproduce. I noticed it when upgrading my app that has three separate list views inside a scrolling container. List views are set to show all rows, as they’re not expected to be very long. But all three are large enough to go off page.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var {
  AppRegistry,
  Component,
  ListView,
  StyleSheet,
  Text,
  ScrollView,
  View,
} = React;

class TestScrollView extends Component {
  constructor(props) {
    super(props);
    let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(["ALABAMA", "ALASKA", "AMERICAN SAMOA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", "DISTRICT OF COLUMBIA", "FEDERATED STATES OF MICRONESIA", "FLORIDA", "GEORGIA", "GUAM GU", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARSHALL ISLANDS", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW HAMPSHIRE", "NEW JERSEY", "NEW MEXICO", "NEW YORK", "NORTH CAROLINA", "NORTH DAKOTA", "NORTHERN MARIANA ISLANDS", "OHIO", "OKLAHOMA", "OREGON", "PALAU", "PENNSYLVANIA", "PUERTO RICO", "RHODE ISLAND", "SOUTH CAROLINA", "SOUTH DAKOTA", "TENNESSEE", "TEXAS", "UTAH", "VERMONT", "VIRGIN ISLANDS", "VIRGINIA", "WASHINGTON", "WEST VIRGINIA", "WISCONSIN", "WYOMING"])
    };
  }
  render() {
    return (
      <View style={styles.container}>
        <ScrollView>
          <ListView
            dataSource={this.state.dataSource}
            renderRow={(rowData) => <Text>{rowData}</Text>}
          />
        </ScrollView>
      </View>
    );
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

AppRegistry.registerComponent('TestScrollView', () => TestScrollView);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

36reactions
sadafk831commented, Mar 8, 2017

I had the same issue as I had the following component structure.

<View>
<ScrollView>
  <View>
      <Text/>
      <ListView />
  </View>
  <View> 
      <Text/>
      <ListView />
  </View>
  <View>
      <Text/>
      <ListView />
  </View>
</ScrollView>
</View>

As wrapping the ListView inside the ScrollView the parent scroll action dominates the child scroll action which leads only ScrollView to scroll. I resolved this issue by adding the following code as a prop to the parent View which wraps the ScrollView

onStartShouldSetResponderCapture={() => {
    this.setState({ enableScrollViewScroll: true });
}}

Add scrollEnabled={this.state.enableScrollViewScroll} prop to ScrollView

And Finally add following to the View which wraps the ListView( immediate parent )

onStartShouldSetResponderCapture={() => {
     this.setState({ enableScrollViewScroll: false });
     if (this.refs.myList.scrollProperties.offset === 0 && this.state.enableScrollViewScroll === false) {
       this.setState({ enableScrollViewScroll: true });
     }
 }}

this works very well on IOS and Android both, scrolls the ListView if the touch is on List and else it scrolls the ScrollView

8reactions
Angelk90commented, Jan 10, 2018

@sadafk831 : Could you post a complete code example? I get lost somewhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ListView inside ScrollView is not scrolling on Android
I found a solution that works excellently and can scroll the ListView without problems: ListView lv = (ListView)findViewById(R.id.
Read more >
[Android] Nested ListView doesn't scroll inner ... - GitHub
When nesting ListViews inside of one another, folks typically set the inner ListView.physics to NeverScrollableScrollPhysics, making only the ...
Read more >
How to embed List in ScrollView using SwiftUI
Hi! I want to allow user to scroll a long list of items iOS app, so I am trying to embbed a List...
Read more >
listview inside nested scrollview doesn't show the list item ...
OS: macOS Sierra Studio Version: Studio 2.3 RC1 ----- Issue: listview inside nested scrollview doesn't show the list item content. Solution:
Read more >
Xamarin Forms Listview in Scrollview doesn't scroll - MSDN
Try to use the Listview inside a Stacklayout and use Listview's header and footer for additional views. How can i make my screen...
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