mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
80c04df4fc
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.
84 lines
3.0 KiB
TypeScript
84 lines
3.0 KiB
TypeScript
import { useTranslation } from '../../i18n';
|
|
|
|
/**
|
|
* Grey stand-ins in the shape of what is loading, where a native app shows the
|
|
* list before its content rather than a spinner in an empty screen: rows for a
|
|
* list, cards for a feed, a cover and lines for a detail page, a plain surface
|
|
* for a map. They pulse softly, and not at all with reduced motion. Announced
|
|
* once as "Loading" for a screen reader; the shapes themselves are hidden from it.
|
|
*/
|
|
|
|
export type MSkeletonVariant = 'rows' | 'cards' | 'detail' | 'map';
|
|
|
|
interface MSkeletonProps {
|
|
variant: MSkeletonVariant;
|
|
/** How many rows or cards (rows, cards). */
|
|
count?: number;
|
|
/** Rows as cards of their own (default), or as lines inside a card that already frames them. */
|
|
framed?: boolean;
|
|
className?: string;
|
|
}
|
|
|
|
const BLOCK = 'bg-[color:var(--m-ic)]';
|
|
// Lines of different lengths read as text; equal ones read as a table.
|
|
const WIDTHS = ['w-2/3', 'w-1/2', 'w-3/4', 'w-3/5'];
|
|
|
|
function Row({ i, framed }: { i: number; framed: boolean }) {
|
|
const frame = framed
|
|
? 'mb-2 rounded-[14px] border border-[color:var(--m-rowbr)] px-3 py-[10px]'
|
|
: 'border-b border-[color:var(--m-rowbr)] py-3 last:border-b-0';
|
|
return (
|
|
<div className={`flex items-center gap-[11px] ${frame}`}>
|
|
<span className={`h-9 w-9 flex-none rounded-[10px] ${BLOCK}`} />
|
|
<span className="min-w-0 flex-1">
|
|
<span className={`block h-3 rounded-full ${BLOCK} ${WIDTHS[i % WIDTHS.length]}`} />
|
|
<span className={`mt-2 block h-2.5 w-1/3 rounded-full ${BLOCK}`} />
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Card({ i }: { i: number }) {
|
|
return (
|
|
<div className="mb-3">
|
|
<div className={`h-[180px] w-full rounded-[22px] ${BLOCK}`} />
|
|
<span className={`mt-3 block h-3.5 rounded-full ${BLOCK} ${WIDTHS[i % WIDTHS.length]}`} />
|
|
<span className={`mt-2 block h-2.5 w-1/3 rounded-full ${BLOCK}`} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Detail() {
|
|
return (
|
|
<div>
|
|
<div className={`h-[300px] w-full ${BLOCK}`} />
|
|
<div className="px-4 pt-5">
|
|
<span className={`block h-5 w-2/3 rounded-full ${BLOCK}`} />
|
|
<span className={`mt-3 block h-3 w-1/3 rounded-full ${BLOCK}`} />
|
|
{WIDTHS.map((w) => (
|
|
<span key={w} className={`mt-4 block h-3 rounded-full ${BLOCK} ${w}`} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function MSkeleton({ variant, count = 4, framed = true, className = '' }: MSkeletonProps) {
|
|
const { t } = useTranslation();
|
|
const items = Array.from({ length: count }, (_, i) => i);
|
|
return (
|
|
<div
|
|
role="status"
|
|
aria-label={t('common.loading')}
|
|
className={`animate-pulse motion-reduce:animate-none ${className}`}
|
|
>
|
|
<div aria-hidden="true" className={variant === 'map' ? 'h-full' : undefined}>
|
|
{variant === 'rows' && items.map((i) => <Row key={i} i={i} framed={framed} />)}
|
|
{variant === 'cards' && items.map((i) => <Card key={i} i={i} />)}
|
|
{variant === 'detail' && <Detail />}
|
|
{variant === 'map' && <div className={`h-full w-full ${BLOCK}`} />}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|