Skip to content

Commit

Permalink
fix: swipe conflict with drawing, close #347
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 17, 2021
1 parent ca19681 commit d521828
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/client/logic/nav.ts
@@ -1,8 +1,9 @@
import { computed, Ref, ref, nextTick } from 'vue'
import { isString, SwipeDirection, timestamp, useSwipe } from '@vueuse/core'
import { isString, SwipeDirection, timestamp, usePointerSwipe } from '@vueuse/core'
import { rawRoutes, router } from '../routes'
import { configs } from '../env'
import { useRouteQuery } from './route'
import { isDrawing } from './drawings'

export { rawRoutes, router }

Expand Down Expand Up @@ -91,15 +92,24 @@ export function go(page: number, clicks?: number) {

export function useSwipeControls(root: Ref<HTMLElement | undefined>) {
const swipeBegin = ref(0)
const { direction, lengthX, lengthY } = useSwipe(root, {
onSwipeStart() {
const { direction, distanceX, distanceY } = usePointerSwipe(root, {
onSwipeStart(e) {
if (e.pointerType !== 'touch')
return
if (isDrawing.value)
return
swipeBegin.value = timestamp()
},
onSwipeEnd() {
onSwipeEnd(e) {
if (e.pointerType !== 'touch')
return
if (!swipeBegin.value)
return
const x = Math.abs(lengthX.value)
const y = Math.abs(lengthY.value)
if (isDrawing.value)
return

const x = Math.abs(distanceX.value)
const y = Math.abs(distanceY.value)
if (x / window.innerWidth > 0.3 || x > 100) {
if (direction.value === SwipeDirection.LEFT)
next()
Expand Down

0 comments on commit d521828

Please sign in to comment.