Skip to content

Commit 69030a4

Browse files
Luna Weifacebook-github-bot
authored andcommitted
Remove maxToRenderPerBatch defaultProps
Summary: Changelog: [Internal][Changed] -Remove maxToRenderPerBatch from defaultProps as part of larger effort to remove defaultProps from VirtualizedList Reviewed By: nadiia Differential Revision: D26969582 fbshipit-source-id: 64a07aae11f0403b01c01896b4f83565da6ecf43
1 parent 34d189a commit 69030a4

File tree

5 files changed

+11
-48
lines changed

5 files changed

+11
-48
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ type OptionalProps = {|
206206
* once, the better the fill rate, but responsiveness may suffer because rendering content may
207207
* interfere with responding to button taps or other interactions.
208208
*/
209-
maxToRenderPerBatch: number,
209+
maxToRenderPerBatch?: ?number,
210210
/**
211211
* Called once when the scroll position gets within `onEndReachedThreshold` of the rendered
212212
* content.
@@ -305,7 +305,6 @@ type Props = {|
305305

306306
type DefaultProps = {|
307307
keyExtractor: (item: Item, index: number) => string,
308-
maxToRenderPerBatch: number,
309308
onEndReachedThreshold: number,
310309
scrollEventThrottle: number,
311310
updateCellsBatchingPeriod: number,
@@ -328,6 +327,10 @@ function initialNumToRenderOrDefault(initialNumToRender: ?number) {
328327
return initialNumToRender ?? 10;
329328
}
330329

330+
function maxToRenderPerBatchOrDefault(maxToRenderPerBatch: ?number) {
331+
return maxToRenderPerBatch ?? 10;
332+
}
333+
331334
/**
332335
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist.html)
333336
* and [`<SectionList>`](https://reactnative.dev/docs/sectionlist.html) components, which are also better
@@ -583,7 +586,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
583586
}
584587
return String(index);
585588
},
586-
maxToRenderPerBatch: 10,
587589
onEndReachedThreshold: 2, // multiples of length
588590
scrollEventThrottle: 50,
589591
updateCellsBatchingPeriod: 50,
@@ -769,7 +771,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
769771
}
770772

771773
static getDerivedStateFromProps(newProps: Props, prevState: State): State {
772-
const {data, getItemCount, maxToRenderPerBatch} = newProps;
774+
const {data, getItemCount} = newProps;
775+
const maxToRenderPerBatch = maxToRenderPerBatchOrDefault(
776+
newProps.maxToRenderPerBatch,
777+
);
773778
// first and last could be stale (e.g. if a new, shorter items props is passed in), so we make
774779
// sure we're rendering a reasonable range here.
775780
return {
@@ -1736,7 +1741,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
17361741
newState = computeWindowedRenderLimits(
17371742
this.props.data,
17381743
this.props.getItemCount,
1739-
this.props.maxToRenderPerBatch,
1744+
maxToRenderPerBatchOrDefault(this.props.maxToRenderPerBatch),
17401745
this.props.windowSize,
17411746
state,
17421747
this._getFrameMetricsApprox,
@@ -1751,7 +1756,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
17511756
* an error found when Flow v0.63 was deployed. To see the error
17521757
* delete this comment and run Flow. */
17531758
distanceFromEnd < onEndReachedThreshold * visibleLength
1754-
? this.props.maxToRenderPerBatch
1759+
? maxToRenderPerBatchOrDefault(this.props.maxToRenderPerBatch)
17551760
: 0;
17561761
newState = {
17571762
first: 0,

Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ exports[`FlatList renders all the bells and whistles 1`] = `
2929
getItemCount={[Function]}
3030
getItemLayout={[Function]}
3131
keyExtractor={[Function]}
32-
maxToRenderPerBatch={10}
3332
onContentSizeChange={[Function]}
3433
onEndReachedThreshold={2}
3534
onLayout={[Function]}
@@ -129,7 +128,6 @@ exports[`FlatList renders empty list 1`] = `
129128
getItem={[Function]}
130129
getItemCount={[Function]}
131130
keyExtractor={[Function]}
132-
maxToRenderPerBatch={10}
133131
onContentSizeChange={[Function]}
134132
onEndReachedThreshold={2}
135133
onLayout={[Function]}
@@ -155,7 +153,6 @@ exports[`FlatList renders null list 1`] = `
155153
getItem={[Function]}
156154
getItemCount={[Function]}
157155
keyExtractor={[Function]}
158-
maxToRenderPerBatch={10}
159156
onContentSizeChange={[Function]}
160157
onEndReachedThreshold={2}
161158
onLayout={[Function]}
@@ -194,7 +191,6 @@ exports[`FlatList renders simple list (multiple columns) 1`] = `
194191
getItem={[Function]}
195192
getItemCount={[Function]}
196193
keyExtractor={[Function]}
197-
maxToRenderPerBatch={10}
198194
onContentSizeChange={[Function]}
199195
onEndReachedThreshold={2}
200196
onLayout={[Function]}
@@ -269,7 +265,6 @@ exports[`FlatList renders simple list 1`] = `
269265
getItem={[Function]}
270266
getItemCount={[Function]}
271267
keyExtractor={[Function]}
272-
maxToRenderPerBatch={10}
273268
onContentSizeChange={[Function]}
274269
onEndReachedThreshold={2}
275270
onLayout={[Function]}
@@ -334,7 +329,6 @@ exports[`FlatList renders simple list using ListItemComponent (multiple columns)
334329
getItem={[Function]}
335330
getItemCount={[Function]}
336331
keyExtractor={[Function]}
337-
maxToRenderPerBatch={10}
338332
onContentSizeChange={[Function]}
339333
onEndReachedThreshold={2}
340334
onLayout={[Function]}
@@ -409,7 +403,6 @@ exports[`FlatList renders simple list using ListItemComponent 1`] = `
409403
getItem={[Function]}
410404
getItemCount={[Function]}
411405
keyExtractor={[Function]}
412-
maxToRenderPerBatch={10}
413406
onContentSizeChange={[Function]}
414407
onEndReachedThreshold={2}
415408
onLayout={[Function]}

Libraries/Lists/__tests__/__snapshots__/SectionList-test.js.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ exports[`SectionList rendering empty section headers is fine 1`] = `
2020
getItem={[Function]}
2121
getItemCount={[Function]}
2222
keyExtractor={[Function]}
23-
maxToRenderPerBatch={10}
2423
onContentSizeChange={[Function]}
2524
onEndReachedThreshold={2}
2625
onLayout={[Function]}
@@ -81,7 +80,6 @@ exports[`SectionList renders a footer when there is no data 1`] = `
8180
getItem={[Function]}
8281
getItemCount={[Function]}
8382
keyExtractor={[Function]}
84-
maxToRenderPerBatch={10}
8583
onContentSizeChange={[Function]}
8684
onEndReachedThreshold={2}
8785
onLayout={[Function]}
@@ -134,7 +132,6 @@ exports[`SectionList renders a footer when there is no data and no header 1`] =
134132
getItem={[Function]}
135133
getItemCount={[Function]}
136134
keyExtractor={[Function]}
137-
maxToRenderPerBatch={10}
138135
onContentSizeChange={[Function]}
139136
onEndReachedThreshold={2}
140137
onLayout={[Function]}
@@ -219,7 +216,6 @@ exports[`SectionList renders all the bells and whistles 1`] = `
219216
getItemCount={[Function]}
220217
initialNumToRender={Infinity}
221218
keyExtractor={[Function]}
222-
maxToRenderPerBatch={10}
223219
onContentSizeChange={[Function]}
224220
onEndReachedThreshold={2}
225221
onLayout={[Function]}
@@ -409,7 +405,6 @@ exports[`SectionList renders empty list 1`] = `
409405
getItem={[Function]}
410406
getItemCount={[Function]}
411407
keyExtractor={[Function]}
412-
maxToRenderPerBatch={10}
413408
onContentSizeChange={[Function]}
414409
onEndReachedThreshold={2}
415410
onLayout={[Function]}

Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ exports[`VirtualizedList forwards correct stickyHeaderIndices when all in initia
4545
getItemLayout={[Function]}
4646
initialNumToRender={10}
4747
keyExtractor={[Function]}
48-
maxToRenderPerBatch={10}
4948
onContentSizeChange={[Function]}
5049
onEndReachedThreshold={2}
5150
onLayout={[Function]}
@@ -191,7 +190,6 @@ exports[`VirtualizedList forwards correct stickyHeaderIndices when partially in
191190
getItemLayout={[Function]}
192191
initialNumToRender={5}
193192
keyExtractor={[Function]}
194-
maxToRenderPerBatch={10}
195193
onContentSizeChange={[Function]}
196194
onEndReachedThreshold={2}
197195
onLayout={[Function]}
@@ -275,7 +273,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
275273
getItem={[Function]}
276274
getItemCount={[Function]}
277275
keyExtractor={[Function]}
278-
maxToRenderPerBatch={10}
279276
onContentSizeChange={[Function]}
280277
onEndReachedThreshold={2}
281278
onLayout={[Function]}
@@ -310,7 +307,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
310307
getItemCount={[Function]}
311308
horizontal={false}
312309
keyExtractor={[Function]}
313-
maxToRenderPerBatch={10}
314310
onContentSizeChange={[Function]}
315311
onEndReachedThreshold={2}
316312
onLayout={[Function]}
@@ -362,7 +358,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
362358
getItemCount={[Function]}
363359
horizontal={true}
364360
keyExtractor={[Function]}
365-
maxToRenderPerBatch={10}
366361
onContentSizeChange={[Function]}
367362
onEndReachedThreshold={2}
368363
onLayout={[Function]}
@@ -434,7 +429,6 @@ exports[`VirtualizedList handles separators correctly 1`] = `
434429
getItem={[Function]}
435430
getItemCount={[Function]}
436431
keyExtractor={[Function]}
437-
maxToRenderPerBatch={10}
438432
onContentSizeChange={[Function]}
439433
onEndReachedThreshold={2}
440434
onLayout={[Function]}
@@ -513,7 +507,6 @@ exports[`VirtualizedList handles separators correctly 2`] = `
513507
getItem={[Function]}
514508
getItemCount={[Function]}
515509
keyExtractor={[Function]}
516-
maxToRenderPerBatch={10}
517510
onContentSizeChange={[Function]}
518511
onEndReachedThreshold={2}
519512
onLayout={[Function]}
@@ -592,7 +585,6 @@ exports[`VirtualizedList handles separators correctly 3`] = `
592585
getItem={[Function]}
593586
getItemCount={[Function]}
594587
keyExtractor={[Function]}
595-
maxToRenderPerBatch={10}
596588
onContentSizeChange={[Function]}
597589
onEndReachedThreshold={2}
598590
onLayout={[Function]}
@@ -744,7 +736,6 @@ exports[`VirtualizedList keeps sticky headers realized after scrolled out of vie
744736
getItemLayout={[Function]}
745737
initialNumToRender={1}
746738
keyExtractor={[Function]}
747-
maxToRenderPerBatch={10}
748739
onContentSizeChange={[Function]}
749740
onEndReachedThreshold={2}
750741
onLayout={[Function]}
@@ -936,7 +927,6 @@ exports[`VirtualizedList realizes sticky headers in viewport on batched render 1
936927
getItemLayout={[Function]}
937928
initialNumToRender={1}
938929
keyExtractor={[Function]}
939-
maxToRenderPerBatch={10}
940930
onContentSizeChange={[Function]}
941931
onEndReachedThreshold={2}
942932
onLayout={[Function]}
@@ -1036,7 +1026,6 @@ exports[`VirtualizedList renders all the bells and whistles 1`] = `
10361026
invertStickyHeaders={true}
10371027
inverted={true}
10381028
keyExtractor={[Function]}
1039-
maxToRenderPerBatch={10}
10401029
onContentSizeChange={[Function]}
10411030
onEndReachedThreshold={2}
10421031
onLayout={[Function]}
@@ -1215,7 +1204,6 @@ exports[`VirtualizedList renders empty list 1`] = `
12151204
getItem={[Function]}
12161205
getItemCount={[Function]}
12171206
keyExtractor={[Function]}
1218-
maxToRenderPerBatch={10}
12191207
onContentSizeChange={[Function]}
12201208
onEndReachedThreshold={2}
12211209
onLayout={[Function]}
@@ -1243,7 +1231,6 @@ exports[`VirtualizedList renders empty list with empty component 1`] = `
12431231
getItem={[Function]}
12441232
getItemCount={[Function]}
12451233
keyExtractor={[Function]}
1246-
maxToRenderPerBatch={10}
12471234
onContentSizeChange={[Function]}
12481235
onEndReachedThreshold={2}
12491236
onLayout={[Function]}
@@ -1287,7 +1274,6 @@ exports[`VirtualizedList renders list with empty component 1`] = `
12871274
getItem={[Function]}
12881275
getItemCount={[Function]}
12891276
keyExtractor={[Function]}
1290-
maxToRenderPerBatch={10}
12911277
onContentSizeChange={[Function]}
12921278
onEndReachedThreshold={2}
12931279
onLayout={[Function]}
@@ -1320,7 +1306,6 @@ exports[`VirtualizedList renders null list 1`] = `
13201306
getItem={[Function]}
13211307
getItemCount={[Function]}
13221308
keyExtractor={[Function]}
1323-
maxToRenderPerBatch={10}
13241309
onContentSizeChange={[Function]}
13251310
onEndReachedThreshold={2}
13261311
onLayout={[Function]}
@@ -1357,7 +1342,6 @@ exports[`VirtualizedList renders simple list 1`] = `
13571342
getItem={[Function]}
13581343
getItemCount={[Function]}
13591344
keyExtractor={[Function]}
1360-
maxToRenderPerBatch={10}
13611345
onContentSizeChange={[Function]}
13621346
onEndReachedThreshold={2}
13631347
onLayout={[Function]}
@@ -1420,7 +1404,6 @@ exports[`VirtualizedList renders simple list using ListItemComponent 1`] = `
14201404
getItem={[Function]}
14211405
getItemCount={[Function]}
14221406
keyExtractor={[Function]}
1423-
maxToRenderPerBatch={10}
14241407
onContentSizeChange={[Function]}
14251408
onEndReachedThreshold={2}
14261409
onLayout={[Function]}
@@ -1475,7 +1458,6 @@ exports[`VirtualizedList test getItem functionality where data is not an Array 1
14751458
getItem={[Function]}
14761459
getItemCount={[Function]}
14771460
keyExtractor={[Function]}
1478-
maxToRenderPerBatch={10}
14791461
onContentSizeChange={[Function]}
14801462
onEndReachedThreshold={2}
14811463
onLayout={[Function]}
@@ -1516,7 +1498,6 @@ exports[`VirtualizedList warns if both renderItem or ListItemComponent are speci
15161498
getItem={[Function]}
15171499
getItemCount={[Function]}
15181500
keyExtractor={[Function]}
1519-
maxToRenderPerBatch={10}
15201501
onContentSizeChange={[Function]}
15211502
onEndReachedThreshold={2}
15221503
onLayout={[Function]}

0 commit comments

Comments
 (0)