Skip to content
Open
Show file tree
Hide file tree
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
38 changes: 19 additions & 19 deletions packages/app-expo/assets/reader/reader.html

Large diffs are not rendered by default.

47 changes: 46 additions & 1 deletion packages/foliate-js/paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,47 @@ export class Paginator extends HTMLElement {
pv.element.style.willChange = 'transform'
}
}
#onScrolledTouchMove(e, state) {
if (e.touches.length > 1) return
const touch = e.changedTouches[0]
if (!touch) return

const x = touch.screenX
const y = touch.screenY
const totalDx = Math.abs(x - (state.startX ?? x))
const totalDy = Math.abs(y - (state.startY ?? y))
const primaryTotal = this.#vertical ? totalDx : totalDy
const crossTotal = this.#vertical ? totalDy : totalDx

if (primaryTotal < 2 || primaryTotal < crossTotal) {
state.x = x
state.y = y
state.t = e.timeStamp
return
}

const dx = state.x - x
const dy = state.y - y
state.x = x
state.y = y
state.t = e.timeStamp

const delta = this.#vertical ? -dx : dy
if (Math.abs(delta) < 0.5) return

e.preventDefault()
this.#touchScrolled = true

const previous = this.containerPosition
this.containerPosition = previous + delta
const moved = Math.abs(this.containerPosition - previous) >= 0.5

if (!moved && Math.abs(delta) > 2) {
const forward = this.#vertical ? delta < 0 : delta > 0
if (forward && !this.atEnd) void this.next()
else if (!forward && !this.atStart) void this.prev()
}
}
#onTouchMove(e) {
const state = this.#touchState
if (this.#navigationLocked || !state) return
Expand All @@ -1829,7 +1870,11 @@ export class Paginator extends HTMLElement {
}
if (state.pinched) return
state.pinched = globalThis.visualViewport.scale > 1
if (this.scrolled || state.pinched) return
if (state.pinched) return
if (this.scrolled) {
this.#onScrolledTouchMove(e, state)
return
}
// When the host opts out of swipe-to-paginate, let touch events reach
// native behavior (text selection, etc.) without us tracking or
// pre-empting them.
Expand Down