mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add mobile swipe-back navigation and gestures
- Implement swipe-to-close for mobile modals and dialogs - Add PageTransition component with push/pop animations - Create navigation store for managing navigation state - Add useNavigationDirection hook for animation direction - Implement useSwipeToClose hook for swipe gestures - Add prefers-reduced-motion accessibility support - Create FileBrowserSheet component for mobile file browser - Add comprehensive tests for swipe behavior and navigation - Update FileBrowser, Dialog, and BackButton components - Configure Vite for proper CSS handling
This commit is contained in:
1 parent
46731210e8
commit
9d94c333b4
23 files changed
+1684
-161
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useLocation, useNavigationType } from 'react-router-dom'
|
||||
import { useNavigationStore } from '@/stores/navigationStore'
|
||||
|
||||
const ANIMATION_DURATION = 300
|
||||
|
||||
export function useNavigationDirection() {
|
||||
const location = useLocation()
|
||||
const navType = useNavigationType()
|
||||
const setDirection = useNavigationStore((s) => s.setDirection)
|
||||
const setPhase = useNavigationStore((s) => s.setPhase)
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined)
|
||||
const isFirstRender = useRef(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (isFirstRender.current) {
|
||||
isFirstRender.current = false
|
||||
return
|
||||
}
|
||||
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current)
|
||||
}
|
||||
|
||||
const direction = navType === 'PUSH' ? 'push' : navType === 'POP' ? 'pop' : 'none'
|
||||
setDirection(direction)
|
||||
|
||||
if (direction !== 'none') {
|
||||
setPhase('entering')
|
||||
timerRef.current = setTimeout(() => {
|
||||
setPhase('idle')
|
||||
setDirection('none')
|
||||
}, ANIMATION_DURATION)
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current)
|
||||
}
|
||||
}
|
||||
}, [location.pathname, navType, setDirection, setPhase])
|
||||
}
|
||||
Reference in new issue
Block a user