mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(mobile): sheets that drag, fling and rise like native ones
The docked sheet could only be pulled by an invisible 20px strip, re-rendered React on every finger move, and a flick sprang back to the top before fading out. A finger on the content now carries the sheet once the content is at its top, the panel moves through direct style writes, and a dismissing release throws it off screen from where it was let go, faster the harder the flick. With unsaved changes it springs back and asks instead. Pulling up only stretches a little. The docked sheet now rises from below the screen edge and sinks back there, and the floating card pops in place the way a native alert does.
This commit is contained in:
@@ -22,15 +22,21 @@ export function useDiscardGuard(guard: unknown, onClose: () => void) {
|
||||
if (guardRef.current !== undefined && baseline.current === null) baseline.current = snapshot(guardRef.current)
|
||||
}, [])
|
||||
|
||||
/** Whether a way out right now would stop to ask rather than close. */
|
||||
const wouldAsk = useCallback(
|
||||
() => guardRef.current !== undefined && baseline.current !== null && snapshot(guardRef.current) !== baseline.current,
|
||||
[],
|
||||
)
|
||||
|
||||
const requestClose = useCallback(() => {
|
||||
if (guardRef.current !== undefined && baseline.current !== null && snapshot(guardRef.current) !== baseline.current) setAsking(true)
|
||||
if (wouldAsk()) setAsking(true)
|
||||
else onClose()
|
||||
}, [onClose])
|
||||
}, [onClose, wouldAsk])
|
||||
|
||||
const keepEditing = useCallback(() => setAsking(false), [])
|
||||
const discard = useCallback(() => { setAsking(false); onClose() }, [onClose])
|
||||
/** Forget the starting point, for a surface that stays mounted between openings. */
|
||||
const reset = useCallback(() => { baseline.current = null; setAsking(false) }, [])
|
||||
|
||||
return { asking, markStart, requestClose, keepEditing, discard, reset }
|
||||
return { asking, markStart, requestClose, wouldAsk, keepEditing, discard, reset }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user