Repository navigation
Commit df5c1a1
authored
Don't call VirtualizedList's onLayout with the ListEmptyComponent's layout
## Summary:
When the list is empty, `VirtualizedList` calls the list's `onLayout` twice: once from the `ScrollView` with the list's own frame, and once from `_onLayoutEmpty` with the frame of `ListEmptyComponent`. The second call reports the empty component's position and size inside the content container, so code that sizes things from the list's width (columns, tile sizes) picks up the wrong width whenever the empty component has a margin or padding.
`_onLayoutEmpty` came in with `ListEmptyComponent` in 2017 (264d67c). The header and footer handlers next to it store their own length; the empty one only forwards its event to `props.onLayout`, which looks unintended. This removes it. The empty component's own `onLayout` is still called.
## Changelog:
[GENERAL] [FIXED] - `VirtualizedList` (and `FlatList`/`SectionList`) no longer calls `onLayout` with the layout of `ListEmptyComponent`
## Test Plan:
- Added a test to `VirtualizedList-test.js`: the list's `onLayout` is not called when the empty component lays out. It fails on `main` (1 call, expected 0) and passes with this change. The whole file passes (89 passed, 1 skipped), and `flow full-check`, ESLint and Prettier are clean.
- iOS simulator, RN 0.88.1: an empty `FlatList` with `margin: 8` and a `ListEmptyComponent` with `margin: 24`, logging every `onLayout` call:
| | list `onLayout` calls |
|---|---|
| empty, before | `x=8 y=221 w=386 h=464`, then `x=24 y=24 w=338 h=66` |
| empty, after | `x=8 y=221 w=386 h=464` only; the empty component's own `onLayout` still gets `x=24 y=24 w=338 h=66` |
| one item (before and after) | `x=8 y=221 w=386 h=464` only |
Differential Revision: D133240954
Pull Request resolved: #601491 parent 03a6765 commit df5c1a1
2 files changed
Lines changed: 33 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1151 | 1151 | | |
1152 | 1152 | | |
1153 | 1153 | | |
1154 | | - | |
1155 | | - | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
1161 | 1154 | | |
1162 | 1155 | | |
1163 | 1156 | | |
| |||
1687 | 1680 | | |
1688 | 1681 | | |
1689 | 1682 | | |
1690 | | - | |
1691 | | - | |
1692 | | - | |
1693 | | - | |
1694 | 1683 | | |
1695 | 1684 | | |
1696 | 1685 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
399 | | - | |
| 399 | + | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
404 | 403 | | |
405 | 404 | | |
406 | 405 | | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
436 | | - | |
| 436 | + | |
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
440 | 469 | | |
441 | 470 | | |
442 | 471 | | |
| |||
0 commit comments