fix: Disabled pane gesture navigation by default and moved it to Labs since it is unstable

This commit is contained in:
Aman Harwara
2023-03-15 17:05:41 +05:30
parent ddc290e302
commit 636de8fada
4 changed files with 42 additions and 7 deletions

View File

@@ -2,18 +2,29 @@ import { useStateRef } from '@/Hooks/useStateRef'
import { useEffect, useRef, useState } from 'react'
import { Direction, Pan, PointerListener, type GestureEventData } from 'contactjs'
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
import { useApplication } from '../ApplicationProvider'
import { ApplicationEvent, PrefKey } from '@standardnotes/snjs'
export const usePaneSwipeGesture = (
direction: 'left' | 'right',
onSwipeEnd: (element: HTMLElement) => void,
gesture: 'pan' | 'swipe' = 'pan',
) => {
const application = useApplication()
const overlayElementRef = useRef<HTMLElement | null>(null)
const [element, setElement] = useState<HTMLElement | null>(null)
const onSwipeEndRef = useStateRef(onSwipeEnd)
const isMobileScreen = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.sm)
const [isEnabled, setIsEnabled] = useState(() => application.getPreference(PrefKey.PaneGesturesEnabled, false))
useEffect(() => {
return application.addSingleEventObserver(ApplicationEvent.PreferencesChanged, async () => {
setIsEnabled(application.getPreference(PrefKey.PaneGesturesEnabled, false))
})
}, [application])
useEffect(() => {
if (!element) {
return
@@ -23,6 +34,10 @@ export const usePaneSwipeGesture = (
return
}
if (!isEnabled) {
return
}
const panRecognizer = new Pan(element, {
supportedDirections: direction === 'left' ? [Direction.Left] : [Direction.Right],
})
@@ -144,7 +159,7 @@ export const usePaneSwipeGesture = (
}
}
}
}, [direction, element, gesture, isMobileScreen, onSwipeEndRef])
}, [direction, element, gesture, isMobileScreen, onSwipeEndRef, isEnabled])
return [setElement]
}