Skip to content

RN 0.44: On Android, ListView Section Header disappears, when the number of elements in the dataSource changes #14189

@joeldalley

Description

@joeldalley

Description

We're using RN 0.44 in combination with React 16.0.0-alpha.6, so that we can have sticky section headers on Android. It works! However, when the number of rows in the dataSource changes, the section header mysteriously disappears.

Unfortunately, the versions of React and RN used on the Snack website are older, but I still created a sample app that, if the site were to feature the upgraded versions of React and RN, should reproduce the problem: https://snack.expo.io/SkohIU4WZ

What we expect here is for the section header to not only stick on Android, but also not to disappear, should the number of rows in its dataSource change. (iOS works perfectly, for what that's worth.)

Reproduction Steps and Sample Code

List all the steps required to reproduce the issue you're reporting. These steps should be clear and concise.

<ListView
        dataSource={dataSource}
        enableEmptySections={true}
        removeClippedSubviews={false}
        renderSectionHeader={() => {
          return (
            <View style={{height: 100, width, backgroundColor: 'red'}}>
              <Text>TEST SECTION</Text>
            </View>
          );
        }}
        renderRow={row => {
          return <View style={{height: 40, width, backgroundColor: 'white'}}><Text>{row.name}</Text></View>;
        }}
        renderHeader={() => {
          return (
            <View style={{height: 50, width, backgroundColor: 'yellow'}}>
              <Text>THIS IS THE LISTVIEW HEADER</Text>
            </View>
          );
        }}
        stickySectionHeadersEnabled={true}
      />

Solution

I've combed through react-native/Libraries/Lists/ListView.js, and I'm unable to find the cause. It appears we always enter the if case on line 411: https://github.com/facebook/react-native/blob/master/Libraries/Lists/ListView/ListView.js#L410

And we always end up having a section header element, which gets pushed onto the bodyComponents array. It's just that it visually disappears, when the number of rows in dataSource changes.

Unfortunately, I don't know the root cause of the bug. :-(

Additional Information

  • React Native version: 0.44.0
  • Platform: Android
  • Development Operating System: MacOS
  • Dev tools: Android API levels 19, 22 and 23 have been tested

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions