facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.97k stars 24.31k forks source link

[iOS, Android] SectionList's creates new ListHeaderComponent when sections property receives empty array. #29490

Closed DodoTheDeveloper closed 1 year ago

DodoTheDeveloper commented 4 years ago

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

The SectionList component creates the component for the ListHeaderComponent new, when an empty array is supplied for the sections property after it has previously been filed with data. Therefore the state of the ListHeaderComponent resets to it's initial state. When the data of the section property is replaced by a non empty array this does not happen. Then the component for the ListHeaderComponent and it's state remains intact.

I've tried to reproduce this with a FlatList but there the ListHeaderComponent did not 'reset' which was the expected behavior.

React Native version:

System: OS: macOS 10.15.6 CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz Memory: 636.88 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.18.1 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.4 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.8.4 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 23, 25, 26, 27, 28, 29 Build Tools: 23.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.3, 28.0.2, 28.0.3, 29.0.3 System Images: android-29 | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 11.6/11E708 - /usr/bin/xcodebuild Languages: Java: 1.8.0_222 - /usr/bin/javac Python: 2.7.17 - /usr/local/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.1 => 0.63.1 npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Use a SectionList and provide a component with an internal state for the ListHeaderComponent.
  2. Provide data to the SectionList.
  3. Manipulate the internal state of the component used as the ListHeaderComponent.
  4. Use an empty array [] for the section property.
  5. The internal state if the ListHeaderComponent is resetted, due to replacing the component with a new one.

Expected Results

The ListHeaderComponent should stay the same event after changing the section properties data with [].

Snack, code example, screenshot, or link to a repository:

Set the snack to iOS or Android. When set to Web this issue will not be reproducable. SectionList: https://snack.expo.io/qfg5fB5qx FlatList (works as expected): https://snack.expo.io/Oh8HToO3U

DodoTheDeveloper commented 4 years ago

Potential duplication of #28919

stale[bot] commented 3 years ago

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 a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

jehartzog commented 3 years ago

Discussion. This is still an active issue, but likely a duplicate of #28919. I maybe isolated part of the cause for the issue, but haven't yet actually found a fix.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 7 days with no activity.