#69 : Apply partial offset

This commit is contained in:
Vadim
2021-09-08 00:09:11 +03:00
parent 9af127105f
commit 39b05730d4
3 changed files with 8 additions and 26 deletions

View File

@@ -21,7 +21,6 @@
getCurrentPageIndexWithoutClones, getCurrentPageIndexWithoutClones,
getPagesCountWithoutClones, getPagesCountWithoutClones,
getClonesCount, getClonesCount,
getIsPartialOffset,
} from '../../utils/page' } from '../../utils/page'
import { get } from '../../utils/object' import { get } from '../../utils/object'
import { ProgressManager } from '../../utils/ProgressManager' import { ProgressManager } from '../../utils/ProgressManager'
@@ -292,14 +291,6 @@
// _duration is an offset animation time // _duration is an offset animation time
_duration = animated ? duration : 0 _duration = animated ? duration : 0
const isPartialOffset = getIsPartialOffset({
pagesCountWithoutClones,
headClonesCount: clonesCount.head,
pagesToScroll,
currentPageIndexWithoutClones,
})
console.log('isPartialOffset', isPartialOffset)
offset = -currentPageIndex * pageWidth offset = -currentPageIndex * pageWidth
setTimeout(() => { setTimeout(() => {
@@ -315,7 +306,7 @@
if (currentPageIndex === 0) { if (currentPageIndex === 0) {
await showPage(pagesCount - clonesCount.total, { animated: false }) await showPage(pagesCount - clonesCount.total, { animated: false })
jumped = true jumped = true
} else if (currentPageIndex === pagesCount - clonesCount.head ) { } else if (currentPageIndex === pagesCount - clonesCount.tail) {
await showPage(clonesCount.head, { animated: false }) await showPage(clonesCount.head, { animated: false })
jumped = true jumped = true
} }
@@ -363,6 +354,7 @@
infinite, infinite,
pagesCount, pagesCount,
pagesToScroll, pagesToScroll,
clonesCountTail: clonesCount.tail,
}), }),
options, options,
) )

View File

@@ -40,12 +40,14 @@ function createStore() {
infinite, infinite,
pagesCount, pagesCount,
pagesToScroll, pagesToScroll,
clonesCountTail,
}) { }) {
update(store => { update(store => {
const newCurrentPageIndex = getNextPageIndexFn(infinite)({ const newCurrentPageIndex = getNextPageIndexFn(infinite)({
currentPageIndex: store.currentPageIndex, currentPageIndex: store.currentPageIndex,
pagesCount, pagesCount,
pagesToScroll, pagesToScroll,
clonesCountTail,
}) })
return { return {
...store, ...store,

View File

@@ -2,6 +2,7 @@ export function getNextPageIndexLimited({
currentPageIndex, currentPageIndex,
pagesCount, pagesCount,
pagesToScroll, pagesToScroll,
clonesCountTail,
}) { }) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1') 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 + pagesToScroll, 0), pagesCount - 1)
@@ -11,9 +12,10 @@ export function getNextPageIndexInfinte({
currentPageIndex, currentPageIndex,
pagesCount, pagesCount,
pagesToScroll, pagesToScroll,
clonesCountTail,
}) { }) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1') 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) return newCurrentPageIndex > pagesCount - 1 ? 0 : Math.max(newCurrentPageIndex, 0)
} }
@@ -36,7 +38,7 @@ export function getPrevPageIndexInfinte({
pagesToScroll, pagesToScroll,
}) { }) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1') 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 return newCurrentPageIndex >= 0 ? Math.min(newCurrentPageIndex, pagesCount - 1) : pagesCount - 1
} }
@@ -168,7 +170,6 @@ export function getPagesCountWithoutClones({
export function getClonesCount({ export function getClonesCount({
infinite, infinite,
// pagesToScroll,
pagesToShow, pagesToShow,
partialPageSize, partialPageSize,
}) { }) {
@@ -190,16 +191,3 @@ export function getClonesCount({
total: clonesCount.head + clonesCount.tail, total: clonesCount.head + clonesCount.tail,
} }
} }
export function getIsPartialOffset({
pagesCountWithoutClones,
headClonesCount,
pagesToScroll,
currentPageIndexWithoutClones,
}) {
return (
pagesCountWithoutClones + headClonesCount ===
currentPageIndexWithoutClones + pagesToScroll
)
}