Files
TREK/client/src/native/quickActions.ts
T
Maurice 80c04df4fc feat(native): swipe rows, long-press menus, placeholders while loading, fading pictures, iOS bounce and app icon quick actions
Packing items, tasks and expenses swipe sideways to their actions, as in
Mail or Reminders: done or open one way, delete and edit the other, the
first one run by a full swipe. They are second ways to what each row
already offers; an expense still asks before it goes.

A long press on a trip card lifts it and opens its menu with the card's own
actions. Plain confirmations in MConfirmSheet now also ask through the
system where the app can.

Lists, the atlas and a journey show grey placeholders in their shape while
loading instead of a spinner in an empty screen (MSkeleton); buttons keep
theirs. A picture still loading fades in once it is there; one from the
cache shows at once. In the iOS app the page bounces at its ends again,
except on screens with pull-to-refresh, whose pull it would race; Android
keeps its stretch off.

On iOS a long press on the app icon offers "New trip" and the trip coming
up by its name, set by the UI in its language (TrekShell.setQuickActions,
feature quickActions), and a tap opens it, also from a cold start.

The app's own CSS moves out of index.css into native/nativeApp.css, which
had outgrown its size budget.
2026-11-09 09:37:36 +01:00

54 lines
2.1 KiB
TypeScript

import type { TranslationFn, Trip } from '../types';
import { hasNativeFeature } from './capabilities';
import { isNativeApp } from './platform';
import { openPushTarget } from './push';
import { reportNativeFailure } from './reportFailure';
import { type NativeQuickAction, TrekShell } from './trekShell';
/**
* The quick actions a long press on the app icon shows, as in every iOS app:
* "New trip", and the trip coming up (or running today) by its name. Set by
* the UI, so they speak the app's language and follow the trips, and a tap
* opens the path each carries, the way a tap on a notification does. Only
* where the binary reports the feature `quickActions`.
*/
export function quickActionsActive(): boolean {
return isNativeApp() && hasNativeFeature('quickActions');
}
/** The actions for the trip the dashboard leads with (`hero`), or "New trip" alone without one. */
export function quickActionsFor(hero: Trip | null, today: string, t: TranslationFn): NativeQuickAction[] {
const items: NativeQuickAction[] = [
{ type: 'newTrip', title: t('dashboard.newTrip'), icon: 'add', path: '/dashboard?create=1' },
];
if (hero) {
const running = !!hero.start_date && hero.start_date <= today && (hero.end_date ?? hero.start_date) >= today;
items.push({
type: 'trip',
title: hero.title,
subtitle: running ? t('native.widget.today') : t('dashboard.nextTrip'),
icon: 'trip',
path: `/trips/${hero.id}`,
});
}
return items;
}
export async function publishQuickActions(items: NativeQuickAction[]): Promise<void> {
if (!quickActionsActive()) return;
await TrekShell.setQuickActions({ items }).catch(reportNativeFailure);
}
/** Opens the action the app was launched with, and every one chosen while it runs. */
export async function startQuickActions(): Promise<void> {
if (!quickActionsActive()) return;
void TrekShell.addListener('quickAction', ({ path }) => openPushTarget(path));
try {
const { path } = await TrekShell.takeQuickAction();
if (path) openPushTarget(path);
} catch (err) {
reportNativeFailure(err);
}
}