#69 : Fix initial page index

This commit is contained in:
Vadim
2021-09-08 18:42:44 +03:00
parent 538624bb5d
commit b8e2e57426
2 changed files with 14 additions and 3 deletions

View File

@@ -264,7 +264,8 @@
await tick()
infinite && addClones()
store.init(initialPageIndex + clonesCount.head)
// TODO: validate initialPageIndex, initialPageIndex is an initialScrollIndex
store.init(initialPageIndex * pagesToScroll + clonesCount.head)
initPageSizes()
}

View File

@@ -5,7 +5,12 @@ export function getNextPageIndexLimited({
clonesCountTail,
}) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
return Math.min(Math.max(currentPageIndex + pagesToScroll, 0), pagesCount - 1)
return Math.min(
Math.max(currentPageIndex +
Math.min(pagesCount - clonesCountTail - currentPageIndex, pagesToScroll),
0),
pagesCount - 1
)
}
export function getNextPageIndexInfinte({
@@ -29,7 +34,12 @@ export function getPrevPageIndexLimited({
pagesToScroll,
}) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
return Math.max(Math.min(currentPageIndex - pagesToScroll, pagesCount - 1), 0)
return Math.max(
Math.min(
currentPageIndex - Math.min(currentPageIndex, pagesToScroll),
pagesCount - 1
),
0)
}
export function getPrevPageIndexInfinte({