Skip to content

Commit

Permalink
- VirtualizedSectionList/SectionList: replace enableVirtualization pr…
Browse files Browse the repository at this point in the history
…op annotation by correct underlying disableVirtualisation of VirtualizedList (#24312)

Summary:
It seems (I used git history to confirm) that FlatList/VirtualizedList have ([since the begining](https://github.com/facebook/react-native/blame/c13f5d48cfe3e7c0f6c6d0b745b50a089d6993ef/Libraries/Lists/VirtualizedList.js#L79)) a `disableVirtualization` prop.
SectionList ([since it's begining](https://github.com/facebook/react-native/blame/abe737fe746406533798f9670e8e243cb18d5634/Libraries/Lists/VirtualizedSectionList.js#L98)) have a `enableVirtualization` prop, but since SectionList is VirtualizedSectionList which use VirtualizedList, this prop probably never did something. This fix just rename the prop properly so it can have an effect on the underlying VirtualizedList when you use a SectionList.

Since props are spread it's kind of working already, but the flow annotation are wrong (so it tells you it won't work/ you can't use it) which sucks.

(NB: I am doing this since I was trying to use a SectionList with react-native-web & server side rendering to get the all list, you can laugh).

[General] [Fixed] - VirtualizedSectionList/SectionList: replace enableVirtualization prop annotation by correct underlying disableVirtualisation of VirtualizedList
Pull Request resolved: #24312

Differential Revision: D14779449

Pulled By: cpojer

fbshipit-source-id: e51e1d639d2bb265b5b286786010d01ffd9d90e0
  • Loading branch information
MoOx authored and facebook-github-bot committed Apr 4, 2019
1 parent 8e37585 commit e980d83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type OptionalProps = {
* unmounts react instances that are outside of the render window. You should only need to disable
* this for debugging purposes.
*/
disableVirtualization: boolean,
disableVirtualization?: ?boolean,
/**
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
Expand Down Expand Up @@ -705,7 +705,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
};

_isVirtualizationDisabled(): boolean {
return this.props.disableVirtualization;
return this.props.disableVirtualization || false;
}

_isNestedWithSameOrientation(): boolean {
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Lists/VirtualizedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ type OptionalProps<SectionT: SectionBase> = {
*/
ItemSeparatorComponent?: ?React.ComponentType<any>,
/**
* Warning: Virtualization can drastically improve memory consumption for long lists, but trashes
* the state of items when they scroll out of the render window, so make sure all relavent data is
* stored outside of the recursive `renderItem` instance tree.
* DEPRECATED: Virtualization provides significant performance and memory optimizations, but fully
* unmounts react instances that are outside of the render window. You should only need to disable
* this for debugging purposes.
*/
enableVirtualization?: ?boolean,
disableVirtualization?: ?boolean,
keyExtractor: (item: Item, index: number) => string,
onEndReached?: ?({distanceFromEnd: number}) => void,
/**
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/SectionListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> {
)}
debug={this.state.debug}
inverted={this.state.inverted}
enableVirtualization={this.state.virtualized}
disableVirtualization={!this.state.virtualized}
onRefresh={() => Alert.alert('onRefresh: nothing to refresh :P')}
onScroll={this._scrollSinkY}
onViewableItemsChanged={this._onViewableItemsChanged}
Expand Down

0 comments on commit e980d83

Please sign in to comment.