-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
BugComponent: FlatListIssue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.This issue can be reproduced in Snack or an attached project.Priority: LowStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Description
🐛 Bug Report
When disabling pull-to-refresh in a FlatList
by setting onRefresh
to undefined
every item in the list gets unmounted and recreated.
I looked into why this would be happening and it appears to be because of this code in ScrollView
:
react-native/Libraries/Components/ScrollView/ScrollView.js
Lines 1082 to 1120 in f741d33
const refreshControl = this.props.refreshControl; | |
if (refreshControl) { | |
if (Platform.OS === 'ios') { | |
// On iOS the RefreshControl is a child of the ScrollView. | |
// tvOS lacks native support for RefreshControl, so don't include it in that case | |
return ( | |
// $FlowFixMe | |
<ScrollViewClass {...props} ref={this._setScrollViewRef}> | |
{Platform.isTV ? null : refreshControl} | |
{contentContainer} | |
</ScrollViewClass> | |
); | |
} else if (Platform.OS === 'android') { | |
// On Android wrap the ScrollView with a AndroidSwipeRefreshLayout. | |
// Since the ScrollView is wrapped add the style props to the | |
// AndroidSwipeRefreshLayout and use flex: 1 for the ScrollView. | |
// Note: we should only apply props.style on the wrapper | |
// however, the ScrollView still needs the baseStyle to be scrollable | |
return React.cloneElement( | |
refreshControl, | |
{style: props.style}, | |
<ScrollViewClass | |
{...props} | |
style={baseStyle} | |
// $FlowFixMe | |
ref={this._setScrollViewRef}> | |
{contentContainer} | |
</ScrollViewClass>, | |
); | |
} | |
} | |
return ( | |
// $FlowFixMe | |
<ScrollViewClass {...props} ref={this._setScrollViewRef}> | |
{contentContainer} | |
</ScrollViewClass> | |
); |
To Reproduce
- Add a
FlatList
with some data andonRefresh
andrefreshing
set to valid values - Change
onRefresh
andrefreshing
toundefined
Expected Behavior
The item components already rendered should be reused
Code Example
https://snack.expo.io/@maxschmeling/disrespectful-toffee
Environment
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 8.02 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.3.0 - ~/.nvm/versions/node/v11.3.0/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v11.3.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
IDEs:
Android Studio: 3.1 AI-173.4907809
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.3 => 16.8.4
react-native: ^0.59.0 => 0.59.0
npmGlobalPackages:
react-native-git-upgrade: 0.2.7
Metadata
Metadata
Assignees
Labels
BugComponent: FlatListIssue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.This issue can be reproduced in Snack or an attached project.Priority: LowStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.