mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 03:26:07 +00:00
Fix problems if _updateCellsToRender gets called too early
Summary: (prior to the scroll metrics being set up, or prior to the view being scrolled to the right location). I'm using a StackNavigator to push a FlatList secondary screen, and it was causing extraneous rendering (item X ->item 0 -> item X) I've logged inside the render functions of my `renderItem` function, and verified that it no longer attempts to render item 0 anymore. And I've verified from the `VirtualizedList.state` no longer renders a `{first: 0, last: 0}`, but persistently stays at `{first: X, last: X}` from start until things stabilize. Closes https://github.com/facebook/react-native/pull/14562 Reviewed By: bvaughn Differential Revision: D5283771 Pulled By: sahrens fbshipit-source-id: 0f70ac0b89922449bd20bfa69edbc8939eafdf1f
This commit is contained in:
parent
8e9322c65e
commit
1ee602b655
@ -1026,12 +1026,24 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, State> {
|
||||
this.setState(state => {
|
||||
let newState;
|
||||
if (!isVirtualizationDisabled) {
|
||||
newState = computeWindowedRenderLimits(
|
||||
this.props,
|
||||
state,
|
||||
this._getFrameMetricsApprox,
|
||||
this._scrollMetrics,
|
||||
);
|
||||
// If we run this with bogus data, we'll force-render window {first: 0, last: 0},
|
||||
// and wipe out the initialNumToRender rendered elements.
|
||||
// So let's wait until the scroll view metrics have been set up. And until then,
|
||||
// we will trust the initialNumToRender suggestion
|
||||
if (this._scrollMetrics.visibleLength) {
|
||||
// If we have a non-zero initialScrollIndex and run this before we've scrolled,
|
||||
// we'll wipe out the initialNumToRender rendered elements starting at initialScrollIndex.
|
||||
// So let's wait until we've scrolled the view to the right place. And until then,
|
||||
// we will trust the initialScrollIndex suggestion.
|
||||
if (!this.props.initialScrollIndex || this._scrollMetrics.offset) {
|
||||
newState = computeWindowedRenderLimits(
|
||||
this.props,
|
||||
state,
|
||||
this._getFrameMetricsApprox,
|
||||
this._scrollMetrics,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const {contentLength, offset, visibleLength} = this._scrollMetrics;
|
||||
const distanceFromEnd = contentLength - visibleLength - offset;
|
||||
|
Loading…
x
Reference in New Issue
Block a user