mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
- 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
43 lines
1.2 KiB
TypeScript
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])
|
|
}
|