// Building blocks shared by the widget layouts. They mirror the webmail pieces // the mockups copied: list rows, avatars, pills, event chips, buttons. // react-native-android-widget turns these into RemoteViews, so only its own // components (FlexWidget, TextWidget, SvgWidget, OverlapWidget) can appear. import React from 'react'; import { FlexWidget, ImageWidget, OverlapWidget, SvgWidget, TextWidget, type ColorProp, type FlexWidgetStyle, type TextWidgetStyle, } from 'react-native-android-widget'; import { chipBackground, normalizeHex, type WidgetPalette } from './theme'; import { filledIcon, icon, type FilledIconName, type IconName } from './icons'; import type { WidgetClick } from './clicks'; /** Corner radius of the widget surface; `widget_radius` in android/app/src/main/res/values/dimens.xml. */ export const WIDGET_RADIUS = 16; /** * The widget's background. Its edge and the clip to rounded corners come from * the root layout (android/app/src/main/res/layout/rn_widget.xml), which has the * launcher's real size; this bitmap is drawn at the reported one and can be cut off. */ export function Surface({ p, children, style, click, }: { p: WidgetPalette; children?: React.ReactNode; style?: FlexWidgetStyle; click?: WidgetClick; }) { return ( {children} ); } export function Txt({ text, color, size = 14, weight = '400', lines = 1, style, click, }: { text: string; color: ColorProp; size?: number; weight?: TextWidgetStyle['fontWeight']; lines?: number; style?: TextWidgetStyle; click?: WidgetClick; }) { return ( ); } export function Icon({ name, color, size = 16, style, click, }: { name: IconName; color: string; size?: number; style?: FlexWidgetStyle; click?: WidgetClick; }) { return ; } export function FilledIcon({ name, color, size = 14 }: { name: FilledIconName; color: string; size?: number }) { return ; } export function Spacer({ size, horizontal }: { size?: number; horizontal?: boolean }) { if (size === undefined) return ; return ; } export function Dot({ color, size = 8 }: { color: ColorProp; size?: number }) { return ; } export function Divider({ p }: { p: WidgetPalette }) { return ; } /** * The webmail's sender avatar: the contact photo or the sender's logo (on * white) when the snapshot has one (./avatar-images.ts), else the initials on * the hashed avatar colour. The initials are drawn underneath, so a picture * that does not draw still leaves them. */ export function Avatar({ initials, color, size = 32, ring, image, }: { initials: string; color: string; size?: number; /** Draws a ring in this colour, for stacked avatars. */ ring?: ColorProp; image?: { src: string; logo: boolean } | null; }) { const face = ( ); if (!image) return face; // Inside the ring, when there is one. const inner = ring ? size - 4 : size; return ( {face} ); } /** `rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium` */ export function Pill({ text, bg, color, size = 11, }: { text: string; bg: ColorProp; color: ColorProp; size?: number; }) { return ( ); } /** Month/week-view event chip: calendar colour at ~14%, 3dp left edge, text in the colour. */ export function EventChip({ title, time, color, height = 24, style, click, }: { title: string; time?: string; color: string; height?: number; style?: FlexWidgetStyle; click?: WidgetClick; }) { const hex = normalizeHex(color); return ( {time ? ( ) : null} ); } /** The 4dp colour bar the agenda puts between the time and the title. */ export function ColorBar({ color, height = 36 }: { color: string; height?: number }) { return ; } export function Button({ p, label, iconName, variant = 'outline', click, height = 32, flex, slop = 0, }: { p: WidgetPalette; label?: string; iconName?: IconName; variant?: 'primary' | 'outline'; click?: WidgetClick; height?: number; flex?: number; /** * Transparent tap area above and below the drawn button, so a 32dp button * still takes a 48dp tap. Take the same amount off the spacing around it. */ slop?: number | { top: number; bottom: number }; }) { const primary = variant === 'primary'; const [slopTop, slopBottom] = typeof slop === 'number' ? [slop, slop] : [slop.top, slop.bottom]; const fg = primary ? p.primaryFg : p.fg; const face = ( {iconName ? : null} {iconName && label ? : null} {label ? : null} ); if (!slop) return face; return ( {face} ); } /** Round primary action (compose, new event), the webmail's floating button. */ export function Fab({ p, iconName, size = 32, click, slop = 0, }: { p: WidgetPalette; iconName: IconName; size?: number; click?: WidgetClick; /** Transparent tap area around the button (see Button). */ slop?: number; }) { const face = ( ); if (!slop) return face; return ( {face} ); } /** Icon-only ghost button (search in a header). */ export function GhostIcon({ p, iconName, click, size = 32, }: { p: WidgetPalette; iconName: IconName; click?: WidgetClick; size?: number; }) { return ( ); } /** Widget header bar: icon, title, optional count, trailing actions, bottom rule. */ export function Header({ p, iconName, iconColor, title, count, trailing, height = 40, click, }: { p: WidgetPalette; iconName?: IconName; iconColor?: string; title: string; count?: string; trailing?: React.ReactNode; height?: number; click?: WidgetClick; }) { return ( {iconName ? : null} {iconName ? : null} {/* The title gives way (truncates) before the actions on the right. */} {count ? : null} {count ? : null} {trailing} ); } /** Uppercase section label (`text-xs font-medium uppercase tracking-wider`). */ export function SectionLabel({ p, text }: { p: WidgetPalette; text: string }) { return ( ); } /** Centred message for empty, signed-out and error states. */ export function Placeholder({ p, iconName, title, body, click, }: { p: WidgetPalette; iconName: IconName; title: string; body?: string; click?: WidgetClick; }) { return ( {body ? ( ) : null} ); } /** Wraps children so an absolutely placed dot/badge can sit on top (FrameLayout). */ export function Overlay({ children, style }: { children?: React.ReactNode; style?: FlexWidgetStyle }) { return {children}; }