mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(native): Android tablets get the shortcuts, two panes meet at a foldable's fold
The Android shell now reports keyCommands and windowLayout, so the large screen layout no longer assumes an iPad: - The keyboard host hands the shortcuts to the app whenever the shell has the keyCommands feature, whatever the platform. Before it also required iOS, so an Android tablet with a keyboard answered the keys in the page and never listed them in the system's shortcuts. - useWindowFold follows the layout the Android shell reports (feature windowLayout). When a vertical fold separates the window, a foldable half open like a book, MobileShell marks it with data-fold and its place, and the leading pane (the trip's plan, a tab's summary, a list beside its detail) ends at the fold while the trailing one starts there, on either reading direction. A flat fold that does not separate stays one screen. - The split size class starts at 840pt, Android's expanded width, instead of 900pt, so a foldable unfolded on its side (about 841dp) gets two panes like an iPad does. An 11" iPad upright (834pt) stays a single pane. The address screen of the native shell follows the same width. - TrekShell exports NativeWindowLayout for it. Also: the sheet's width and anchor types and the collab board type stay private to their modules, which nothing else imports (knip).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ReactNode, useRef } from 'react'
|
||||
import { CSSProperties, ReactNode, useRef } from 'react'
|
||||
import { useMatch } from 'react-router'
|
||||
import BottomNav from '../components/Layout/BottomNav'
|
||||
import ErrorBoundary from '../components/shared/ErrorBoundary'
|
||||
@@ -11,6 +11,7 @@ import MToastHost from './components/MToastHost'
|
||||
import MEdgeBack from './components/MEdgeBack'
|
||||
import { useNativeCapabilities } from '../native/capabilities'
|
||||
import { isNativeIos } from '../native/platform'
|
||||
import { useWindowFold } from '../native/windowFold'
|
||||
import './mobile.css'
|
||||
|
||||
interface MobileShellProps {
|
||||
@@ -46,6 +47,12 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
|
||||
// On a wide window (an iPad, a foldable unfolded) the rail on the leading edge
|
||||
// replaces the dock, and the page column starts after it.
|
||||
const wide = useIsWide()
|
||||
// A foldable's fold, as the Android app reports it: two-pane screens end their
|
||||
// leading pane there (mobile.css, data-fold).
|
||||
const fold = useWindowFold()
|
||||
const foldStyle = fold
|
||||
? ({ '--m-fold-start': `${fold.start}px`, '--m-fold-end': `${fold.end}px` } as CSSProperties)
|
||||
: undefined
|
||||
|
||||
if (!isPhone) {
|
||||
return (
|
||||
@@ -59,7 +66,7 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
|
||||
return (
|
||||
// min-h-svh, not min-h-dvh: dvh grows while Safari's toolbar retracts, so a
|
||||
// dvh page length would chase the animation it just triggered.
|
||||
<div className="m-root m-shell flex min-h-svh flex-col text-m-ink">
|
||||
<div className="m-root m-shell flex min-h-svh flex-col text-m-ink" data-fold={fold ? 'vertical' : undefined} style={foldStyle}>
|
||||
{/* Background and screen gradient live on their own viewport-sized layer.
|
||||
The shell root is as tall as the document now, and --m-scr is a radial
|
||||
gradient measured against its element box, so on it the light cone would
|
||||
|
||||
@@ -47,7 +47,7 @@ const DISCARD_BUTTON = 'rounded-full bg-danger px-4 py-2 text-body font-semibold
|
||||
* rather than a panel across the screen: compact for a short list of actions,
|
||||
* regular for a form, large for a sheet that holds a page of its own.
|
||||
*/
|
||||
export type MSheetWidth = 'compact' | 'regular' | 'large'
|
||||
type MSheetWidth = 'compact' | 'regular' | 'large'
|
||||
|
||||
// On a wide window (hooks/sizeClass.ts) a docked or floating sheet becomes
|
||||
// what iPadOS shows there: a form sheet centred over the dimmed page, as wide
|
||||
@@ -72,7 +72,7 @@ const POSITION: Record<MSheetVariant, string> = {
|
||||
* (the trip's More), the way iPadOS shows a menu next to the button that
|
||||
* opened it rather than in the middle of the screen.
|
||||
*/
|
||||
export type MSheetWideAnchor = 'center' | 'rail-foot'
|
||||
type MSheetWideAnchor = 'center' | 'rail-foot'
|
||||
const WIDE_ANCHOR: Record<MSheetWideAnchor, string> = {
|
||||
center: WIDE_POSITION,
|
||||
'rail-foot': 'wide:top-auto wide:translate-y-0 wide:end-auto wide:bottom-[calc(env(safe-area-inset-bottom,0px)+12px)] wide:start-[calc(var(--m-rail-w)+6px)]',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNativeCapabilities } from '../../native/capabilities';
|
||||
import { isNativeIos } from '../../native/platform';
|
||||
import { reportNativeFailure } from '../../native/reportFailure';
|
||||
import { TrekShell } from '../../native/trekShell';
|
||||
import { findShortcut, toNativeCommand, useShortcutRegistry } from './shortcuts';
|
||||
@@ -8,14 +7,16 @@ import { findShortcut, toNativeCommand, useShortcutRegistry } from './shortcuts'
|
||||
/**
|
||||
* Answers the touch shell's keyboard shortcuts (useShortcuts), once for every
|
||||
* screen. In a browser it listens for the keys itself. In the app the binary
|
||||
* takes them over as native key commands when it can (feature keyCommands),
|
||||
* which puts them in the overlay a held ⌘ shows and in the iPadOS menu bar;
|
||||
* the page then leaves those keys alone, so nothing runs twice.
|
||||
* takes them over as native key commands when it can (feature keyCommands):
|
||||
* on iOS they show in the overlay a held ⌘ shows and in the iPadOS menu bar,
|
||||
* on Android in the system's keyboard shortcuts list. The page then leaves
|
||||
* those keys alone, so nothing runs twice. Only a shell that has the feature
|
||||
* reports it, so the feature alone decides, whatever the platform.
|
||||
*/
|
||||
export default function MKeyboardHost() {
|
||||
const lists = useShortcutRegistry((s) => s.lists);
|
||||
const { caps } = useNativeCapabilities();
|
||||
const native = isNativeIos() && caps.features.includes('keyCommands');
|
||||
const native = caps.features.includes('keyCommands');
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
|
||||
@@ -589,6 +589,24 @@
|
||||
--m-pane-trail-w: env(viewport-segment-width 1 0, 50vw);
|
||||
}
|
||||
}
|
||||
/* The Android app reports a foldable's fold itself (native/windowFold.ts):
|
||||
MobileShell marks a vertical fold that separates the window with data-fold
|
||||
and its place in --m-fold-start/--m-fold-end, and the panes meet there. The
|
||||
leading side follows the reading direction, the fold's place does not. */
|
||||
.m-root[data-fold='vertical'] {
|
||||
--m-pane-aside-w: calc(var(--m-fold-start) - var(--m-rail-w, 0px));
|
||||
--m-pane-trail-w: calc(100vw - var(--m-fold-end));
|
||||
}
|
||||
.m-root[data-fold='vertical'] .m-trip {
|
||||
--trip-pane-open: calc(var(--m-fold-start) - var(--m-rail-w, 0px));
|
||||
}
|
||||
:root[dir='rtl'] .m-root[data-fold='vertical'] {
|
||||
--m-pane-aside-w: calc(100vw - var(--m-fold-end) - var(--m-rail-w, 0px));
|
||||
--m-pane-trail-w: var(--m-fold-start);
|
||||
}
|
||||
:root[dir='rtl'] .m-root[data-fold='vertical'] .m-trip {
|
||||
--trip-pane-open: calc(100vw - var(--m-fold-end) - var(--m-rail-w, 0px));
|
||||
}
|
||||
.m-pane-aside {
|
||||
width: var(--m-pane-aside-w);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { MTripCollabTab } from '../MTripShell';
|
||||
|
||||
/** The collab boards that can stand beside the chat: everything but the chat itself. */
|
||||
const BOARD_TABS = ['notes', 'links', 'polls'] as const;
|
||||
export type CollabBoardTab = (typeof BOARD_TABS)[number];
|
||||
type CollabBoardTab = (typeof BOARD_TABS)[number];
|
||||
|
||||
/** Whether a collab tab is one of the boards (not the chat, nor a tab this screen does not know). */
|
||||
export function isCollabBoard(tab: string): tab is CollabBoardTab {
|
||||
|
||||
Reference in New Issue
Block a user