#69 : Apply partial offset
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
getCurrentPageIndexWithoutClones,
|
||||
getPagesCountWithoutClones,
|
||||
getClonesCount,
|
||||
getIsPartialOffset,
|
||||
} from '../../utils/page'
|
||||
import { get } from '../../utils/object'
|
||||
import { ProgressManager } from '../../utils/ProgressManager'
|
||||
@@ -292,14 +291,6 @@
|
||||
// _duration is an offset animation time
|
||||
_duration = animated ? duration : 0
|
||||
|
||||
const isPartialOffset = getIsPartialOffset({
|
||||
pagesCountWithoutClones,
|
||||
headClonesCount: clonesCount.head,
|
||||
pagesToScroll,
|
||||
currentPageIndexWithoutClones,
|
||||
})
|
||||
console.log('isPartialOffset', isPartialOffset)
|
||||
|
||||
offset = -currentPageIndex * pageWidth
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -315,7 +306,7 @@
|
||||
if (currentPageIndex === 0) {
|
||||
await showPage(pagesCount - clonesCount.total, { animated: false })
|
||||
jumped = true
|
||||
} else if (currentPageIndex === pagesCount - clonesCount.head ) {
|
||||
} else if (currentPageIndex === pagesCount - clonesCount.tail) {
|
||||
await showPage(clonesCount.head, { animated: false })
|
||||
jumped = true
|
||||
}
|
||||
@@ -363,6 +354,7 @@
|
||||
infinite,
|
||||
pagesCount,
|
||||
pagesToScroll,
|
||||
clonesCountTail: clonesCount.tail,
|
||||
}),
|
||||
options,
|
||||
)
|
||||
|
||||
@@ -40,12 +40,14 @@ function createStore() {
|
||||
infinite,
|
||||
pagesCount,
|
||||
pagesToScroll,
|
||||
clonesCountTail,
|
||||
}) {
|
||||
update(store => {
|
||||
const newCurrentPageIndex = getNextPageIndexFn(infinite)({
|
||||
currentPageIndex: store.currentPageIndex,
|
||||
pagesCount,
|
||||
pagesToScroll,
|
||||
clonesCountTail,
|
||||
})
|
||||
return {
|
||||
...store,
|
||||
|
||||
@@ -2,6 +2,7 @@ export function getNextPageIndexLimited({
|
||||
currentPageIndex,
|
||||
pagesCount,
|
||||
pagesToScroll,
|
||||
clonesCountTail,
|
||||
}) {
|
||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||
return Math.min(Math.max(currentPageIndex + pagesToScroll, 0), pagesCount - 1)
|
||||
@@ -11,9 +12,10 @@ export function getNextPageIndexInfinte({
|
||||
currentPageIndex,
|
||||
pagesCount,
|
||||
pagesToScroll,
|
||||
clonesCountTail,
|
||||
}) {
|
||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||
const newCurrentPageIndex = Math.max(currentPageIndex, 0) + pagesToScroll
|
||||
const newCurrentPageIndex = Math.max(currentPageIndex, 0) + Math.min(pagesCount - clonesCountTail - currentPageIndex, pagesToScroll)
|
||||
return newCurrentPageIndex > pagesCount - 1 ? 0 : Math.max(newCurrentPageIndex, 0)
|
||||
}
|
||||
|
||||
@@ -36,7 +38,7 @@ export function getPrevPageIndexInfinte({
|
||||
pagesToScroll,
|
||||
}) {
|
||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||
const newCurrentPageIndex = Math.min(currentPageIndex, pagesCount - 1) - pagesToScroll
|
||||
const newCurrentPageIndex = Math.min(currentPageIndex, pagesCount - 1) - Math.min(currentPageIndex, pagesToScroll)
|
||||
return newCurrentPageIndex >= 0 ? Math.min(newCurrentPageIndex, pagesCount - 1) : pagesCount - 1
|
||||
}
|
||||
|
||||
@@ -168,7 +170,6 @@ export function getPagesCountWithoutClones({
|
||||
|
||||
export function getClonesCount({
|
||||
infinite,
|
||||
// pagesToScroll,
|
||||
pagesToShow,
|
||||
partialPageSize,
|
||||
}) {
|
||||
@@ -190,16 +191,3 @@ export function getClonesCount({
|
||||
total: clonesCount.head + clonesCount.tail,
|
||||
}
|
||||
}
|
||||
|
||||
export function getIsPartialOffset({
|
||||
pagesCountWithoutClones,
|
||||
headClonesCount,
|
||||
pagesToScroll,
|
||||
currentPageIndexWithoutClones,
|
||||
}) {
|
||||
return (
|
||||
pagesCountWithoutClones + headClonesCount ===
|
||||
currentPageIndexWithoutClones + pagesToScroll
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user