Skip to content

Commit f8f6f9d

Browse files
committed
fix: Improve scroll anchor offset calculation
1 parent c4373d1 commit f8f6f9d

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/Reader.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,15 @@ const Reader = ({
309309
onViewportsMeasured && onViewportsMeasured();
310310

311311
if (scrollAnchor) {
312-
const startOffset = virtualizer.getOffsetForIndex(
313-
scrollAnchor.index,
314-
"start",
315-
)?.[0];
312+
// const startOffset = virtualizer.getOffsetForIndex(
313+
// scrollAnchor.index,
314+
// "start",
315+
// )?.[0];
316+
let offset = virtualizer.options.paddingStart;
317+
for (let i = 0; i < scrollAnchor.index; i++) {
318+
offset += estimateSize(i) + virtualizer.options.gap;
319+
}
320+
const startOffset = offset;
316321

317322
console.log({ ...scrollAnchor });
318323
if (startOffset != null) {
@@ -324,7 +329,8 @@ const Reader = ({
324329
});
325330
const offsetExtra = itemHeight * scrollAnchor.percentageOffsetY * 0.01;
326331
console.log({
327-
startOffset,
332+
wantPageIndex: scrollAnchor.index,
333+
startOffsetForPage: startOffset,
328334
itemHeight,
329335
percentage: scrollAnchor.percentageOffsetY,
330336
offsetExtra,

0 commit comments

Comments
 (0)