Files
opencode-manager/frontend/src/hooks/useNavigationDirection.ts
T
Chris Scott 9d94c333b4 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
2026-04-15 12:44:33 -04:00

43 lines
1.2 KiB
TypeScript

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])
}