Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/recyclerview/RecyclerViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,26 @@ export class RecyclerViewManager<T> {
}

const initialScrollIndex = this.getInitialScrollIndex();
const initialItemLayout = this.layoutManager?.getLayout(
initialScrollIndex ?? 0
);
const initialItemOffset = this.propsRef.horizontal
? initialItemLayout?.x
: initialItemLayout?.y;

if (initialScrollIndex !== undefined) {
// console.log(
// "initialItemOffset",
// initialScrollIndex,
// initialItemOffset,
// this.firstItemOffset
// );
// Recompute layouts first, then read the offset. The recompute may
// re-estimate unmeasured items with an updated average height, changing
// the target item's position. Reading before recompute would capture a
// stale offset, causing the wrong items to be rendered.
this.layoutManager.recomputeLayouts(0, initialScrollIndex);
this.engagedIndicesTracker.scrollOffset =
initialItemOffset ?? 0 + this.firstItemOffset;
const initialItemLayout =
this.layoutManager.getLayout(initialScrollIndex);
const initialItemOffset = this.propsRef.horizontal
? initialItemLayout.x
: initialItemLayout.y;
this.engagedIndicesTracker.scrollOffset = initialItemOffset;
} else {
// console.log("initialItemOffset", initialItemOffset, this.firstItemOffset);
const initialItemLayout = this.layoutManager.getLayout(0);
const initialItemOffset = this.propsRef.horizontal
? initialItemLayout.x
: initialItemLayout.y;
this.engagedIndicesTracker.scrollOffset =
(initialItemOffset ?? 0) - this.firstItemOffset;
initialItemOffset - this.firstItemOffset;
}
}

Expand Down