From b3101457a6de28d20dc96727d2286fcdf84d130a Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 17 Mar 2021 12:46:06 -0700 Subject: [PATCH] Remove windowSize defaultProps Summary: Changelog: [Internal][Changed] -Remove windowSize from defaultProps as part of larger effort to remove defaultProps from VirtualizedList Reviewed By: nadiia Differential Revision: D26969589 fbshipit-source-id: da6215ee3876c8f186d59f91ef6fd94396366119 --- Libraries/Lists/VirtualizedList.js | 13 +++++++------ .../__snapshots__/FlatList-test.js.snap | 7 ------- .../__snapshots__/SectionList-test.js.snap | 5 ----- .../__snapshots__/VirtualizedList-test.js.snap | 17 ----------------- .../VirtualizedSectionList-test.js.snap | 11 ----------- 5 files changed, 7 insertions(+), 46 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 866333845a..7baa055b3d 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -290,7 +290,7 @@ type OptionalProps = {| * this number will reduce memory consumption and may improve performance, but will increase the * chance that fast scrolling may reveal momentary blank areas of unrendered content. */ - windowSize: number, + windowSize?: ?number, /** * The legacy implementation is no longer supported. */ @@ -306,7 +306,6 @@ type Props = {| type DefaultProps = {| keyExtractor: (item: Item, index: number) => string, updateCellsBatchingPeriod: number, - windowSize: number, |}; let _usedIndexForKey = false; @@ -337,6 +336,10 @@ function scrollEventThrottleOrDefault(scrollEventThrottle: ?number) { return scrollEventThrottle ?? 50; } +function windowSizeOrDefault(windowSize: ?number) { + return windowSize ?? 21; +} + /** * Base implementation for the more convenient [``](https://reactnative.dev/docs/flatlist.html) * and [``](https://reactnative.dev/docs/sectionlist.html) components, which are also better @@ -593,7 +596,6 @@ class VirtualizedList extends React.PureComponent { return String(index); }, updateCellsBatchingPeriod: 50, - windowSize: 21, // multiples of length }; _getCellKey(): string { @@ -691,9 +693,8 @@ class VirtualizedList extends React.PureComponent { 'Components based on VirtualizedList must be wrapped with Animated.createAnimatedComponent ' + 'to support native onScroll events with useNativeDriver', ); - invariant( - props.windowSize > 0, + windowSizeOrDefault(props.windowSize) > 0, 'VirtualizedList: The windowSize prop must be present and set to a value greater than 0.', ); @@ -1753,7 +1754,7 @@ class VirtualizedList extends React.PureComponent { this.props.data, this.props.getItemCount, maxToRenderPerBatchOrDefault(this.props.maxToRenderPerBatch), - this.props.windowSize, + windowSizeOrDefault(this.props.windowSize), state, this._getFrameMetricsApprox, this._scrollMetrics, diff --git a/Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap b/Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap index f4411ebd58..f518ae0c5d 100644 --- a/Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap +++ b/Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap @@ -50,7 +50,6 @@ exports[`FlatList renders all the bells and whistles 1`] = ` stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} viewabilityConfigCallbackPairs={Array []} - windowSize={21} > @@ -140,7 +139,6 @@ exports[`FlatList renders empty list 1`] = ` stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} viewabilityConfigCallbackPairs={Array []} - windowSize={21} > @@ -164,7 +162,6 @@ exports[`FlatList renders null list 1`] = ` stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} viewabilityConfigCallbackPairs={Array []} - windowSize={21} > @@ -201,7 +198,6 @@ exports[`FlatList renders simple list (multiple columns) 1`] = ` stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} viewabilityConfigCallbackPairs={Array []} - windowSize={21} > @@ -412,7 +408,6 @@ exports[`SectionList renders empty list 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} > diff --git a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap index a59c9d4e8b..129cb4cd6e 100644 --- a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap +++ b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap @@ -63,7 +63,6 @@ exports[`VirtualizedList forwards correct stickyHeaderIndices when all in initia ] } updateCellsBatchingPeriod={50} - windowSize={21} > @@ -1204,7 +1195,6 @@ exports[`VirtualizedList renders empty list 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} > @@ -1230,7 +1220,6 @@ exports[`VirtualizedList renders empty list with empty component 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} > @@ -1338,7 +1325,6 @@ exports[`VirtualizedList renders simple list 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} > @@ -871,7 +864,6 @@ exports[`VirtualizedSectionList renders empty list 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} > @@ -897,7 +889,6 @@ exports[`VirtualizedSectionList renders empty list with empty component 1`] = ` scrollEventThrottle={50} stickyHeaderIndices={Array []} updateCellsBatchingPeriod={50} - windowSize={21} >