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:
Maurice
2026-11-07 17:27:19 +01:00
parent 7083667cbf
commit 6906f80ff8
14 changed files with 255 additions and 17 deletions
@@ -7,7 +7,11 @@ import { usePluginStore } from '../../../src/store/pluginStore';
// FE-MOB-MSHELL-001 onwards
const fold = vi.hoisted(() => ({ current: null as null | { start: number; end: number } }));
vi.mock('../../../src/native/windowFold', () => ({ useWindowFold: () => fold.current }));
beforeEach(() => {
fold.current = null;
useAddonStore.setState({ addons: [], loaded: true });
usePluginStore.setState({ plugins: [], loaded: true });
});
@@ -117,4 +121,20 @@ describe('MobileShell', () => {
expect(content.className).toContain('overflow-y-auto');
expect(content.className).toContain('md:overflow-visible');
});
it('FE-MOB-MSHELL-008: a fold the Android app reports is where the panes meet', () => {
const { container, rerender } = render(
<MobileShell isPhone><p>page body</p></MobileShell>,
{ initialEntries: ['/dashboard'] },
);
const root = () => container.querySelector('.m-root') as HTMLElement;
expect(root().dataset.fold).toBeUndefined();
expect(root().style.getPropertyValue('--m-fold-start')).toBe('');
fold.current = { start: 420, end: 421 };
rerender(<MobileShell isPhone><p>page body</p></MobileShell>);
expect(root().dataset.fold).toBe('vertical');
expect(root().style.getPropertyValue('--m-fold-start')).toBe('420px');
expect(root().style.getPropertyValue('--m-fold-end')).toBe('421px');
});
});
@@ -193,9 +193,37 @@ describe('MKeyboardHost', () => {
});
});
describe('MKeyboardHost in the Android app', () => {
beforeEach(() => {
native.ios = false;
native.features = [];
native.setKeyCommands.mockClear();
useShortcutRegistry.setState({ lists: [] });
});
it('FE-MOB-KEYS-010: an Android shell with key commands takes the shortcuts too, the feature decides', async () => {
native.features = ['keyCommands'];
const run = vi.fn();
render(
<>
<MKeyboardHost />
<Probe owner="trip" shortcuts={[{ id: 'tab-plan', title: 'Plan', key: '1', mod: true, run }]} />
</>
);
await waitFor(() =>
expect(native.setKeyCommands).toHaveBeenLastCalledWith({
commands: [{ id: 'trip:tab-plan', title: 'Plan', input: '1', modifiers: ['command'] }],
})
);
fireEvent.keyDown(document.body, { key: '1', metaKey: true });
expect(run).not.toHaveBeenCalled();
});
});
describe('MShellShortcuts', () => {
beforeEach(() => {
native.ios = false;
native.features = [];
useShortcutRegistry.setState({ lists: [] });
usePluginStore.setState({ plugins: [], loaded: true });
useAddonStore.setState({
@@ -36,6 +36,9 @@ describe('size classes', () => {
ipad13SplitHalf: [683, 1032, true, false],
duoUnfoldedLandscape: [1017, 699, true, true],
duoUnfoldedPortrait: [699, 1017, true, false],
ipad11Portrait: [834, 1194, true, false],
androidFoldUnfoldedLandscape: [841, 701, true, true],
androidFoldUnfoldedPortrait: [701, 841, true, false],
};
for (const [name, [w, h, wide, split]] of Object.entries(sizes)) {
expect([name, evaluate(WIDE_QUERY, w, h)]).toEqual([name, wide]);