Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): add shared UI components
Richie McIlroy96d8d585c341
diff --git a/apps/mobile/src/components/ActionButton.test.tsx b/apps/mobile/src/components/ActionButton.test.tsxnew file mode 100644index 000000000..c735962be--- /dev/null+++ b/apps/mobile/src/components/ActionButton.test.tsx@@ -0,0 +1,147 @@+import type { ReactElement, ReactNode } from "react";+import TestRenderer, { act, type ReactTestRenderer } from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import { ActionButton } from "./ActionButton";++type HostProps = {+ children?: ReactNode;+ [key: string]: unknown;+};++const renderComponent = async (+ node: ReactElement,+): Promise<ReactTestRenderer> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return renderer as unknown as ReactTestRenderer;+};++(+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const resolveStyle = (style: unknown): Record<string, unknown> => {+ const resolved =+ typeof style === "function" ? style({ pressed: false }) : style;+ const styles = Array.isArray(resolved) ? resolved : [resolved];+ return Object.assign({}, ...styles.filter(Boolean));+};++vi.mock("react-native", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ ActivityIndicator: createHost("ActivityIndicator"),+ Pressable: createHost("Pressable"),+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ hairlineWidth: 1,+ },+ Text: createHost("Text"),+ View: createHost("View"),+ };+});++vi.mock("expo-symbols", async () => {+ const React = await import("react");+ return {+ SymbolView: (props: Record<string, unknown>) =>+ React.createElement("SymbolView", props),+ };+});++describe("ActionButton", () => {+ it("matches the Cap web dark button surface and clips the inset highlight", async () => {+ const renderer = await renderComponent(+ <ActionButton+ label="Upload"+ onPress={vi.fn()}+ accessibilityHint="Opens upload options"+ symbol="square.and.arrow.up"+ variant="dark"+ />,+ );+ const button = renderer.root.findByProps({+ accessibilityLabel: "Upload",+ });++ expect(button.props.android_ripple).toEqual({+ color: "rgba(18, 22, 31, 0.05)",+ });+ expect(button.props.hitSlop).toEqual({+ bottom: 4,+ left: 4,+ right: 4,+ top: 4,+ });+ expect(button.props.accessibilityState).toEqual({+ busy: false,+ disabled: false,+ });+ expect(button.props.accessibilityHint).toBe("Opens upload options");+ expect(resolveStyle(button.props.style)).toMatchObject({+ backgroundColor: "#202020",+ borderColor: "#202020",+ borderRadius: 999,+ height: 44,+ overflow: "hidden",+ });+ });++ it("uses the Cap web gray button token pair", async () => {+ const renderer = await renderComponent(+ <ActionButton label="Photos" onPress={vi.fn()} variant="gray" />,+ );+ const button = renderer.root.findByProps({+ accessibilityLabel: "Photos",+ });++ expect(resolveStyle(button.props.style)).toMatchObject({+ backgroundColor: "#e0e0e0",+ borderColor: "#bbbbbb",+ });+ });++ it("allows a specific native label while keeping short visible text", async () => {+ const renderer = await renderComponent(+ <ActionButton+ label="Retry"+ accessibilityLabel="Retry upload failed-upload.mp4"+ accessibilityValue={{ text: "Upload failed" }}+ onPress={vi.fn()}+ variant="secondary"+ />,+ );+ const button = renderer.root.findByProps({+ accessibilityLabel: "Retry upload failed-upload.mp4",+ });++ expect(button.findByProps({ children: "Retry" }).props.children).toBe(+ "Retry",+ );+ expect(button.props.accessibilityValue).toEqual({+ text: "Upload failed",+ });+ });++ it("exposes native disabled and busy state while loading", async () => {+ const renderer = await renderComponent(+ <ActionButton label="Upload" loading onPress={vi.fn()} variant="blue" />,+ );+ const button = renderer.root.findByProps({+ accessibilityLabel: "Upload",+ });++ expect(button.props.disabled).toBe(true);+ expect(button.props.accessibilityState).toEqual({+ busy: true,+ disabled: true,+ });+ });+});diff --git a/apps/mobile/src/components/ActionButton.tsx b/apps/mobile/src/components/ActionButton.tsxnew file mode 100644index 000000000..d12855f23--- /dev/null+++ b/apps/mobile/src/components/ActionButton.tsx@@ -0,0 +1,320 @@+import { type SFSymbol, SymbolView } from "expo-symbols";+import type { ReactNode } from "react";+import {+ type AccessibilityValue,+ ActivityIndicator,+ type GestureResponderEvent,+ Pressable,+ StyleSheet,+ Text,+ View,+ type ViewStyle,+} from "react-native";+import { colors, fonts, radius, squircle } from "@/theme";++type ActionButtonProps = {+ label: string;+ onPress: (event?: GestureResponderEvent) => void;+ accessibilityLabel?: string;+ accessibilityHint?: string;+ accessibilityValue?: AccessibilityValue;+ symbol?: SFSymbol;+ leading?: ReactNode;+ variant?:+ | "primary"+ | "blue"+ | "secondary"+ | "gray"+ | "dark"+ | "danger"+ | "ghost";+ size?: "sm" | "md" | "lg";+ disabled?: boolean;+ loading?: boolean;+ style?: ViewStyle;+ children?: ReactNode;+};++const labelBySize = {+ sm: "labelSm",+ md: "labelMd",+ lg: "labelLg",+} as const;++const iconColor = (+ variant: NonNullable<ActionButtonProps["variant"]>,+ isDisabled: boolean,+) => {+ if (isDisabled) {+ if (variant === "primary") return colors.gray9;+ if (variant === "blue" || variant === "dark" || variant === "danger") {+ return colors.gray10;+ }+ if (variant === "gray") return colors.gray11;+ }++ return variant === "primary" ||+ variant === "blue" ||+ variant === "dark" ||+ variant === "danger"+ ? colors.white+ : colors.gray12;+};++const usesInsetHighlight = (+ variant: NonNullable<ActionButtonProps["variant"]>,+) =>+ variant === "primary" ||+ variant === "blue" ||+ variant === "gray" ||+ variant === "dark";++const buttonHitSlop = { bottom: 4, left: 4, right: 4, top: 4 };+const androidRipple = { color: colors.blackAlpha5 };++export function ActionButton({+ label,+ onPress,+ accessibilityLabel,+ accessibilityHint,+ accessibilityValue,+ symbol,+ leading,+ variant = "primary",+ size = "md",+ disabled = false,+ loading = false,+ style,+ children,+}: ActionButtonProps) {+ const isDisabled = disabled || loading;+ const showInsetHighlight = usesInsetHighlight(variant);++ return (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={accessibilityLabel ?? label}+ accessibilityHint={accessibilityHint}+ accessibilityState={{ busy: loading, disabled: isDisabled }}+ accessibilityValue={accessibilityValue}+ android_ripple={androidRipple}+ hitSlop={buttonHitSlop}+ onPress={onPress}+ disabled={isDisabled}+ style={({ pressed }) => [+ styles.base,+ styles[size],+ styles[variant],+ isDisabled && styles[`${variant}Disabled`],+ pressed && !isDisabled && pressedStyles[variant],+ style,+ ]}+ >+ {showInsetHighlight ? (+ <View pointerEvents="none" style={styles.insetHighlight} />+ ) : null}+ {loading ? (+ <ActivityIndicator color={iconColor(variant, isDisabled)} />+ ) : leading ? (+ leading+ ) : symbol ? (+ <SymbolView+ name={symbol}+ size={18}+ tintColor={iconColor(variant, isDisabled)}+ type="monochrome"+ weight="semibold"+ />+ ) : null}+ <Text+ numberOfLines={1}+ adjustsFontSizeToFit+ style={[+ styles.label,+ styles[labelBySize[size]],+ variant === "primary" ||+ variant === "blue" ||+ variant === "dark" ||+ variant === "danger"+ ? styles.primaryLabel+ : styles.defaultLabel,+ isDisabled && styles[`${variant}DisabledLabel`],+ ]}+ >+ {children ?? label}+ </Text>+ </Pressable>+ );+}++const styles = StyleSheet.create({+ base: {+ alignItems: "center",+ justifyContent: "center",+ flexDirection: "row",+ gap: 4,+ position: "relative",+ borderWidth: StyleSheet.hairlineWidth,+ overflow: "hidden",+ ...squircle,+ },+ sm: {+ height: 40,+ borderRadius: radius.full,+ paddingHorizontal: 20,+ },+ md: {+ height: 44,+ borderRadius: radius.full,+ paddingHorizontal: 20,+ },+ lg: {+ height: 48,+ borderRadius: radius.full,+ paddingHorizontal: 20,+ },+ primary: {+ backgroundColor: colors.gray12,+ borderColor: colors.gray12,+ },+ primaryPressed: {+ backgroundColor: colors.gray11,+ borderColor: colors.gray11,+ },+ blue: {+ backgroundColor: colors.buttonBlue,+ borderColor: colors.buttonBlueBorder,+ },+ bluePressed: {+ backgroundColor: colors.buttonBlueHover,+ borderColor: colors.buttonBlueBorder,+ },+ dark: {+ backgroundColor: colors.gray12,+ borderColor: colors.gray12,+ },+ darkPressed: {+ backgroundColor: colors.gray11,+ borderColor: colors.gray11,+ },+ secondary: {+ backgroundColor: colors.gray3,+ borderColor: colors.gray5,+ },+ secondaryPressed: {+ backgroundColor: colors.gray5,+ borderColor: colors.gray6,+ },+ gray: {+ backgroundColor: colors.gray5,+ borderColor: colors.gray8,+ },+ grayPressed: {+ backgroundColor: colors.gray7,+ borderColor: colors.gray8,+ },+ danger: {+ backgroundColor: colors.red9,+ borderColor: colors.red9,+ },+ dangerPressed: {+ backgroundColor: colors.red10,+ borderColor: colors.red10,+ },+ ghost: {+ backgroundColor: "transparent",+ borderColor: "transparent",+ },+ ghostPressed: {+ backgroundColor: colors.blackAlpha5,+ borderColor: "transparent",+ },+ primaryDisabled: {+ backgroundColor: colors.gray6,+ borderColor: colors.gray6,+ },+ blueDisabled: {+ backgroundColor: colors.gray7,+ borderColor: colors.gray8,+ },+ darkDisabled: {+ backgroundColor: colors.gray7,+ borderColor: colors.gray8,+ },+ secondaryDisabled: {+ backgroundColor: colors.gray8,+ borderColor: colors.gray8,+ },+ grayDisabled: {+ backgroundColor: colors.gray8,+ borderColor: colors.gray7,+ },+ dangerDisabled: {+ backgroundColor: colors.gray7,+ borderColor: colors.gray8,+ },+ ghostDisabled: {+ backgroundColor: "transparent",+ borderColor: "transparent",+ },+ label: {+ fontFamily: fonts.medium,+ },+ labelSm: {+ fontSize: 14,+ lineHeight: 18,+ },+ labelMd: {+ fontSize: 14,+ lineHeight: 20,+ },+ labelLg: {+ fontSize: 16,+ lineHeight: 22,+ },+ primaryLabel: {+ color: colors.white,+ },+ defaultLabel: {+ color: colors.gray12,+ },+ primaryDisabledLabel: {+ color: colors.gray9,+ },+ blueDisabledLabel: {+ color: colors.gray10,+ },+ darkDisabledLabel: {+ color: colors.gray10,+ },+ secondaryDisabledLabel: {+ color: colors.gray11,+ },+ grayDisabledLabel: {+ color: colors.gray11,+ },+ dangerDisabledLabel: {+ color: colors.gray10,+ },+ ghostDisabledLabel: {+ color: colors.gray9,+ },+ insetHighlight: {+ position: "absolute",+ top: 0,+ left: 0,+ right: 0,+ height: 1.5,+ backgroundColor: "rgba(255, 255, 255, 0.4)",+ },+});++const pressedStyles = {+ primary: styles.primaryPressed,+ blue: styles.bluePressed,+ secondary: styles.secondaryPressed,+ gray: styles.grayPressed,+ dark: styles.darkPressed,+ danger: styles.dangerPressed,+ ghost: styles.ghostPressed,+} as const;diff --git a/apps/mobile/src/components/CapCard.test.ts b/apps/mobile/src/components/CapCard.test.tsnew file mode 100644index 000000000..fc441d203--- /dev/null+++ b/apps/mobile/src/components/CapCard.test.ts@@ -0,0 +1,521 @@+import { Video } from "@cap/web-domain";+import React, { type ReactElement, type ReactNode } from "react";+import TestRenderer, {+ act,+ type ReactTestRenderer,+ type ReactTestRendererJSON,+} from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import type { MobileCapSummary } from "@/api/mobile";+import { CapCard } from "./CapCard";+import { getCapCardViewModel } from "./capCardViewModel";++type HostProps = {+ children?: ReactNode;+ [key: string]: unknown;+};++type JsonNode = ReactTestRendererJSON | ReactTestRendererJSON[] | string | null;++(+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const renderTree = async (node: ReactElement): Promise<JsonNode> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return (renderer as ReactTestRenderer | null)?.toJSON() ?? null;+};++const renderComponent = async (+ node: ReactElement,+): Promise<ReactTestRenderer> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return renderer as unknown as ReactTestRenderer;+};++const getTextNodes = (node: JsonNode): string[] => {+ if (!node) return [];+ if (typeof node === "string") return [node];+ if (Array.isArray(node)) return node.flatMap(getTextNodes);+ return node.children?.flatMap(getTextNodes) ?? [];+};++const hasProp = (node: JsonNode, prop: string, value: unknown): boolean => {+ if (!node || typeof node === "string") return false;+ if (Array.isArray(node))+ return node.some((item) => hasProp(item, prop, value));+ if (node.props[prop] === value) return true;+ return node.children?.some((child) => hasProp(child, prop, value)) ?? false;+};++const resolveStyle = (+ style: unknown,+ pressed = false,+): Record<string, unknown> => {+ const resolved = typeof style === "function" ? style({ pressed }) : style;+ const styles = Array.isArray(resolved) ? resolved : [resolved];+ return Object.assign({}, ...styles.filter(Boolean));+};++vi.mock("react-native", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ ActivityIndicator: createHost("ActivityIndicator"),+ Pressable: createHost("Pressable"),+ StyleSheet: {+ absoluteFillObject: {+ bottom: 0,+ left: 0,+ position: "absolute",+ right: 0,+ top: 0,+ },+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ hairlineWidth: 1,+ },+ Text: createHost("Text"),+ View: createHost("View"),+ };+});++vi.mock("expo-image", async () => {+ const React = await import("react");+ return {+ Image: (props: Record<string, unknown>) =>+ React.createElement("Image", props),+ };+});++vi.mock("expo-symbols", async () => {+ const React = await import("react");+ return {+ SymbolView: (props: Record<string, unknown>) =>+ React.createElement("SymbolView", props),+ };+});++vi.mock("react-native-svg", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ default: createHost("Svg"),+ Circle: createHost("Circle"),+ };+});++const cap: MobileCapSummary = {+ id: Video.VideoId.make("video_123"),+ shareUrl: "https://cap.so/s/video_123",+ title: "Launch review",+ createdAt: "2026-05-18T10:00:00.000Z",+ updatedAt: "2026-05-18T10:30:00.000Z",+ ownerName: "Richie",+ durationSeconds: 125,+ thumbnailUrl: null,+ folderId: null,+ public: true,+ protected: false,+ viewCount: 7,+ commentCount: 2,+ reactionCount: 3,+ upload: null,+};++describe("getCapCardViewModel", () => {+ it("formats card rendering state", () => {+ expect(+ getCapCardViewModel(cap, new Date("2026-05-18T11:00:00.000Z")),+ ).toMatchObject({+ date: "an hour ago",+ duration: "2 mins",+ visibility: "Shared",+ accessibilityLabel: "Launch review, an hour ago, Shared",+ });+ });++ it("formats active upload state for the thumbnail overlay", () => {+ expect(+ getCapCardViewModel(+ {+ ...cap,+ upload: {+ uploaded: 25,+ total: 100,+ phase: "uploading",+ processingProgress: 0,+ processingMessage: null,+ processingError: null,+ },+ },+ new Date("2026-05-18T11:00:00.000Z"),+ ),+ ).toMatchObject({+ uploadStatusText: "25% uploaded",+ uploadProgress: 25,+ uploadFailed: false,+ accessibilityLabel: "Launch review, an hour ago, Shared, 25% uploaded",+ });+ });++ it("keeps password protection separate from sharing state", () => {+ expect(+ getCapCardViewModel(+ {+ ...cap,+ public: false,+ protected: true,+ },+ new Date("2026-05-18T11:00:00.000Z"),+ ),+ ).toMatchObject({+ date: "an hour ago",+ visibility: "Not shared",+ accessibilityLabel: "Launch review, an hour ago, Not shared",+ });+ });++ it("uses processing progress as a percent value", () => {+ expect(+ getCapCardViewModel({+ ...cap,+ upload: {+ uploaded: 100,+ total: 100,+ phase: "processing",+ processingProgress: 42,+ processingMessage: "Processing",+ processingError: null,+ },+ }).uploadProgress,+ ).toBe(42);+ });++ it("keeps non-finite upload progress display-safe", () => {+ const uploading = getCapCardViewModel(+ {+ ...cap,+ upload: {+ uploaded: Number.NaN,+ total: Number.NaN,+ phase: "uploading",+ processingProgress: 0,+ processingMessage: null,+ processingError: null,+ },+ },+ new Date("2026-05-18T11:00:00.000Z"),+ );+ const processing = getCapCardViewModel({+ ...cap,+ upload: {+ uploaded: 100,+ total: 100,+ phase: "processing",+ processingProgress: Number.POSITIVE_INFINITY,+ processingMessage: "Processing",+ processingError: null,+ },+ });++ expect(uploading).toMatchObject({+ uploadStatusText: "0% uploaded",+ uploadProgress: 0,+ accessibilityLabel: "Launch review, an hour ago, Shared, 0% uploaded",+ });+ expect(processing.uploadProgress).toBe(0);+ });++ it("matches the web finishing state for completed processing records", () => {+ expect(+ getCapCardViewModel({+ ...cap,+ upload: {+ uploaded: 100,+ total: 100,+ phase: "complete",+ processingProgress: 100,+ processingMessage: null,+ processingError: null,+ },+ }).uploadStatusText,+ ).toBe("Finishing up");+ });+});++describe("CapCard", () => {+ it("uses a branded thumbnail placeholder when a Cap has no thumbnail", async () => {+ const tree = await renderTree(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );++ expect(hasProp(tree, "fill", "#cecece")).toBe(true);+ expect(hasProp(tree, "name", "play.fill")).toBe(false);+ });++ it("exposes active upload progress as a native progressbar", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap: {+ ...cap,+ upload: {+ uploaded: 25,+ total: 100,+ phase: "uploading",+ processingProgress: 0,+ processingMessage: null,+ processingError: null,+ },+ },+ onPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [progress] = renderer.root.findAllByProps({+ accessibilityLabel: "Upload progress",+ });+ if (!progress) throw new Error("Upload progress was not rendered");++ expect(progress.props.accessibilityRole).toBe("progressbar");+ expect(progress.props.accessibilityValue).toEqual({+ max: 100,+ min: 0,+ now: 25,+ text: "25%",+ });+ });++ it("exposes processing upload state as an indeterminate progressbar", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap: {+ ...cap,+ upload: {+ uploaded: 100,+ total: 100,+ phase: "processing",+ processingProgress: 0,+ processingMessage: "Processing",+ processingError: null,+ },+ },+ onPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [progress] = renderer.root.findAllByProps({+ accessibilityLabel: "Upload progress",+ });+ if (!progress) throw new Error("Upload progress was not rendered");++ expect(progress.props.accessibilityRole).toBe("progressbar");+ expect(progress.props.accessibilityValue).toEqual({+ text: "Processing",+ });+ });++ it("shows copy, share, and more actions together", async () => {+ const tree = await renderTree(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ onCopyPress: vi.fn(),+ onSharePress: vi.fn(),+ onMenuPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );++ expect(+ hasProp(tree, "accessibilityLabel", "Copy link for Launch review"),+ ).toBe(true);+ expect(hasProp(tree, "accessibilityHint", "Copies this Cap link")).toBe(+ true,+ );+ expect(hasProp(tree, "accessibilityLabel", "Share Launch review")).toBe(+ true,+ );+ expect(+ hasProp(tree, "accessibilityHint", "Opens the native share sheet"),+ ).toBe(true);+ expect(+ hasProp(tree, "accessibilityLabel", "More actions for Launch review"),+ ).toBe(true);+ expect(hasProp(tree, "accessibilityHint", "Opens Cap actions")).toBe(true);+ });++ it("uses the Cap web neutral button surface for card actions", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ onCopyPress: vi.fn(),+ onSharePress: vi.fn(),+ onMenuPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [copyButton] = renderer.root.findAllByProps({+ accessibilityLabel: "Copy link for Launch review",+ });+ if (!copyButton) throw new Error("Copy action was not rendered");++ expect(resolveStyle(copyButton.props.style)).toMatchObject({+ width: 32,+ height: 32,+ backgroundColor: "#f0f0f0",+ borderColor: "#e0e0e0",+ });+ expect(resolveStyle(copyButton.props.style, true)).toMatchObject({+ backgroundColor: "#e0e0e0",+ borderColor: "#cecece",+ });+ expect(copyButton.props.hitSlop).toEqual({+ bottom: 6,+ left: 6,+ right: 6,+ top: 6,+ });+ });++ it("opens visibility controls from the shared status row like the web card", async () => {+ const onVisibilityPress = vi.fn();+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ onVisibilityPress,+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [shareState] = renderer.root.findAllByProps({+ accessibilityLabel: "Change sharing for Launch review",+ });+ if (!shareState) throw new Error("Shared status action was not rendered");+ const stopPropagation = vi.fn();++ expect(shareState.props.accessibilityHint).toBe("Opens sharing settings");+ expect(shareState.props.accessibilityState).toEqual({+ busy: false,+ disabled: false,+ });+ expect(shareState.props.hitSlop).toEqual({+ bottom: 6,+ left: 6,+ right: 6,+ top: 6,+ });++ await act(async () => {+ shareState.props.onPress({ stopPropagation });+ });++ expect(stopPropagation).toHaveBeenCalled();+ expect(onVisibilityPress).toHaveBeenCalledTimes(1);+ });++ it("shows a disabled sharing state while the card visibility is updating", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ onVisibilityPress: vi.fn(),+ visibilityBusy: true,+ visibilityDisabled: true,+ visibilityDisabledHint: "Sharing update is in progress",+ visibilityAccessibilityValue: "Updating sharing for Launch review",+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [shareState] = renderer.root.findAllByProps({+ accessibilityLabel: "Change sharing for Launch review",+ });+ if (!shareState) throw new Error("Shared status action was not rendered");++ expect(getTextNodes(renderer.toJSON())).toContain("Shared");+ expect(getTextNodes(renderer.toJSON())).not.toContain("Updating...");+ expect(shareState.props.disabled).toBe(true);+ expect(shareState.props.accessibilityHint).toBe(+ "Sharing update is in progress",+ );+ expect(shareState.props.accessibilityState).toEqual({+ busy: true,+ disabled: true,+ });+ expect(shareState.props.accessibilityValue).toEqual({+ text: "Updating sharing for Launch review",+ });+ expect(resolveStyle(shareState.props.style, true)).toMatchObject({+ backgroundColor: "#f9f9f9",+ });+ });++ it("opens analytics from the metrics row like the web card", async () => {+ const onAnalyticsPress = vi.fn();+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap,+ onAnalyticsPress,+ onPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [metricsRow] = renderer.root.findAllByProps({+ accessibilityLabel: "View analytics for Launch review",+ });+ if (!metricsRow) throw new Error("Analytics action was not rendered");+ const stopPropagation = vi.fn();++ expect(metricsRow.props.accessibilityHint).toBe(+ "Opens analytics in a browser sheet",+ );+ expect(metricsRow.props.accessibilityState).toEqual({+ disabled: false,+ });++ await act(async () => {+ metricsRow.props.onPress({ stopPropagation });+ });++ expect(stopPropagation).toHaveBeenCalled();+ expect(onAnalyticsPress).toHaveBeenCalledTimes(1);+ });++ it("marks metrics as disabled when analytics are informational only", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap,+ onPress: vi.fn(),+ now: new Date("2026-05-18T11:00:00.000Z"),+ }),+ );+ const [metricsRow] = renderer.root.findAllByProps({+ accessibilityLabel: "View analytics for Launch review",+ });+ if (!metricsRow) throw new Error("Metrics row was not rendered");++ expect(metricsRow.props.disabled).toBe(true);+ expect(metricsRow.props.accessibilityHint).toBeUndefined();+ expect(metricsRow.props.accessibilityState).toEqual({+ disabled: true,+ });+ });+});diff --git a/apps/mobile/src/components/CapCard.tsx b/apps/mobile/src/components/CapCard.tsxnew file mode 100644index 000000000..16b698c5b--- /dev/null+++ b/apps/mobile/src/components/CapCard.tsx@@ -0,0 +1,649 @@+import { Image } from "expo-image";+import { SymbolView } from "expo-symbols";+import { useEffect, useRef, useState } from "react";+import {+ ActivityIndicator,+ Pressable,+ StyleSheet,+ Text,+ View,+} from "react-native";+import Svg, { Circle } from "react-native-svg";+import type { MobileCapSummary } from "@/api/mobile";+import { colors, fonts, radius, squircle } from "@/theme";+import { getCapCardViewModel } from "./capCardViewModel";++type CapCardProps = {+ cap: MobileCapSummary;+ onPress: () => void;+ onCopyPress?: () => void;+ onSharePress?: () => void;+ onVisibilityPress?: () => void;+ onAnalyticsPress?: () => void;+ onMenuPress?: () => void;+ visibilityBusy?: boolean;+ visibilityDisabled?: boolean;+ visibilityDisabledHint?: string;+ visibilityValue?: string;+ visibilityAccessibilityValue?: string;+ now?: Date;+};++const progressSize = 18;+const progressStrokeWidth = 3;+const progressRadius = (progressSize - progressStrokeWidth) / 2;+const progressCircumference = 2 * Math.PI * progressRadius;+const compactHitSlop = { bottom: 6, left: 6, right: 6, top: 6 };++const getProgressAccessibilityValue = (+ progress: number | null,+ indeterminate: boolean,+ statusText: string,+) => {+ if (indeterminate || progress === null) {+ return { text: statusText };+ }++ const clampedProgress = Math.min(100, Math.max(0, progress));++ return {+ max: 100,+ min: 0,+ now: clampedProgress,+ text: `${clampedProgress}%`,+ };+};++function CapThumbnailPlaceholder() {+ return (+ <View style={styles.emptyThumbnail}>+ <View style={styles.placeholderSheen} />+ <View style={styles.placeholderMark}>+ <Svg width={34} height={34} viewBox="0 0 40 40">+ <Circle cx={20} cy={20} fill={colors.gray7} r={16} />+ <Circle cx={20} cy={20} fill={colors.gray5} r={13} />+ <Circle cx={20} cy={20} fill={colors.gray1} r={10} />+ </Svg>+ </View>+ </View>+ );+}++function UploadProgressIndicator({+ progress,+ indeterminate,+ statusText,+}: {+ progress: number | null;+ indeterminate: boolean;+ statusText: string;+}) {+ const accessibilityValue = getProgressAccessibilityValue(+ progress,+ indeterminate,+ statusText,+ );++ if (indeterminate || progress === null) {+ return (+ <View+ accessibilityLabel="Upload progress"+ accessibilityRole="progressbar"+ accessibilityValue={accessibilityValue}+ style={styles.progressIndicator}+ >+ <ActivityIndicator color={colors.white} size="small" />+ </View>+ );+ }++ const strokeDashoffset =+ progressCircumference -+ (Math.min(100, Math.max(0, progress)) / 100) * progressCircumference;++ return (+ <View+ accessibilityLabel="Upload progress"+ accessibilityRole="progressbar"+ accessibilityValue={accessibilityValue}+ style={styles.progressIndicator}+ >+ <View style={styles.progressRing}>+ <Svg width={progressSize} height={progressSize}>+ <Circle+ cx={progressSize / 2}+ cy={progressSize / 2}+ fill="none"+ r={progressRadius}+ stroke="rgba(255, 255, 255, 0.3)"+ strokeWidth={progressStrokeWidth}+ />+ <Circle+ cx={progressSize / 2}+ cy={progressSize / 2}+ fill="none"+ r={progressRadius}+ stroke={colors.white}+ strokeDasharray={`${progressCircumference} ${progressCircumference}`}+ strokeDashoffset={strokeDashoffset}+ strokeLinecap="round"+ strokeWidth={progressStrokeWidth}+ />+ </Svg>+ </View>+ </View>+ );+}++export function CapCard({+ cap,+ onPress,+ onCopyPress,+ onSharePress,+ onVisibilityPress,+ onAnalyticsPress,+ onMenuPress,+ visibilityBusy = false,+ visibilityDisabled = false,+ visibilityDisabledHint,+ visibilityValue,+ visibilityAccessibilityValue,+ now,+}: CapCardProps) {+ const viewModel = getCapCardViewModel(cap, now);+ const [copyPressed, setCopyPressed] = useState(false);+ const copyResetTimer = useRef<ReturnType<typeof setTimeout> | null>(null);+ const hasCopyAction = Boolean(onCopyPress);+ const hasShareAction = Boolean(onSharePress);+ const hasVisibleMenuAction = Boolean(onMenuPress);+ const hasActions = hasCopyAction || hasShareAction || hasVisibleMenuAction;+ const visibilityActionDisabled = visibilityDisabled || visibilityBusy;+ const visibilityHint = visibilityActionDisabled+ ? (visibilityDisabledHint ?? "Sharing update is in progress")+ : "Opens sharing settings";+ const visibilityText = visibilityValue ?? viewModel.visibility;+ const uploadIndeterminate =+ Boolean(cap.upload) &&+ cap.upload?.phase !== "uploading" &&+ (viewModel.uploadProgress ?? 0) === 0;++ useEffect(+ () => () => {+ if (copyResetTimer.current) clearTimeout(copyResetTimer.current);+ },+ [],+ );++ const copyLink = () => {+ if (!onCopyPress) return;+ onCopyPress();+ setCopyPressed(true);+ if (copyResetTimer.current) clearTimeout(copyResetTimer.current);+ copyResetTimer.current = setTimeout(() => {+ setCopyPressed(false);+ copyResetTimer.current = null;+ }, 1400);+ };++ return (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={viewModel.accessibilityLabel}+ onPress={onPress}+ onLongPress={onMenuPress}+ style={({ pressed }) => [styles.card, pressed && styles.pressed]}+ >+ <View style={styles.thumbnailWrap}>+ {hasActions ? (+ <View style={styles.actionStack}>+ {onCopyPress ? (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`Copy link for ${cap.title}`}+ accessibilityHint="Copies this Cap link"+ hitSlop={compactHitSlop}+ onPress={(event) => {+ event.stopPropagation();+ copyLink();+ }}+ style={({ pressed }) => [+ styles.actionIconButton,+ pressed && styles.actionIconButtonPressed,+ ]}+ >+ <SymbolView+ name={copyPressed ? "checkmark" : "link"}+ size={16}+ tintColor={colors.gray12}+ weight="semibold"+ />+ </Pressable>+ ) : null}+ {onSharePress ? (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`Share ${cap.title}`}+ accessibilityHint="Opens the native share sheet"+ hitSlop={compactHitSlop}+ onPress={(event) => {+ event.stopPropagation();+ onSharePress();+ }}+ style={({ pressed }) => [+ styles.actionIconButton,+ pressed && styles.actionIconButtonPressed,+ ]}+ >+ <SymbolView+ name="square.and.arrow.up"+ size={16}+ tintColor={colors.gray12}+ weight="semibold"+ />+ </Pressable>+ ) : null}+ {onMenuPress ? (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`More actions for ${cap.title}`}+ accessibilityHint="Opens Cap actions"+ hitSlop={compactHitSlop}+ onPress={(event) => {+ event.stopPropagation();+ onMenuPress();+ }}+ style={({ pressed }) => [+ styles.actionIconButton,+ pressed && styles.actionIconButtonPressed,+ ]}+ >+ <SymbolView+ name="ellipsis"+ size={17}+ tintColor={colors.gray12}+ weight="semibold"+ />+ </Pressable>+ ) : null}+ </View>+ ) : null}+ {cap.thumbnailUrl ? (+ <Image source={{ uri: cap.thumbnailUrl }} style={styles.thumbnail} />+ ) : (+ <CapThumbnailPlaceholder />+ )}+ {viewModel.uploadStatusText ? (+ <View pointerEvents="none" style={styles.uploadOverlay}>+ <View style={styles.uploadStatusRow}>+ <Text numberOfLines={1} style={styles.uploadStatusText}>+ {viewModel.uploadStatusText}+ </Text>+ {viewModel.uploadFailed ? null : (+ <UploadProgressIndicator+ indeterminate={uploadIndeterminate}+ progress={viewModel.uploadProgress}+ statusText={viewModel.uploadStatusText}+ />+ )}+ </View>+ </View>+ ) : null}+ {cap.protected ? (+ <View+ style={[+ styles.lockBadge,+ hasActions && styles.lockBadgeWithActions,+ ]}+ >+ <SymbolView+ name="lock.fill"+ size={13}+ tintColor={colors.white}+ weight="semibold"+ />+ </View>+ ) : null}+ {viewModel.duration ? (+ <View style={styles.durationPill}>+ <Text style={styles.durationText}>{viewModel.duration}</Text>+ </View>+ ) : null}+ </View>+ <View style={styles.body}>+ <View>+ <Text numberOfLines={1} style={styles.title}>+ {cap.title}+ </Text>+ {onVisibilityPress ? (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`Change sharing for ${cap.title}`}+ accessibilityHint={visibilityHint}+ accessibilityState={{+ busy: visibilityBusy,+ disabled: visibilityActionDisabled,+ }}+ accessibilityValue={+ visibilityAccessibilityValue+ ? { text: visibilityAccessibilityValue }+ : undefined+ }+ disabled={visibilityActionDisabled}+ hitSlop={compactHitSlop}+ onPress={(event) => {+ event.stopPropagation();+ onVisibilityPress();+ }}+ style={({ pressed }) => [+ styles.shareStateButton,+ pressed &&+ !visibilityActionDisabled &&+ styles.shareStateButtonPressed,+ visibilityActionDisabled && styles.shareStateButtonDisabled,+ ]}+ >+ <Text+ numberOfLines={1}+ style={[+ styles.shareState,+ visibilityActionDisabled && styles.shareStateDisabled,+ ]}+ >+ {visibilityText}+ </Text>+ <SymbolView+ name="chevron.down"+ size={10}+ tintColor={+ visibilityActionDisabled ? colors.gray8 : colors.gray10+ }+ weight="semibold"+ />+ </Pressable>+ ) : (+ <Text numberOfLines={1} style={styles.shareState}>+ {viewModel.visibility}+ </Text>+ )}+ <Text numberOfLines={1} style={styles.meta}>+ {viewModel.date}+ </Text>+ </View>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`View analytics for ${cap.title}`}+ accessibilityHint={+ onAnalyticsPress ? "Opens analytics in a browser sheet" : undefined+ }+ accessibilityState={{ disabled: !onAnalyticsPress }}+ disabled={!onAnalyticsPress}+ onPress={(event) => {+ event.stopPropagation();+ onAnalyticsPress?.();+ }}+ style={({ pressed }) => [+ styles.metricsRow,+ onAnalyticsPress && styles.metricsRowAction,+ pressed && onAnalyticsPress && styles.metricsRowPressed,+ ]}+ >+ <View style={styles.metric}>+ <SymbolView+ name="eye"+ size={15}+ tintColor={colors.gray8}+ weight="medium"+ />+ <Text style={styles.metricText}>{cap.viewCount}</Text>+ </View>+ <View style={styles.metric}>+ <SymbolView+ name="text.bubble"+ size={15}+ tintColor={colors.gray8}+ weight="medium"+ />+ <Text style={styles.metricText}>{cap.commentCount}</Text>+ </View>+ <View style={styles.metric}>+ <SymbolView+ name="face.smiling"+ size={15}+ tintColor={colors.gray8}+ weight="medium"+ />+ <Text style={styles.metricText}>{cap.reactionCount}</Text>+ </View>+ {onAnalyticsPress ? (+ <Text style={styles.analyticsLink}>View analytics</Text>+ ) : null}+ </Pressable>+ </View>+ </Pressable>+ );+}++const styles = StyleSheet.create({+ card: {+ backgroundColor: colors.gray1,+ borderRadius: radius.md,+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: colors.gray3,+ overflow: "hidden",+ marginBottom: 16,+ ...squircle,+ },+ pressed: {+ backgroundColor: colors.gray2,+ borderColor: colors.blue10,+ },+ thumbnailWrap: {+ width: "100%",+ aspectRatio: 16 / 9,+ backgroundColor: colors.black,+ position: "relative",+ borderBottomWidth: StyleSheet.hairlineWidth,+ borderBottomColor: colors.gray3,+ },+ thumbnail: {+ width: "100%",+ height: "100%",+ },+ emptyThumbnail: {+ flex: 1,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: colors.gray3,+ overflow: "hidden",+ },+ placeholderSheen: {+ position: "absolute",+ top: -36,+ left: -28,+ width: "78%",+ height: "140%",+ backgroundColor: "rgba(255, 255, 255, 0.34)",+ transform: [{ rotate: "18deg" }],+ },+ placeholderMark: {+ width: 48,+ height: 48,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: "rgba(255, 255, 255, 0.72)",+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: "rgba(255, 255, 255, 0.95)",+ ...squircle,+ },+ durationPill: {+ position: "absolute",+ left: 12,+ bottom: 12,+ minWidth: 46,+ height: 23,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: "rgba(0, 0, 0, 0.5)",+ paddingHorizontal: 8,+ ...squircle,+ },+ durationText: {+ fontFamily: fonts.medium,+ fontSize: 11,+ color: colors.white,+ },+ lockBadge: {+ position: "absolute",+ right: 10,+ top: 10,+ zIndex: 2,+ width: 28,+ height: 28,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: "rgba(0, 0, 0, 0.7)",+ },+ lockBadgeWithActions: {+ right: 46,+ },+ actionStack: {+ position: "absolute",+ right: 10,+ top: 10,+ zIndex: 2,+ gap: 8,+ },+ actionIconButton: {+ width: 32,+ height: 32,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: colors.gray3,+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: colors.gray5,+ shadowColor: colors.black,+ shadowOffset: { width: 0, height: 2 },+ shadowOpacity: 0.1,+ shadowRadius: 8,+ elevation: 2,+ ...squircle,+ },+ actionIconButtonPressed: {+ backgroundColor: colors.gray5,+ borderColor: colors.gray7,+ },+ uploadOverlay: {+ ...StyleSheet.absoluteFillObject,+ justifyContent: "flex-end",+ backgroundColor: "rgba(0, 0, 0, 0.58)",+ paddingHorizontal: 12,+ paddingBottom: 12,+ zIndex: 1,+ },+ uploadStatusRow: {+ flexDirection: "row",+ alignItems: "center",+ gap: 8,+ paddingRight: 96,+ },+ uploadStatusText: {+ fontFamily: fonts.medium,+ fontSize: 14,+ lineHeight: 19,+ color: colors.white,+ },+ progressIndicator: {+ width: progressSize,+ height: progressSize,+ alignItems: "center",+ justifyContent: "center",+ },+ progressRing: {+ transform: [{ rotate: "-90deg" }],+ },+ body: {+ paddingHorizontal: 16,+ paddingBottom: 16,+ gap: 12,+ },+ title: {+ fontFamily: fonts.medium,+ fontSize: 16,+ lineHeight: 21,+ color: colors.gray12,+ marginTop: 13,+ marginBottom: 4,+ },+ shareState: {+ fontFamily: fonts.regular,+ fontSize: 14,+ lineHeight: 19,+ color: colors.gray10,+ },+ shareStateButton: {+ alignSelf: "flex-start",+ minHeight: 22,+ maxWidth: "100%",+ flexDirection: "row",+ alignItems: "center",+ gap: 5,+ marginBottom: 2,+ borderRadius: radius.xs,+ paddingHorizontal: 3,+ marginLeft: -3,+ ...squircle,+ },+ shareStateButtonPressed: {+ backgroundColor: colors.gray3,+ },+ shareStateButtonDisabled: {+ backgroundColor: colors.gray2,+ },+ shareStateDisabled: {+ color: colors.gray8,+ },+ meta: {+ fontFamily: fonts.regular,+ fontSize: 14,+ lineHeight: 20,+ color: colors.gray10,+ },+ metricsRow: {+ flexDirection: "row",+ alignItems: "center",+ gap: 16,+ minHeight: 24,+ },+ metricsRowAction: {+ width: "100%",+ maxWidth: "100%",+ borderRadius: radius.xs,+ paddingHorizontal: 3,+ marginLeft: -3,+ ...squircle,+ },+ metricsRowPressed: {+ backgroundColor: colors.gray3,+ },+ metric: {+ flexDirection: "row",+ alignItems: "center",+ gap: 7,+ },+ metricText: {+ fontFamily: fonts.regular,+ fontSize: 14,+ color: colors.gray12,+ },+ analyticsLink: {+ marginLeft: "auto",+ fontFamily: fonts.regular,+ fontSize: 12,+ lineHeight: 17,+ color: colors.blue11,+ },+});diff --git a/apps/mobile/src/components/CapLogoBadge.tsx b/apps/mobile/src/components/CapLogoBadge.tsxnew file mode 100644index 000000000..7393a5b2e--- /dev/null+++ b/apps/mobile/src/components/CapLogoBadge.tsx@@ -0,0 +1,32 @@+import Svg, { Path, Rect } from "react-native-svg";+import { colors } from "@/theme";++type CapLogoBadgeProps = {+ size?: number;+};++export function CapLogoBadge({ size = 48 }: CapLogoBadgeProps) {+ return (+ <Svg+ accessibilityLabel="Cap logo"+ accessibilityRole="image"+ width={size}+ height={size}+ viewBox="0 0 40 40"+ >+ <Rect width={40} height={40} fill={colors.white} rx={8} />+ <Path+ fill="#4785FF"+ d="M20 36c8.837 0 16-7.163 16-16 0-8.836-7.163-16-16-16-8.836 0-16 7.164-16 16 0 8.837 7.164 16 16 16z"+ />+ <Path+ fill="#ADC9FF"+ d="M20 33c7.18 0 13-5.82 13-13S27.18 7 20 7 7 12.82 7 20s5.82 13 13 13z"+ />+ <Path+ fill={colors.white}+ d="M20 30c5.523 0 10-4.477 10-10s-4.477-10-10-10-10 4.477-10 10 4.477 10 10 10z"+ />+ </Svg>+ );+}diff --git a/apps/mobile/src/components/CapRefreshControl.test.tsx b/apps/mobile/src/components/CapRefreshControl.test.tsxnew file mode 100644index 000000000..372a9adf5--- /dev/null+++ b/apps/mobile/src/components/CapRefreshControl.test.tsx@@ -0,0 +1,57 @@+import type { ReactElement, ReactNode } from "react";+import { RefreshControl } from "react-native";+import TestRenderer, { act, type ReactTestRenderer } from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import { CapRefreshControl } from "./CapRefreshControl";++type HostProps = {+ children?: ReactNode;+ [key: string]: unknown;+};++(+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const renderComponent = async (+ node: ReactElement,+): Promise<ReactTestRenderer> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return renderer as unknown as ReactTestRenderer;+};++vi.mock("react-native", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ RefreshControl: createHost("RefreshControl"),+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ },+ };+});++describe("CapRefreshControl", () => {+ it("uses Cap web colors for native pull-to-refresh", async () => {+ const onRefresh = vi.fn();+ const renderer = await renderComponent(+ <CapRefreshControl refreshing onRefresh={onRefresh} />,+ );+ const refreshControl = renderer.root.findByType(RefreshControl);++ expect(refreshControl.props).toMatchObject({+ colors: ["#0d74ce"],+ onRefresh,+ progressBackgroundColor: "#fcfcfc",+ refreshing: true,+ tintColor: "#0d74ce",+ });+ });+});diff --git a/apps/mobile/src/components/CapRefreshControl.tsx b/apps/mobile/src/components/CapRefreshControl.tsxnew file mode 100644index 000000000..6c55078bc--- /dev/null+++ b/apps/mobile/src/components/CapRefreshControl.tsx@@ -0,0 +1,22 @@+import { RefreshControl } from "react-native";+import { colors } from "@/theme";++type CapRefreshControlProps = {+ refreshing: boolean;+ onRefresh: () => void;+};++export function CapRefreshControl({+ refreshing,+ onRefresh,+}: CapRefreshControlProps) {+ return (+ <RefreshControl+ colors={[colors.blue11]}+ onRefresh={onRefresh}+ progressBackgroundColor={colors.gray1}+ refreshing={refreshing}+ tintColor={colors.blue11}+ />+ );+}diff --git a/apps/mobile/src/components/GlassSurface.tsx b/apps/mobile/src/components/GlassSurface.tsxnew file mode 100644index 000000000..9ee85941a--- /dev/null+++ b/apps/mobile/src/components/GlassSurface.tsx@@ -0,0 +1,72 @@+import {+ GlassView,+ isGlassEffectAPIAvailable,+ isLiquidGlassAvailable,+} from "expo-glass-effect";+import type { ReactNode } from "react";+import {+ Platform,+ type StyleProp,+ StyleSheet,+ View,+ type ViewStyle,+} from "react-native";+import { colors } from "@/theme";++type GlassSurfaceProps = {+ children?: ReactNode;+ style?: StyleProp<ViewStyle>;+ fallbackStyle?: StyleProp<ViewStyle>;+ glassEffectStyle?: "clear" | "regular" | "none";+ tintColor?: string;+ isInteractive?: boolean;+};++const getGlassAvailable = () => {+ if (Platform.OS !== "ios") return false;+ try {+ return isGlassEffectAPIAvailable() && isLiquidGlassAvailable();+ } catch {+ return false;+ }+};++const glassAvailable = getGlassAvailable();++export function GlassSurface({+ children,+ style,+ fallbackStyle,+ glassEffectStyle = "regular",+ tintColor = colors.glass,+ isInteractive = false,+}: GlassSurfaceProps) {+ if (glassAvailable) {+ return (+ <GlassView+ colorScheme="light"+ glassEffectStyle={glassEffectStyle}+ isInteractive={isInteractive}+ style={[styles.surface, style]}+ tintColor={tintColor}+ >+ {children}+ </GlassView>+ );+ }++ return (+ <View style={[styles.surface, styles.fallback, fallbackStyle, style]}>+ {children}+ </View>+ );+}++const styles = StyleSheet.create({+ surface: {+ overflow: "hidden",+ },+ fallback: {+ backgroundColor: colors.glass,+ },+});diff --git a/apps/mobile/src/components/OrgSwitcher.test.tsx b/apps/mobile/src/components/OrgSwitcher.test.tsxnew file mode 100644index 000000000..57f01ea78--- /dev/null+++ b/apps/mobile/src/components/OrgSwitcher.test.tsx@@ -0,0 +1,188 @@+import { Organisation, User } from "@cap/web-domain";+import type { ReactElement, ReactNode } from "react";+import TestRenderer, {+ act,+ type ReactTestRenderer,+ type ReactTestRendererJSON,+} from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import type { MobileBootstrapResponse } from "@/api/mobile";+import { OrgSwitcher } from "./OrgSwitcher";++type HostProps = {+ children?: ReactNode;+ [key: string]: unknown;+};++type JsonNode = ReactTestRendererJSON | ReactTestRendererJSON[] | string | null;++(+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const renderTree = async (node: ReactElement): Promise<JsonNode> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return (renderer as ReactTestRenderer | null)?.toJSON() ?? null;+};++const renderComponent = async (+ node: ReactElement,+): Promise<ReactTestRenderer> => {+ let renderer: ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(node);+ });+ return renderer as unknown as ReactTestRenderer;+};++const hasImageSourceUri = (node: JsonNode, uri: string): boolean => {+ if (!node || typeof node === "string") return false;+ if (Array.isArray(node))+ return node.some((item) => hasImageSourceUri(item, uri));+ const source = node.props.source;+ if (+ source &&+ typeof source === "object" &&+ "uri" in source &&+ source.uri === uri+ ) {+ return true;+ }+ return node.children?.some((child) => hasImageSourceUri(child, uri)) ?? false;+};++const resolveStyle = (+ style: unknown,+ pressed = false,+): Record<string, unknown> => {+ const resolved = typeof style === "function" ? style({ pressed }) : style;+ const styles = Array.isArray(resolved) ? resolved : [resolved];+ return Object.assign({}, ...styles.filter(Boolean));+};++vi.mock("react-native", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ ActionSheetIOS: {+ showActionSheetWithOptions: vi.fn(),+ },+ Modal: createHost("Modal"),+ Platform: {+ OS: "ios",+ },+ Pressable: createHost("Pressable"),+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ hairlineWidth: 1,+ },+ Text: createHost("Text"),+ View: createHost("View"),+ };+});++vi.mock("expo-image", async () => {+ const React = await import("react");+ return {+ Image: (props: Record<string, unknown>) =>+ React.createElement("Image", props),+ };+});++vi.mock("expo-symbols", async () => {+ const React = await import("react");+ return {+ SymbolView: (props: Record<string, unknown>) =>+ React.createElement("SymbolView", props),+ };+});++const bootstrap: MobileBootstrapResponse = {+ user: {+ id: User.UserId.make("user_123"),+ name: "Richie",+ email: "[email protected]",+ imageUrl: null,+ activeOrganizationId: Organisation.OrganisationId.make("org_123"),+ },+ organizations: [+ {+ id: Organisation.OrganisationId.make("org_123"),+ name: "Cap",+ iconUrl: "https://cap.so/icon.png",+ role: "owner",+ },+ {+ id: Organisation.OrganisationId.make("org_456"),+ name: "Design",+ iconUrl: null,+ role: "member",+ },+ ],+ activeOrganizationId: Organisation.OrganisationId.make("org_123"),+ rootFolders: [],+};++describe("OrgSwitcher", () => {+ it("uses the organization icon when the active org has one", async () => {+ const tree = await renderTree(+ <OrgSwitcher bootstrap={bootstrap} onChange={vi.fn()} />,+ );++ expect(hasImageSourceUri(tree, "https://cap.so/icon.png")).toBe(true);+ });++ it("uses a native organization action sheet with roles and disabled active org", async () => {+ const onChange = vi.fn(() => Promise.resolve());+ const renderer = await renderComponent(+ <OrgSwitcher bootstrap={bootstrap} onChange={onChange} />,+ );+ const [trigger] = renderer.root.findAllByProps({+ accessibilityLabel: "Switch organization",+ });+ if (!trigger) throw new Error("Organization switcher was not rendered");++ expect(resolveStyle(trigger.props.style, true)).toMatchObject({+ backgroundColor: "#f0f0f0",+ borderColor: "#d9d9d9",+ });++ const { ActionSheetIOS } = await import("react-native");+ const showActionSheetWithOptions = vi.mocked(+ ActionSheetIOS.showActionSheetWithOptions,+ );+ showActionSheetWithOptions.mockClear();++ await act(async () => {+ trigger.props.onPress();+ });++ expect(showActionSheetWithOptions).toHaveBeenCalledWith(+ expect.objectContaining({+ cancelButtonIndex: 2,+ disabledButtonIndices: [0],+ disabledButtonTintColor: "#8d8d8d",+ options: ["Cap (Owner)", "Design (Member)", "Cancel"],+ title: "Organization",+ userInterfaceStyle: "light",+ }),+ expect.any(Function),+ );++ const [, callback] = showActionSheetWithOptions.mock.calls[0] ?? [];+ if (!callback) throw new Error("Organization action sheet did not open");++ await act(async () => {+ callback(1);+ });++ expect(onChange).toHaveBeenCalledWith("org_456");+ });+});diff --git a/apps/mobile/src/components/OrgSwitcher.tsx b/apps/mobile/src/components/OrgSwitcher.tsxnew file mode 100644index 000000000..b87f5391f--- /dev/null+++ b/apps/mobile/src/components/OrgSwitcher.tsx@@ -0,0 +1,246 @@+import { Image } from "expo-image";+import { SymbolView } from "expo-symbols";+import { useState } from "react";+import {+ ActionSheetIOS,+ Modal,+ Platform,+ Pressable,+ StyleSheet,+ Text,+ View,+} from "react-native";+import type { MobileBootstrapResponse } from "@/api/mobile";+import { colors, fonts, radius, shadows, squircle } from "@/theme";++type OrgSwitcherProps = {+ bootstrap: MobileBootstrapResponse;+ onChange: (organizationId: string) => Promise<void>;+};++type Organization = MobileBootstrapResponse["organizations"][number];++const formatRole = (role: Organization["role"]) =>+ role.slice(0, 1).toUpperCase() + role.slice(1);++function OrgAvatar({ organization }: { organization: Organization }) {+ return (+ <View style={styles.avatar}>+ {organization.iconUrl ? (+ <Image+ source={{ uri: organization.iconUrl }}+ style={styles.avatarImage}+ />+ ) : (+ <Text style={styles.avatarText}>+ {organization.name.slice(0, 1).toUpperCase()}+ </Text>+ )}+ </View>+ );+}++export function OrgSwitcher({ bootstrap, onChange }: OrgSwitcherProps) {+ const [open, setOpen] = useState(false);+ const activeOrganization =+ bootstrap.organizations.find(+ (org) => org.id === bootstrap.activeOrganizationId,+ ) ?? bootstrap.organizations[0];++ if (!activeOrganization) return null;++ const openSwitcher = () => {+ if (Platform.OS === "ios") {+ const activeIndex = bootstrap.organizations.findIndex(+ (organization) => organization.id === activeOrganization.id,+ );+ const options = [+ ...bootstrap.organizations.map(+ (organization) =>+ `${organization.name} (${formatRole(organization.role)})`,+ ),+ "Cancel",+ ];+ ActionSheetIOS.showActionSheetWithOptions(+ {+ cancelButtonIndex: options.length - 1,+ disabledButtonIndices: activeIndex >= 0 ? [activeIndex] : undefined,+ disabledButtonTintColor: colors.gray9,+ message: activeOrganization.name,+ options,+ title: "Organization",+ tintColor: colors.blue11,+ userInterfaceStyle: "light",+ },+ (index) => {+ const organization = bootstrap.organizations[index];+ if (organization && organization.id !== activeOrganization.id) {+ void onChange(organization.id);+ }+ },+ );+ return;+ }+ setOpen(true);+ };++ return (+ <>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel="Switch organization"+ onPress={openSwitcher}+ style={({ pressed }) => [+ styles.trigger,+ pressed && styles.triggerPressed,+ ]}+ >+ <OrgAvatar organization={activeOrganization} />+ <Text numberOfLines={1} style={styles.triggerText}>+ {activeOrganization.name}+ </Text>+ <SymbolView+ name="chevron.down"+ size={16}+ tintColor={colors.gray11}+ weight="medium"+ />+ </Pressable>+ <Modal+ allowSwipeDismissal+ animationType="fade"+ onRequestClose={() => setOpen(false)}+ presentationStyle="overFullScreen"+ transparent+ visible={open}+ >+ <Pressable style={styles.overlay} onPress={() => setOpen(false)}>+ <Pressable style={styles.sheet}>+ <Text style={styles.sheetTitle}>Organization</Text>+ {bootstrap.organizations.map((org) => {+ const active = org.id === activeOrganization.id;+ return (+ <Pressable+ key={org.id}+ accessibilityRole="button"+ accessibilityState={{ selected: active }}+ onPress={async () => {+ setOpen(false);+ if (!active) await onChange(org.id);+ }}+ style={styles.orgRow}+ >+ <OrgAvatar organization={org} />+ <View style={styles.orgTextWrap}>+ <Text numberOfLines={1} style={styles.orgName}>+ {org.name}+ </Text>+ <Text style={styles.orgRole}>{org.role}</Text>+ </View>+ {active ? (+ <SymbolView+ name="checkmark"+ size={18}+ tintColor={colors.blue9}+ weight="semibold"+ />+ ) : null}+ </Pressable>+ );+ })}+ </Pressable>+ </Pressable>+ </Modal>+ </>+ );+}++const styles = StyleSheet.create({+ trigger: {+ height: 44,+ flexDirection: "row",+ alignItems: "center",+ gap: 9,+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: colors.gray5,+ backgroundColor: colors.gray1,+ borderRadius: radius.full,+ paddingHorizontal: 10,+ ...squircle,+ },+ triggerPressed: {+ backgroundColor: colors.gray3,+ borderColor: colors.gray6,+ },+ triggerText: {+ flex: 1,+ fontFamily: fonts.medium,+ color: colors.gray12,+ fontSize: 15,+ },+ avatar: {+ width: 26,+ height: 26,+ borderRadius: radius.xs,+ overflow: "hidden",+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: colors.blue3,+ ...squircle,+ },+ avatarImage: {+ width: "100%",+ height: "100%",+ },+ avatarText: {+ fontFamily: fonts.medium,+ fontSize: 12,+ color: colors.blue11,+ },+ overlay: {+ flex: 1,+ backgroundColor: colors.blackAlpha40,+ justifyContent: "flex-end",+ },+ sheet: {+ backgroundColor: colors.gray1,+ borderTopLeftRadius: radius.xl,+ borderTopRightRadius: radius.xl,+ padding: 18,+ paddingBottom: 32,+ gap: 6,+ ...shadows.popover,+ ...squircle,+ },+ sheetTitle: {+ fontFamily: fonts.medium,+ fontSize: 20,+ lineHeight: 26,+ color: colors.gray12,+ marginBottom: 6,+ },+ orgRow: {+ minHeight: 58,+ flexDirection: "row",+ alignItems: "center",+ gap: 12,+ borderRadius: radius.sm,+ paddingHorizontal: 8,+ ...squircle,+ },+ orgTextWrap: {+ flex: 1,+ minWidth: 0,+ },+ orgName: {+ fontFamily: fonts.medium,+ fontSize: 16,+ color: colors.gray12,+ },+ orgRole: {+ fontFamily: fonts.regular,+ fontSize: 12,+ color: colors.gray10,+ textTransform: "capitalize",+ },+});diff --git a/apps/mobile/src/components/Screen.test.tsx b/apps/mobile/src/components/Screen.test.tsxnew file mode 100644index 000000000..0e5fe2458--- /dev/null+++ b/apps/mobile/src/components/Screen.test.tsx@@ -0,0 +1,109 @@+import type React from "react";+import TestRenderer, {+ act,+ type ReactTestRendererJSON,+} from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import { Screen } from "./Screen";++type HostProps = {+ children?: React.ReactNode;+ [key: string]: unknown;+};++type JsonNode = ReactTestRendererJSON | ReactTestRendererJSON[] | string | null;++(+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const renderTree = async (): Promise<JsonNode> => {+ let renderer: TestRenderer.ReactTestRenderer | null = null;+ await act(async () => {+ renderer = TestRenderer.create(+ <Screen title="Import" subtitle="Import videos from external sources." />,+ );+ });+ return (renderer as TestRenderer.ReactTestRenderer | null)?.toJSON() ?? null;+};++const findTextByValue = (+ node: JsonNode,+ value: string,+): ReactTestRendererJSON | null => {+ if (!node || typeof node === "string") return null;+ if (Array.isArray(node)) {+ for (const item of node) {+ const match = findTextByValue(item, value);+ if (match) return match;+ }+ return null;+ }+ if (node.type === "Text" && node.children?.includes(value)) return node;+ for (const child of node.children ?? []) {+ const match = findTextByValue(child, value);+ if (match) return match;+ }+ return null;+};++const hasStyle = (+ node: JsonNode,+ expected: Record<string, unknown>,+): boolean => {+ if (!node || typeof node === "string") return false;+ if (Array.isArray(node)) return node.some((item) => hasStyle(item, expected));+ const resolved = Array.isArray(node.props.style)+ ? Object.assign({}, ...node.props.style.filter(Boolean))+ : node.props.style;+ if (+ resolved &&+ Object.entries(expected).every(([key, value]) => resolved[key] === value)+ ) {+ return true;+ }+ return node.children?.some((child) => hasStyle(child, expected)) ?? false;+};++vi.mock("react-native", async () => {+ const React = await import("react");+ const createHost =+ (name: string) =>+ ({ children, ...props }: HostProps) =>+ React.createElement(name, props, children);++ return {+ ActivityIndicator: createHost("ActivityIndicator"),+ RefreshControl: createHost("RefreshControl"),+ ScrollView: createHost("ScrollView"),+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ },+ Text: createHost("Text"),+ View: createHost("View"),+ };+});++vi.mock("react-native-safe-area-context", async () => {+ const React = await import("react");+ return {+ SafeAreaView: ({ children, ...props }: HostProps) =>+ React.createElement("SafeAreaView", props, children),+ };+});++describe("Screen", () => {+ it("uses the Cap web subtitle scale", async () => {+ const tree = await renderTree();+ const subtitle = findTextByValue(+ tree,+ "Import videos from external sources.",+ );++ expect(subtitle?.props.style).toMatchObject({+ fontSize: 14,+ lineHeight: 20,+ });+ expect(hasStyle(tree, { paddingBottom: 32 })).toBe(true);+ });+});diff --git a/apps/mobile/src/components/Screen.tsx b/apps/mobile/src/components/Screen.tsxnew file mode 100644index 000000000..2e2e456e8--- /dev/null+++ b/apps/mobile/src/components/Screen.tsx@@ -0,0 +1,124 @@+import type { ReactNode } from "react";+import {+ ActivityIndicator,+ ScrollView,+ StyleSheet,+ Text,+ View,+} from "react-native";+import { type Edge, SafeAreaView } from "react-native-safe-area-context";+import { colors, fonts } from "@/theme";+import { CapRefreshControl } from "./CapRefreshControl";++type ScreenProps = {+ children?: ReactNode;+ title?: string;+ subtitle?: string | null;+ scroll?: boolean;+ refreshing?: boolean;+ onRefresh?: () => void;+ loading?: boolean;+ footer?: ReactNode;+ safeEdges?: Edge[];+};++const defaultSafeEdges: Edge[] = ["top", "left", "right"];++export function Screen({+ children,+ title,+ subtitle,+ scroll = false,+ refreshing = false,+ onRefresh,+ loading = false,+ footer,+ safeEdges = defaultSafeEdges,+}: ScreenProps) {+ const content = (+ <>+ {title ? (+ <View style={[styles.header, subtitle && styles.headerWithSubtitle]}>+ <Text style={styles.title}>{title}</Text>+ {subtitle ? <Text style={styles.subtitle}>{subtitle}</Text> : null}+ </View>+ ) : null}+ {loading ? (+ <View style={styles.loading}>+ <ActivityIndicator color={colors.blue9} />+ </View>+ ) : (+ children+ )}+ {footer}+ </>+ );++ return (+ <SafeAreaView style={styles.safeArea} edges={safeEdges}>+ {scroll ? (+ <ScrollView+ contentInsetAdjustmentBehavior="automatic"+ contentContainerStyle={styles.scrollContent}+ keyboardDismissMode="interactive"+ keyboardShouldPersistTaps="handled"+ refreshControl={+ onRefresh ? (+ <CapRefreshControl+ refreshing={refreshing}+ onRefresh={onRefresh}+ />+ ) : undefined+ }+ >+ {content}+ </ScrollView>+ ) : (+ <View style={styles.content}>{content}</View>+ )}+ </SafeAreaView>+ );+}++const styles = StyleSheet.create({+ safeArea: {+ flex: 1,+ backgroundColor: colors.appBackground,+ },+ content: {+ flex: 1,+ paddingHorizontal: 20,+ paddingBottom: 18,+ },+ scrollContent: {+ flexGrow: 1,+ paddingHorizontal: 20,+ paddingBottom: 28,+ },+ header: {+ paddingTop: 8,+ paddingBottom: 16,+ gap: 4,+ },+ headerWithSubtitle: {+ paddingBottom: 32,+ },+ title: {+ fontFamily: fonts.medium,+ fontSize: 24,+ lineHeight: 30,+ color: colors.gray12,+ },+ subtitle: {+ fontFamily: fonts.regular,+ fontSize: 14,+ lineHeight: 20,+ color: colors.gray10,+ },+ loading: {+ flex: 1,+ alignItems: "center",+ justifyContent: "center",+ paddingVertical: 48,+ },+});diff --git a/apps/mobile/src/components/capCardViewModel.ts b/apps/mobile/src/components/capCardViewModel.tsnew file mode 100644index 000000000..84aae8189--- /dev/null+++ b/apps/mobile/src/components/capCardViewModel.ts@@ -0,0 +1,60 @@+import type { MobileCapSummary } from "@/api/mobile";+import { formatDuration, formatRelativeDate } from "../utils/format";++const clampPercent = (value: number) => {+ const safeValue = Number.isFinite(value) ? value : 0;+ return Math.min(100, Math.max(0, Math.round(safeValue)));+};++const getUploadProgress = (cap: MobileCapSummary) => {+ if (!cap.upload) return null;++ if (cap.upload.phase === "uploading") {+ return clampPercent(+ (cap.upload.total > 0 ? cap.upload.uploaded / cap.upload.total : 0) * 100,+ );+ }++ return clampPercent(cap.upload.processingProgress);+};++const getUploadStatusText = (cap: MobileCapSummary) => {+ if (!cap.upload) return null;++ switch (cap.upload.phase) {+ case "processing":+ return cap.upload.processingMessage ?? "Processing";+ case "generating_thumbnail":+ return cap.upload.processingMessage ?? "Finishing up";+ case "complete":+ return cap.upload.processingMessage ?? "Finishing up";+ case "error":+ return cap.upload.processingError ?? "Upload failed";+ default:+ return `${getUploadProgress(cap) ?? 0}% uploaded`;+ }+};++export const getCapCardViewModel = (+ cap: MobileCapSummary,+ now = new Date(),+) => {+ const duration = formatDuration(cap.durationSeconds);+ const date = formatRelativeDate(cap.createdAt, now);+ const visibility = cap.public ? "Shared" : "Not shared";+ const uploadStatusText = getUploadStatusText(cap);+ const uploadProgress = getUploadProgress(cap);+ const uploadFailed = cap.upload?.phase === "error";++ return {+ date,+ duration,+ visibility,+ uploadStatusText,+ uploadProgress,+ uploadFailed,+ accessibilityLabel: [cap.title, date, visibility, uploadStatusText]+ .filter(Boolean)+ .join(", "),+ };+};