Skip to content

Commit

Permalink
fix: same fix as before
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Aug 19, 2024
1 parent 17471d8 commit a73c08f
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions packages/enhancer-gestures/src/gestures/pan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HookManager, Reader } from "@prose-reader/core"
import { Subject, filter, tap, withLatestFrom } from "rxjs"
import { EMPTY, Subject, switchMap, tap } from "rxjs"
import { GestureEvent, Hook } from "../types"
import { GesturesSettingsManager } from "../SettingsManager"
import { PanRecognizer } from "gesturx"
Expand All @@ -17,28 +17,32 @@ export const registerPan = ({
unhandledEvent$: Subject<GestureEvent>
settingsManager: GesturesSettingsManager
}) => {
const gestures$ = recognizer.events$.pipe(
withLatestFrom(settingsManager.values$),
filter(([, { panNavigation }]) => panNavigation === "pan"),
tap(([event]) => {
if (reader.zoom.isZooming) return

if (event.type === `panStart`) {
/**
* We let the user select
*/
if (event.delay > DELAY_IGNORE_PAN) return

reader?.navigation.moveTo({ x: 0, y: 0 }, { start: true })
}

if (event.type === `panMove`) {
reader?.navigation.moveTo({ x: event.deltaX, y: event.deltaY })
}

if (event.type === `panEnd`) {
reader?.navigation.moveTo({ x: event.deltaX, y: event.deltaY }, { final: true })
}
const gestures$ = settingsManager.values$.pipe(
switchMap(({ panNavigation }) => {
if (panNavigation !== "pan") return EMPTY

return recognizer.events$.pipe(
tap((event) => {
if (reader.zoom.isZooming) return

if (event.type === `panStart`) {
/**
* We let the user select
*/
if (event.delay > DELAY_IGNORE_PAN) return

reader?.navigation.moveTo({ x: 0, y: 0 }, { start: true })
}

if (event.type === `panMove`) {
reader?.navigation.moveTo({ x: event.deltaX, y: event.deltaY })
}

if (event.type === `panEnd`) {
reader?.navigation.moveTo({ x: event.deltaX, y: event.deltaY }, { final: true })
}
}),
)
}),
)

Expand Down

0 comments on commit a73c08f

Please sign in to comment.