Skip to content

Commit e928f54

Browse files
Luna Weifacebook-github-bot
authored andcommitted
Remove initialNumToRender defaultProps
Summary: Changelog: [Internal][Changed] - Remove initialNumToRender from defaultProps as part of larger effort to remove defaultProps from VirtualizedList Reviewed By: nadiia Differential Revision: D26969585 fbshipit-source-id: 8674544c06b7b99eee693cc7508c9e4199232e98
1 parent 00bc09c commit e928f54

File tree

8 files changed

+11
-45
lines changed

8 files changed

+11
-45
lines changed

Libraries/Lists/FillRateHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class FillRateHelper {
135135
props: {
136136
data: any,
137137
getItemCount: (data: any) => number,
138-
initialNumToRender: number,
138+
initialNumToRender?: ?number,
139139
...
140140
},
141141
state: {

Libraries/Lists/FlatList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type OptionalProps<ItemT> = {|
103103
* much more. Note these items will never be unmounted as part of the windowed rendering in order
104104
* to improve perceived performance of scroll-to-top actions.
105105
*/
106-
initialNumToRender: number,
106+
initialNumToRender?: ?number,
107107
/**
108108
* Instead of starting at the top with the first item, start at `initialScrollIndex`. This
109109
* disables the "scroll to top" optimization that keeps the first `initialNumToRender` items

Libraries/Lists/SectionList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type OptionalProps<SectionT: SectionBase<any>> = {|
6767
* much more. Note these items will never be unmounted as part of the windowed rendering in order
6868
* to improve perceived performance of scroll-to-top actions.
6969
*/
70-
initialNumToRender: number,
70+
initialNumToRender?: ?number,
7171
/**
7272
* Reverses the direction of scroll. Uses scale transforms of -1.
7373
*/

Libraries/Lists/VirtualizedList.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type OptionalProps = {|
120120
* much more. Note these items will never be unmounted as part of the windowed rendering in order
121121
* to improve perceived performance of scroll-to-top actions.
122122
*/
123-
initialNumToRender: number,
123+
initialNumToRender?: ?number,
124124
/**
125125
* Instead of starting at the top with the first item, start at `initialScrollIndex`. This
126126
* disables the "scroll to top" optimization that keeps the first `initialNumToRender` items
@@ -304,7 +304,6 @@ type Props = {|
304304
|};
305305

306306
type DefaultProps = {|
307-
initialNumToRender: number,
308307
keyExtractor: (item: Item, index: number) => string,
309308
maxToRenderPerBatch: number,
310309
onEndReachedThreshold: number,
@@ -325,6 +324,10 @@ function horizontalOrDefault(horizontal: ?boolean) {
325324
return horizontal ?? false;
326325
}
327326

327+
function initialNumToRenderOrDefault(initialNumToRender: ?number) {
328+
return initialNumToRender ?? 10;
329+
}
330+
328331
/**
329332
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist.html)
330333
* and [`<SectionList>`](https://reactnative.dev/docs/sectionlist.html) components, which are also better
@@ -567,7 +570,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
567570
}
568571

569572
static defaultProps: DefaultProps = {
570-
initialNumToRender: 10,
571573
keyExtractor: (item: Item, index: number) => {
572574
if (item.key != null) {
573575
return item.key;
@@ -715,7 +717,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
715717
last:
716718
Math.min(
717719
this.props.getItemCount(this.props.data),
718-
(this.props.initialScrollIndex || 0) + this.props.initialNumToRender,
720+
(this.props.initialScrollIndex || 0) +
721+
initialNumToRenderOrDefault(this.props.initialNumToRender),
719722
) - 1,
720723
};
721724

@@ -913,7 +916,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
913916
const spacerKey = this._getSpacerKey(!horizontal);
914917
const lastInitialIndex = this.props.initialScrollIndex
915918
? -1
916-
: this.props.initialNumToRender - 1;
919+
: initialNumToRenderOrDefault(this.props.initialNumToRender) - 1;
917920
const {first, last} = this.state;
918921
this._pushCells(
919922
cells,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ exports[`FlatList renders all the bells and whistles 1`] = `
2828
getItem={[Function]}
2929
getItemCount={[Function]}
3030
getItemLayout={[Function]}
31-
initialNumToRender={10}
3231
keyExtractor={[Function]}
3332
maxToRenderPerBatch={10}
3433
onContentSizeChange={[Function]}
@@ -129,7 +128,6 @@ exports[`FlatList renders empty list 1`] = `
129128
data={Array []}
130129
getItem={[Function]}
131130
getItemCount={[Function]}
132-
initialNumToRender={10}
133131
keyExtractor={[Function]}
134132
maxToRenderPerBatch={10}
135133
onContentSizeChange={[Function]}
@@ -156,7 +154,6 @@ exports[`FlatList renders null list 1`] = `
156154
<RCTScrollView
157155
getItem={[Function]}
158156
getItemCount={[Function]}
159-
initialNumToRender={10}
160157
keyExtractor={[Function]}
161158
maxToRenderPerBatch={10}
162159
onContentSizeChange={[Function]}
@@ -196,7 +193,6 @@ exports[`FlatList renders simple list (multiple columns) 1`] = `
196193
}
197194
getItem={[Function]}
198195
getItemCount={[Function]}
199-
initialNumToRender={10}
200196
keyExtractor={[Function]}
201197
maxToRenderPerBatch={10}
202198
onContentSizeChange={[Function]}
@@ -272,7 +268,6 @@ exports[`FlatList renders simple list 1`] = `
272268
}
273269
getItem={[Function]}
274270
getItemCount={[Function]}
275-
initialNumToRender={10}
276271
keyExtractor={[Function]}
277272
maxToRenderPerBatch={10}
278273
onContentSizeChange={[Function]}
@@ -338,7 +333,6 @@ exports[`FlatList renders simple list using ListItemComponent (multiple columns)
338333
}
339334
getItem={[Function]}
340335
getItemCount={[Function]}
341-
initialNumToRender={10}
342336
keyExtractor={[Function]}
343337
maxToRenderPerBatch={10}
344338
onContentSizeChange={[Function]}
@@ -414,7 +408,6 @@ exports[`FlatList renders simple list using ListItemComponent 1`] = `
414408
}
415409
getItem={[Function]}
416410
getItemCount={[Function]}
417-
initialNumToRender={10}
418411
keyExtractor={[Function]}
419412
maxToRenderPerBatch={10}
420413
onContentSizeChange={[Function]}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exports[`SectionList rendering empty section headers is fine 1`] = `
1919
}
2020
getItem={[Function]}
2121
getItemCount={[Function]}
22-
initialNumToRender={10}
2322
keyExtractor={[Function]}
2423
maxToRenderPerBatch={10}
2524
onContentSizeChange={[Function]}
@@ -81,7 +80,6 @@ exports[`SectionList renders a footer when there is no data 1`] = `
8180
}
8281
getItem={[Function]}
8382
getItemCount={[Function]}
84-
initialNumToRender={10}
8583
keyExtractor={[Function]}
8684
maxToRenderPerBatch={10}
8785
onContentSizeChange={[Function]}
@@ -135,7 +133,6 @@ exports[`SectionList renders a footer when there is no data and no header 1`] =
135133
}
136134
getItem={[Function]}
137135
getItemCount={[Function]}
138-
initialNumToRender={10}
139136
keyExtractor={[Function]}
140137
maxToRenderPerBatch={10}
141138
onContentSizeChange={[Function]}
@@ -411,7 +408,6 @@ exports[`SectionList renders empty list 1`] = `
411408
data={Array []}
412409
getItem={[Function]}
413410
getItemCount={[Function]}
414-
initialNumToRender={10}
415411
keyExtractor={[Function]}
416412
maxToRenderPerBatch={10}
417413
onContentSizeChange={[Function]}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
274274
}
275275
getItem={[Function]}
276276
getItemCount={[Function]}
277-
initialNumToRender={10}
278277
keyExtractor={[Function]}
279278
maxToRenderPerBatch={10}
280279
onContentSizeChange={[Function]}
@@ -310,7 +309,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
310309
getItem={[Function]}
311310
getItemCount={[Function]}
312311
horizontal={false}
313-
initialNumToRender={10}
314312
keyExtractor={[Function]}
315313
maxToRenderPerBatch={10}
316314
onContentSizeChange={[Function]}
@@ -363,7 +361,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
363361
getItem={[Function]}
364362
getItemCount={[Function]}
365363
horizontal={true}
366-
initialNumToRender={10}
367364
keyExtractor={[Function]}
368365
maxToRenderPerBatch={10}
369366
onContentSizeChange={[Function]}
@@ -436,7 +433,6 @@ exports[`VirtualizedList handles separators correctly 1`] = `
436433
}
437434
getItem={[Function]}
438435
getItemCount={[Function]}
439-
initialNumToRender={10}
440436
keyExtractor={[Function]}
441437
maxToRenderPerBatch={10}
442438
onContentSizeChange={[Function]}
@@ -516,7 +512,6 @@ exports[`VirtualizedList handles separators correctly 2`] = `
516512
}
517513
getItem={[Function]}
518514
getItemCount={[Function]}
519-
initialNumToRender={10}
520515
keyExtractor={[Function]}
521516
maxToRenderPerBatch={10}
522517
onContentSizeChange={[Function]}
@@ -596,7 +591,6 @@ exports[`VirtualizedList handles separators correctly 3`] = `
596591
}
597592
getItem={[Function]}
598593
getItemCount={[Function]}
599-
initialNumToRender={10}
600594
keyExtractor={[Function]}
601595
maxToRenderPerBatch={10}
602596
onContentSizeChange={[Function]}
@@ -1039,7 +1033,6 @@ exports[`VirtualizedList renders all the bells and whistles 1`] = `
10391033
getItem={[Function]}
10401034
getItemCount={[Function]}
10411035
getItemLayout={[Function]}
1042-
initialNumToRender={10}
10431036
invertStickyHeaders={true}
10441037
inverted={true}
10451038
keyExtractor={[Function]}
@@ -1221,7 +1214,6 @@ exports[`VirtualizedList renders empty list 1`] = `
12211214
data={Array []}
12221215
getItem={[Function]}
12231216
getItemCount={[Function]}
1224-
initialNumToRender={10}
12251217
keyExtractor={[Function]}
12261218
maxToRenderPerBatch={10}
12271219
onContentSizeChange={[Function]}
@@ -1250,7 +1242,6 @@ exports[`VirtualizedList renders empty list with empty component 1`] = `
12501242
data={Array []}
12511243
getItem={[Function]}
12521244
getItemCount={[Function]}
1253-
initialNumToRender={10}
12541245
keyExtractor={[Function]}
12551246
maxToRenderPerBatch={10}
12561247
onContentSizeChange={[Function]}
@@ -1295,7 +1286,6 @@ exports[`VirtualizedList renders list with empty component 1`] = `
12951286
}
12961287
getItem={[Function]}
12971288
getItemCount={[Function]}
1298-
initialNumToRender={10}
12991289
keyExtractor={[Function]}
13001290
maxToRenderPerBatch={10}
13011291
onContentSizeChange={[Function]}
@@ -1329,7 +1319,6 @@ exports[`VirtualizedList renders null list 1`] = `
13291319
<RCTScrollView
13301320
getItem={[Function]}
13311321
getItemCount={[Function]}
1332-
initialNumToRender={10}
13331322
keyExtractor={[Function]}
13341323
maxToRenderPerBatch={10}
13351324
onContentSizeChange={[Function]}
@@ -1367,7 +1356,6 @@ exports[`VirtualizedList renders simple list 1`] = `
13671356
}
13681357
getItem={[Function]}
13691358
getItemCount={[Function]}
1370-
initialNumToRender={10}
13711359
keyExtractor={[Function]}
13721360
maxToRenderPerBatch={10}
13731361
onContentSizeChange={[Function]}
@@ -1431,7 +1419,6 @@ exports[`VirtualizedList renders simple list using ListItemComponent 1`] = `
14311419
}
14321420
getItem={[Function]}
14331421
getItemCount={[Function]}
1434-
initialNumToRender={10}
14351422
keyExtractor={[Function]}
14361423
maxToRenderPerBatch={10}
14371424
onContentSizeChange={[Function]}
@@ -1487,7 +1474,6 @@ exports[`VirtualizedList test getItem functionality where data is not an Array 1
14871474
}
14881475
getItem={[Function]}
14891476
getItemCount={[Function]}
1490-
initialNumToRender={10}
14911477
keyExtractor={[Function]}
14921478
maxToRenderPerBatch={10}
14931479
onContentSizeChange={[Function]}
@@ -1529,7 +1515,6 @@ exports[`VirtualizedList warns if both renderItem or ListItemComponent are speci
15291515
}
15301516
getItem={[Function]}
15311517
getItemCount={[Function]}
1532-
initialNumToRender={10}
15331518
keyExtractor={[Function]}
15341519
maxToRenderPerBatch={10}
15351520
onContentSizeChange={[Function]}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exports[`VirtualizedSectionList handles nested lists 1`] = `
1919
}
2020
getItem={[Function]}
2121
getItemCount={[Function]}
22-
initialNumToRender={10}
2322
keyExtractor={[Function]}
2423
maxToRenderPerBatch={10}
2524
onContentSizeChange={[Function]}
@@ -64,7 +63,6 @@ exports[`VirtualizedSectionList handles nested lists 1`] = `
6463
getItem={[Function]}
6564
getItemCount={[Function]}
6665
horizontal={false}
67-
initialNumToRender={10}
6866
keyExtractor={[Function]}
6967
maxToRenderPerBatch={10}
7068
onContentSizeChange={[Function]}
@@ -130,7 +128,6 @@ exports[`VirtualizedSectionList handles nested lists 1`] = `
130128
getItem={[Function]}
131129
getItemCount={[Function]}
132130
horizontal={true}
133-
initialNumToRender={10}
134131
keyExtractor={[Function]}
135132
maxToRenderPerBatch={10}
136133
onContentSizeChange={[Function]}
@@ -233,7 +230,6 @@ exports[`VirtualizedSectionList handles separators correctly 1`] = `
233230
}
234231
getItem={[Function]}
235232
getItemCount={[Function]}
236-
initialNumToRender={10}
237233
keyExtractor={[Function]}
238234
maxToRenderPerBatch={10}
239235
onContentSizeChange={[Function]}
@@ -371,7 +367,6 @@ exports[`VirtualizedSectionList handles separators correctly 2`] = `
371367
}
372368
getItem={[Function]}
373369
getItemCount={[Function]}
374-
initialNumToRender={10}
375370
keyExtractor={[Function]}
376371
maxToRenderPerBatch={10}
377372
onContentSizeChange={[Function]}
@@ -509,7 +504,6 @@ exports[`VirtualizedSectionList handles separators correctly 3`] = `
509504
}
510505
getItem={[Function]}
511506
getItemCount={[Function]}
512-
initialNumToRender={10}
513507
keyExtractor={[Function]}
514508
maxToRenderPerBatch={10}
515509
onContentSizeChange={[Function]}
@@ -658,7 +652,6 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
658652
getItem={[Function]}
659653
getItemCount={[Function]}
660654
getItemLayout={[Function]}
661-
initialNumToRender={10}
662655
invertStickyHeaders={true}
663656
inverted={true}
664657
keyExtractor={[Function]}
@@ -880,7 +873,6 @@ exports[`VirtualizedSectionList renders empty list 1`] = `
880873
data={Array []}
881874
getItem={[Function]}
882875
getItemCount={[Function]}
883-
initialNumToRender={10}
884876
keyExtractor={[Function]}
885877
maxToRenderPerBatch={10}
886878
onContentSizeChange={[Function]}
@@ -909,7 +901,6 @@ exports[`VirtualizedSectionList renders empty list with empty component 1`] = `
909901
data={Array []}
910902
getItem={[Function]}
911903
getItemCount={[Function]}
912-
initialNumToRender={10}
913904
keyExtractor={[Function]}
914905
maxToRenderPerBatch={10}
915906
onContentSizeChange={[Function]}
@@ -959,7 +950,6 @@ exports[`VirtualizedSectionList renders list with empty component 1`] = `
959950
}
960951
getItem={[Function]}
961952
getItemCount={[Function]}
962-
initialNumToRender={10}
963953
keyExtractor={[Function]}
964954
maxToRenderPerBatch={10}
965955
onContentSizeChange={[Function]}
@@ -1019,7 +1009,6 @@ exports[`VirtualizedSectionList renders simple list 1`] = `
10191009
}
10201010
getItem={[Function]}
10211011
getItemCount={[Function]}
1022-
initialNumToRender={10}
10231012
keyExtractor={[Function]}
10241013
maxToRenderPerBatch={10}
10251014
onContentSizeChange={[Function]}

0 commit comments

Comments
 (0)