Touch and scroll polish: chip rows own the horizontal axis, sheets lock an axis before following the finger and close on a flick, the slider drags relative to the knob, steppers repeat on hold, back-navigation restores the scroll position, a dropped row is tappable at once, the picker search stays above the keyboard, tappable rows work from the keyboard, bigger hit areas in the set row
This commit is contained in:
1 parent
e1fadadadb
commit
60df0cf0dd
19 files changed
+574
-88
No files matched your search
+27
-4
@@ -1,5 +1,5 @@
|
||||
import { useEffect } from 'react'
|
||||
import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation } from 'react-router-dom'
|
||||
import { useEffect, useLayoutEffect, useRef } from 'react'
|
||||
import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation, useNavigationType } from 'react-router-dom'
|
||||
import { useStore } from './store/useStore.js'
|
||||
import { useUI } from './store/useUI.js'
|
||||
import { bindUI } from './components/ui.jsx'
|
||||
@@ -28,6 +28,9 @@ import Library from './views/Library.jsx'
|
||||
import Settings from './views/Settings.jsx'
|
||||
import Admin from './views/Admin.jsx'
|
||||
|
||||
// last known scrollY per route, so back-navigation can put the page where it was
|
||||
const scrollPositions = new Map()
|
||||
|
||||
bindUI(useUI) // lets the shared controls open sheets without importing the store at module scope
|
||||
|
||||
// theme === 'system' follows the OS/browser preference instead of a fixed choice.
|
||||
@@ -46,6 +49,7 @@ function applyPrefs(theme, accent) {
|
||||
function Shell() {
|
||||
const navigate = useNavigate()
|
||||
const loc = useLocation()
|
||||
const navType = useNavigationType()
|
||||
const { S, user, ready } = useStore()
|
||||
const isGuest = useStore(s => s.isGuest())
|
||||
const needsMobileOnboarding = useStore(s => s.needsMobileOnboarding)
|
||||
@@ -64,8 +68,27 @@ function Shell() {
|
||||
}, [S.theme, S.accent])
|
||||
useEffect(() => { setLang(S.lang || 'en') }, [S.lang])
|
||||
useEffect(() => { document.documentElement.lang = S.lang || 'en' }, [langV, S.lang])
|
||||
// every tab/route change starts at the top of the page
|
||||
useEffect(() => { window.scrollTo(0, 0) }, [loc.pathname])
|
||||
// Forward navigation starts at the top; going back lands where you left off.
|
||||
// The position is recorded from scroll events rather than read at route
|
||||
// change, because by then a shorter page may already have clamped it.
|
||||
const pathRef = useRef(loc.pathname)
|
||||
useEffect(() => {
|
||||
const onScroll = () => {
|
||||
// Modals pins the body while a sheet is open; scrollY is 0 then, not a position.
|
||||
if (document.body.style.position === 'fixed') return
|
||||
scrollPositions.set(pathRef.current, window.scrollY)
|
||||
}
|
||||
window.addEventListener('scroll', onScroll, { passive: true })
|
||||
return () => window.removeEventListener('scroll', onScroll)
|
||||
}, [])
|
||||
useLayoutEffect(() => {
|
||||
pathRef.current = loc.pathname
|
||||
if (navType !== 'POP') { window.scrollTo(0, 0); return }
|
||||
const y = scrollPositions.get(loc.pathname) || 0
|
||||
// the restored view needs a layout pass before it is tall enough to scroll to y
|
||||
const frame = window.requestAnimationFrame(() => window.scrollTo(0, y))
|
||||
return () => window.cancelAnimationFrame(frame)
|
||||
}, [loc.pathname, navType])
|
||||
// bound to the workout, not to the route — checking Stats mid-session keeps the screen on
|
||||
useWakeLock(!!S.active && S.keepAwake !== false)
|
||||
|
||||
|
||||
Reference in new issue
Block a user