Files
TREK/client/src/mobile/useIsPhone.ts
T
Maurice c204a25a9c feat(mobile): the touch shell laid out for iPad and unfolded foldables
The app shows the touch shell at every size now, an iPad's and an unfolded
foldable's included, instead of switching to the desktop pages from 768px.
One route tree survives rotation, Split View, Stage Manager and folding, and
the app's own features (Wallet, sharing into a trip, the edge swipe back)
are there on the big screen too.

Two size classes drive the layout (hooks/sizeClass.ts, Tailwind variants
wide: and split:):

- wide (600pt and taller than a phone on its side): a glass navigation rail
  on the leading edge replaces the dock and holds every destination with its
  name; sheets become centred form sheets; the trip's More menu is a popover
  beside the rail; lists keep a readable measure; dashboard, journey and
  vacay get columns; full-bleed maps run under the floating rail.
- split (900pt): the trip's plan, places or road trip chain sit in a pane
  beside the map, which follows the plan's day; the list/map switch hides
  and shows the pane like a sidebar; on a foldable that reports its fold the
  pane ends at the fold. Settings show their sections beside the page and the
  dashboard keeps its widgets in a column of their own.

A hardware keyboard gets the shortcuts an iPad app has (⌘1 to ⌘9 for the
sections, ⌘N, ⌘, , ⌥←/⌥→ through the days, ⌃⌘S for the pane, ⌘[ back),
answered by the page or, with a binary that has the keyCommands feature,
handed to it as native key commands.

The day strip fades at an edge that runs on, journey cards grow on a wide
window and a card without a photo takes the day's colour, and the Leaflet
map measures itself again when its box changes size.
2026-11-07 23:25:12 +01:00

51 lines
2.1 KiB
TypeScript

import { useState, useEffect } from 'react'
import { isNativeApp } from '../native/platform'
/**
* The phone shell's viewport: narrower than the md breakpoint (768px), or a
* touch screen short enough to be a phone on its side.
*
* Width alone flipped a phone into the desktop planner the moment it was
* turned: most phones are wider than 767px in landscape. That swapped the
* whole route tree, so an open sheet, what was typed into it and the map's
* position were gone. A tablet stays where it was, since none is under 500px
* tall, and a desktop window keeps following its width, since its pointer is
* fine.
*
* The phone rules in `index.css` repeat this query; keep them in step.
*
* The app is the exception: inside it the phone shell applies at every size.
* An iPad, an iPad in Split View or Stage Manager and a foldable unfolded all
* get the touch shell, laid out for their width (see `hooks/sizeClass.ts`), never
* the desktop pages. Only that keeps one route tree across a fold, a
* rotation or a window resize, so nothing open or typed is lost, and only the
* touch shell has the app's own features (Wallet, sharing into a trip, the
* edge swipe back).
*/
export const PHONE_QUERY = '(max-width: 767px), (pointer: coarse) and (max-height: 500px)'
/** Whether the phone shell applies right now, for code that is not a component. */
export function isPhoneViewport(): boolean {
if (isNativeApp()) return true
return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(PHONE_QUERY).matches
}
/**
* True while the phone shell applies (see {@link PHONE_QUERY}). Reactive:
* follows viewport resizes and orientation changes via matchMedia.
*/
export function useIsPhone(): boolean {
const [isPhone, setIsPhone] = useState(isPhoneViewport)
useEffect(() => {
if (isNativeApp()) return
const mq = window.matchMedia(PHONE_QUERY)
const handler = (e: MediaQueryListEvent) => setIsPhone(e.matches)
setIsPhone(mq.matches)
mq.addEventListener('change', handler)
return () => mq.removeEventListener('change', handler)
}, [])
return isPhone
}