Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): add cap settings and metadata actions
Richie McIlroy0479e9abbb10
diff --git a/apps/mobile/src/caps/CapSettingsSheet.test.tsx b/apps/mobile/src/caps/CapSettingsSheet.test.tsxnew file mode 100644index 000000000..535558bc5--- /dev/null+++ b/apps/mobile/src/caps/CapSettingsSheet.test.tsx@@ -0,0 +1,319 @@+import { Video } from "@cap/web-domain";+import type { ReactElement, ReactNode } from "react";+import { Switch } from "react-native";+import TestRenderer, {+ act,+ type ReactTestInstance,+ type ReactTestRenderer,+ type ReactTestRendererJSON,+} from "react-test-renderer";+import { describe, expect, it, vi } from "vitest";+import type { MobileCapSummary } from "@/api/mobile";+import { CapSettingsSheet } from "./CapSettingsSheet";++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 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 getInstanceText = (node: ReactTestInstance): string[] =>+ node.children.flatMap((child) =>+ typeof child === "string" ? [child] : getInstanceText(child),+ );++const getNodeType = (node: ReactTestInstance) => String(node.type);+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 {+ Modal: createHost("Modal"),+ Pressable: createHost("Pressable"),+ ScrollView: createHost("ScrollView"),+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ hairlineWidth: 1,+ },+ Switch: createHost("Switch"),+ 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),+ };+});++vi.mock("@/components/GlassSurface", async () => {+ const React = await import("react");+ return {+ GlassSurface: ({ children, ...props }: HostProps) =>+ React.createElement("GlassSurface", props, children),+ };+});++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: null,+ thumbnailUrl: null,+ folderId: null,+ public: true,+ protected: true,+ viewCount: 0,+ commentCount: 0,+ reactionCount: 0,+ upload: null,+};++describe("CapSettingsSheet", () => {+ it("renders native settings rows for Cap actions", async () => {+ const renderer = await renderComponent(+ <CapSettingsSheet+ cap={cap}+ visible+ onClose={vi.fn()}+ onCopyLink={vi.fn()}+ onDelete={vi.fn()}+ onPassword={vi.fn()}+ onRename={vi.fn()}+ onSaveVideo={vi.fn()}+ onShareLink={vi.fn()}+ onViewAnalytics={vi.fn()}+ onVisibilityChange={vi.fn()}+ />,+ );++ expect(getTextNodes(renderer.toJSON())).toEqual(+ expect.arrayContaining([+ "Settings",+ "Launch review",+ "Title",+ "View analytics",+ "Public link",+ "Password",+ "Protected",+ "Copy link",+ "Share",+ "Save video",+ "Delete Cap",+ ]),+ );+ expect(+ renderer.root.findAll((node) => getNodeType(node) === "GlassSurface"),+ ).toHaveLength(4);+ expect(+ renderer.root.find((node) => getNodeType(node) === "Modal").props+ .allowSwipeDismissal,+ ).toBe(true);+ const closeButton = renderer.root.findByProps({+ accessibilityLabel: "Close Cap settings",+ });+ expect(closeButton.props.accessibilityHint).toBe("Dismisses Cap settings");+ expect(closeButton.props.hitSlop).toBe(8);+ expect(+ renderer.root.findByProps({ accessibilityHint: "Renames this Cap" }),+ ).toBeTruthy();+ expect(+ renderer.root.findByProps({+ accessibilityHint: "Copies this Cap link",+ }),+ ).toBeTruthy();+ expect(+ renderer.root.findByProps({+ accessibilityHint: "Opens the native share sheet",+ }),+ ).toBeTruthy();+ expect(+ renderer.root.findByProps({ accessibilityHint: "Deletes this Cap" }),+ ).toBeTruthy();+ });++ it("updates public link with the native switch", async () => {+ const onVisibilityChange = vi.fn();+ const renderer = await renderComponent(+ <CapSettingsSheet+ cap={cap}+ visible+ onClose={vi.fn()}+ onCopyLink={vi.fn()}+ onDelete={vi.fn()}+ onPassword={vi.fn()}+ onRename={vi.fn()}+ onSaveVideo={vi.fn()}+ onShareLink={vi.fn()}+ onVisibilityChange={onVisibilityChange}+ />,+ );++ const switchNode = renderer.root.findByType(Switch);+ expect(switchNode.props).toMatchObject({+ accessibilityLabel: "Public link",+ accessibilityHint: "Toggles public link sharing",+ accessibilityRole: "switch",+ accessibilityState: {+ checked: true,+ disabled: false,+ },+ ios_backgroundColor: "#e0e0e0",+ trackColor: {+ false: "#e0e0e0",+ true: "#8ec8f6",+ },+ });++ switchNode.props.onValueChange(false);++ expect(onVisibilityChange).toHaveBeenCalledWith(cap, false);+ });++ it("marks disabled save actions as unavailable in the native settings sheet", async () => {+ const onSaveVideo = vi.fn();+ const renderer = await renderComponent(+ <CapSettingsSheet+ cap={cap}+ visible+ onClose={vi.fn()}+ onCopyLink={vi.fn()}+ onDelete={vi.fn()}+ onPassword={vi.fn()}+ onRename={vi.fn()}+ onSaveVideo={onSaveVideo}+ onShareLink={vi.fn()}+ onVisibilityChange={vi.fn()}+ saveDisabled+ saveDisabledAccessibilityValue="Saving video for Launch review"+ />,+ );++ const saveRow = renderer.root+ .findAllByProps({ accessibilityRole: "button" })+ .find((node) => getInstanceText(node).includes("Save video"));+ if (!saveRow) throw new Error("Save video row was not rendered");++ expect(saveRow.props.accessibilityState).toEqual({ disabled: true });+ expect(saveRow.props.disabled).toBe(true);+ expect(saveRow.props.accessibilityHint).toBe("Save is in progress");+ expect(saveRow.props.accessibilityValue).toEqual({+ text: "Saving video for Launch review",+ });+ expect(getInstanceText(saveRow)).not.toContain("Saving...");+ expect(resolveStyle(saveRow.props.style)).toMatchObject({+ backgroundColor: "#f9f9f9",+ });+ });++ it("marks disabled sharing updates as in progress", async () => {+ const onVisibilityChange = vi.fn();+ const renderer = await renderComponent(+ <CapSettingsSheet+ cap={cap}+ visible+ onClose={vi.fn()}+ onCopyLink={vi.fn()}+ onDelete={vi.fn()}+ onPassword={vi.fn()}+ onRename={vi.fn()}+ onSaveVideo={vi.fn()}+ onShareLink={vi.fn()}+ onVisibilityChange={onVisibilityChange}+ visibilityDisabled+ visibilityDisabledAccessibilityValue="Updating sharing for Launch review"+ />,+ );++ const publicLinkRow = renderer.root+ .findAllByProps({ accessibilityLabel: "Public link" })+ .find((node) => getInstanceText(node).includes("Public link"));+ if (!publicLinkRow) throw new Error("Public link row was not rendered");+ const switchNode = renderer.root.findByType(Switch);+ expect(publicLinkRow.props.accessibilityValue).toEqual({+ text: "Updating sharing for Launch review",+ });+ expect(getInstanceText(publicLinkRow)).not.toContain("Updating...");+ expect(switchNode.props.accessibilityState).toEqual({+ checked: true,+ disabled: true,+ });+ expect(switchNode.props.accessibilityHint).toBe(+ "Sharing update is in progress",+ );+ expect(switchNode.props.disabled).toBe(true);+ });++ it("opens analytics from the native settings sheet", async () => {+ const onViewAnalytics = vi.fn();+ const renderer = await renderComponent(+ <CapSettingsSheet+ cap={cap}+ visible+ onClose={vi.fn()}+ onCopyLink={vi.fn()}+ onDelete={vi.fn()}+ onPassword={vi.fn()}+ onRename={vi.fn()}+ onSaveVideo={vi.fn()}+ onShareLink={vi.fn()}+ onViewAnalytics={onViewAnalytics}+ onVisibilityChange={vi.fn()}+ />,+ );++ const analyticsRow = renderer.root+ .findAllByProps({ accessibilityRole: "button" })+ .find((node) => getInstanceText(node).includes("View analytics"));+ if (!analyticsRow) throw new Error("Analytics row was not rendered");+ expect(analyticsRow.props.accessibilityHint).toBe(+ "Opens analytics in a browser sheet",+ );++ await act(async () => {+ analyticsRow.props.onPress();+ });++ expect(onViewAnalytics).toHaveBeenCalledWith(cap);+ });+});diff --git a/apps/mobile/src/caps/CapSettingsSheet.tsx b/apps/mobile/src/caps/CapSettingsSheet.tsxnew file mode 100644index 000000000..ceb1ab03b--- /dev/null+++ b/apps/mobile/src/caps/CapSettingsSheet.tsx@@ -0,0 +1,471 @@+import { type SFSymbol, SymbolView } from "expo-symbols";+import type { ReactNode } from "react";+import {+ Modal,+ Pressable,+ ScrollView,+ StyleSheet,+ Switch,+ Text,+ View,+} from "react-native";+import type { MobileCapSummary } from "@/api/mobile";+import { GlassSurface } from "@/components/GlassSurface";+import { colors, fonts, radius, squircle } from "@/theme";++type CapSettingsSheetProps = {+ cap: MobileCapSummary | null;+ visible: boolean;+ onClose: () => void;+ onCopyLink: (cap: MobileCapSummary) => void;+ onShareLink: (cap: MobileCapSummary) => void;+ onRename: (cap: MobileCapSummary) => void;+ onPassword: (cap: MobileCapSummary) => void;+ onViewAnalytics?: (cap: MobileCapSummary) => void;+ onVisibilityChange: (cap: MobileCapSummary, isPublic: boolean) => void;+ onSaveVideo: (cap: MobileCapSummary) => void;+ onDelete: (cap: MobileCapSummary) => void;+ visibilityDisabled?: boolean;+ visibilityDisabledHint?: string;+ visibilityDisabledValue?: string;+ visibilityDisabledAccessibilityValue?: string;+ saveDisabled?: boolean;+ saveDisabledHint?: string;+ saveDisabledValue?: string;+ saveDisabledAccessibilityValue?: string;+};++type SettingsRowProps = {+ label: string;+ value?: string;+ accessibilityValueText?: string;+ symbol: SFSymbol;+ accessibilityHint?: string;+ danger?: boolean;+ disabled?: boolean;+ onPress?: () => void;+ children?: ReactNode;+};++function SettingsRow({+ label,+ value,+ accessibilityValueText,+ symbol,+ accessibilityHint,+ danger = false,+ disabled = false,+ onPress,+ children,+}: SettingsRowProps) {+ const accessibilityValue = accessibilityValueText+ ? { text: accessibilityValueText }+ : value+ ? { text: value }+ : undefined;+ const isAction = Boolean(onPress) || disabled;+ const content = (+ <>+ <View+ style={[+ styles.rowIcon,+ danger ? styles.dangerIcon : null,+ disabled ? styles.rowIconDisabled : null,+ ]}+ >+ <SymbolView+ name={symbol}+ size={16}+ tintColor={+ disabled ? colors.gray9 : danger ? colors.red11 : colors.gray11+ }+ weight="medium"+ />+ </View>+ <Text+ numberOfLines={1}+ style={[+ styles.rowLabel,+ danger ? styles.dangerText : null,+ disabled ? styles.rowLabelDisabled : null,+ ]}+ >+ {label}+ </Text>+ {value ? (+ <Text+ numberOfLines={1}+ style={[styles.rowValue, disabled ? styles.rowValueDisabled : null]}+ >+ {value}+ </Text>+ ) : null}+ {children}+ {isAction ? (+ <SymbolView+ name="chevron.right"+ size={12}+ tintColor={disabled ? colors.gray7 : colors.gray9}+ weight="semibold"+ />+ ) : null}+ </>+ );++ if (!isAction) {+ return (+ <View+ accessibilityLabel={label}+ accessibilityHint={accessibilityHint}+ accessibilityValue={accessibilityValue}+ style={styles.row}+ >+ {content}+ </View>+ );+ }++ return (+ <Pressable+ accessibilityLabel={label}+ accessibilityHint={accessibilityHint}+ accessibilityRole="button"+ accessibilityState={disabled ? { disabled: true } : undefined}+ accessibilityValue={accessibilityValue}+ disabled={disabled}+ onPress={onPress}+ style={({ pressed }) => [+ styles.row,+ pressed && !disabled ? styles.rowPressed : null,+ disabled ? styles.rowDisabled : null,+ ]}+ >+ {content}+ </Pressable>+ );+}++function SettingsSection({+ children,+ title,+}: {+ children: ReactNode;+ title: string;+}) {+ return (+ <View style={styles.section}>+ <Text style={styles.sectionTitle}>{title}</Text>+ <GlassSurface+ fallbackStyle={styles.groupFallback}+ isInteractive+ style={styles.group}+ tintColor={colors.gray1}+ >+ {children}+ </GlassSurface>+ </View>+ );+}++export function CapSettingsSheet({+ cap,+ visible,+ onClose,+ onCopyLink,+ onShareLink,+ onRename,+ onPassword,+ onViewAnalytics,+ onVisibilityChange,+ onSaveVideo,+ onDelete,+ visibilityDisabled = false,+ visibilityDisabledHint,+ visibilityDisabledValue,+ visibilityDisabledAccessibilityValue,+ saveDisabled = false,+ saveDisabledHint,+ saveDisabledValue,+ saveDisabledAccessibilityValue,+}: CapSettingsSheetProps) {+ if (!cap) return null;++ return (+ <Modal+ allowSwipeDismissal+ animationType="slide"+ onRequestClose={onClose}+ presentationStyle="formSheet"+ visible={visible}+ >+ <ScrollView+ contentContainerStyle={styles.sheetContent}+ showsVerticalScrollIndicator={false}+ style={styles.sheet}+ >+ <View style={styles.header}>+ <View style={styles.headerCopy}>+ <Text style={styles.eyebrow}>Settings</Text>+ <Text numberOfLines={1} style={styles.title}>+ {cap.title}+ </Text>+ <Text numberOfLines={1} style={styles.shareUrl}>+ {cap.shareUrl}+ </Text>+ </View>+ <Pressable+ accessibilityLabel="Close Cap settings"+ accessibilityHint="Dismisses Cap settings"+ accessibilityRole="button"+ hitSlop={8}+ onPress={onClose}+ style={({ pressed }) => [+ styles.closeButton,+ pressed ? styles.closeButtonPressed : null,+ ]}+ >+ <SymbolView+ name="xmark"+ size={14}+ tintColor={colors.gray12}+ weight="semibold"+ />+ </Pressable>+ </View>++ <SettingsSection title="Details">+ <SettingsRow+ accessibilityHint="Renames this Cap"+ label="Title"+ onPress={() => onRename(cap)}+ symbol="textformat"+ value={cap.title}+ />+ {onViewAnalytics ? (+ <>+ <View style={styles.separator} />+ <SettingsRow+ accessibilityHint="Opens analytics in a browser sheet"+ label="View analytics"+ onPress={() => onViewAnalytics(cap)}+ symbol="chart.bar"+ />+ </>+ ) : null}+ </SettingsSection>++ <SettingsSection title="Share">+ <SettingsRow+ accessibilityValueText={visibilityDisabledAccessibilityValue}+ label="Public link"+ symbol="link"+ value={visibilityDisabledValue}+ >+ <Switch+ accessibilityHint={+ visibilityDisabled+ ? (visibilityDisabledHint ?? "Sharing update is in progress")+ : "Toggles public link sharing"+ }+ accessibilityLabel="Public link"+ accessibilityRole="switch"+ accessibilityState={{+ checked: cap.public,+ disabled: visibilityDisabled,+ }}+ disabled={visibilityDisabled}+ ios_backgroundColor={colors.gray5}+ onValueChange={(value) => onVisibilityChange(cap, value)}+ trackColor={{ false: colors.gray5, true: colors.blue7 }}+ thumbColor={colors.white}+ value={cap.public}+ />+ </SettingsRow>+ <View style={styles.separator} />+ <SettingsRow+ accessibilityHint="Opens password settings"+ label="Password"+ onPress={() => onPassword(cap)}+ symbol={cap.protected ? "lock.fill" : "lock.open"}+ value={cap.protected ? "Protected" : "Off"}+ />+ </SettingsSection>++ <SettingsSection title="Actions">+ <SettingsRow+ accessibilityHint="Copies this Cap link"+ label="Copy link"+ onPress={() => onCopyLink(cap)}+ symbol="doc.on.doc"+ />+ <View style={styles.separator} />+ <SettingsRow+ accessibilityHint="Opens the native share sheet"+ label="Share"+ onPress={() => onShareLink(cap)}+ symbol="square.and.arrow.up"+ />+ <View style={styles.separator} />+ <SettingsRow+ accessibilityHint={+ saveDisabled+ ? (saveDisabledHint ?? "Save is in progress")+ : "Saves this video to Photos"+ }+ disabled={saveDisabled}+ label="Save video"+ onPress={() => onSaveVideo(cap)}+ symbol="square.and.arrow.down"+ accessibilityValueText={saveDisabledAccessibilityValue}+ value={saveDisabled ? saveDisabledValue : undefined}+ />+ </SettingsSection>++ <SettingsSection title="Danger Zone">+ <SettingsRow+ accessibilityHint="Deletes this Cap"+ danger+ label="Delete Cap"+ onPress={() => onDelete(cap)}+ symbol="trash"+ />+ </SettingsSection>+ </ScrollView>+ </Modal>+ );+}++const styles = StyleSheet.create({+ sheet: {+ flex: 1,+ backgroundColor: colors.appBackground,+ },+ sheetContent: {+ paddingHorizontal: 20,+ paddingTop: 20,+ paddingBottom: 28,+ },+ header: {+ flexDirection: "row",+ alignItems: "flex-start",+ gap: 16,+ paddingTop: 8,+ paddingBottom: 18,+ },+ headerCopy: {+ flex: 1,+ minWidth: 0,+ },+ eyebrow: {+ fontFamily: fonts.medium,+ fontSize: 13,+ lineHeight: 18,+ color: colors.gray10,+ marginBottom: 4,+ },+ title: {+ fontFamily: fonts.medium,+ fontSize: 24,+ lineHeight: 30,+ color: colors.gray12,+ },+ shareUrl: {+ fontFamily: fonts.regular,+ fontSize: 14,+ lineHeight: 20,+ color: colors.gray10,+ marginTop: 4,+ },+ closeButton: {+ width: 34,+ height: 34,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: colors.gray3,+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: colors.gray5,+ ...squircle,+ },+ closeButtonPressed: {+ backgroundColor: colors.gray5,+ },+ section: {+ gap: 8,+ marginBottom: 18,+ },+ sectionTitle: {+ fontFamily: fonts.medium,+ fontSize: 13,+ lineHeight: 18,+ color: colors.gray10,+ paddingHorizontal: 4,+ },+ group: {+ overflow: "hidden",+ borderRadius: radius.md,+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: colors.gray3,+ ...squircle,+ },+ groupFallback: {+ backgroundColor: colors.gray1,+ },+ row: {+ minHeight: 54,+ flexDirection: "row",+ alignItems: "center",+ gap: 12,+ paddingHorizontal: 14,+ paddingVertical: 10,+ },+ rowPressed: {+ backgroundColor: colors.gray2,+ },+ rowDisabled: {+ backgroundColor: colors.gray2,+ },+ rowIcon: {+ width: 28,+ height: 28,+ borderRadius: radius.sm,+ backgroundColor: colors.gray3,+ alignItems: "center",+ justifyContent: "center",+ ...squircle,+ },+ dangerIcon: {+ backgroundColor: colors.red3,+ },+ rowIconDisabled: {+ backgroundColor: colors.gray3,+ },+ rowLabel: {+ flex: 1,+ fontFamily: fonts.regular,+ fontSize: 16,+ lineHeight: 22,+ color: colors.gray12,+ },+ rowValue: {+ maxWidth: "42%",+ fontFamily: fonts.regular,+ fontSize: 14,+ lineHeight: 20,+ color: colors.gray10,+ },+ rowLabelDisabled: {+ color: colors.gray9,+ },+ rowValueDisabled: {+ color: colors.gray9,+ },+ dangerText: {+ color: colors.red11,+ },+ separator: {+ height: StyleSheet.hairlineWidth,+ backgroundColor: colors.gray3,+ marginLeft: 54,+ },+});diff --git a/apps/mobile/src/caps/passwordActions.test.ts b/apps/mobile/src/caps/passwordActions.test.tsnew file mode 100644index 000000000..95d0511aa--- /dev/null+++ b/apps/mobile/src/caps/passwordActions.test.ts@@ -0,0 +1,116 @@+import { Video } from "@cap/web-domain";+import { beforeEach, describe, expect, it, vi } from "vitest";+import type { MobileApiClient, MobileCapSummary } from "@/api/mobile";+import { showCapPasswordActions } from "./passwordActions";++const reactNativeMock = vi.hoisted(() => ({+ ActionSheetIOS: {+ showActionSheetWithOptions: vi.fn(),+ },+ Alert: {+ alert: vi.fn(),+ prompt: vi.fn(),+ },+ Platform: {+ OS: "ios",+ },+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ },+}));++vi.mock("react-native", () => reactNativeMock);++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: null,+ thumbnailUrl: null,+ folderId: null,+ public: true,+ protected: false,+ viewCount: 0,+ commentCount: 0,+ reactionCount: 0,+ upload: null,+};++describe("showCapPasswordActions", () => {+ beforeEach(() => {+ reactNativeMock.ActionSheetIOS.showActionSheetWithOptions.mockClear();+ reactNativeMock.Alert.alert.mockClear();+ reactNativeMock.Alert.prompt.mockClear();+ });++ it("uses a native secure prompt to add a Cap password", async () => {+ const updated = { ...cap, protected: true };+ const updateCapPassword = vi.fn(async () => updated);+ const onUpdated = vi.fn();++ showCapPasswordActions({+ cap,+ client: { updateCapPassword } as unknown as MobileApiClient,+ onUpdated,+ });++ expect(reactNativeMock.Alert.prompt).toHaveBeenCalledWith(+ "Add password",+ "Set a password for this Cap link.",+ expect.any(Array),+ "secure-text",+ );++ const buttons = reactNativeMock.Alert.prompt.mock.calls[0]?.[2];+ const saveButton = Array.isArray(buttons) ? buttons[1] : undefined;+ saveButton?.onPress?.(" secret ");+ await Promise.resolve();+ await Promise.resolve();++ expect(updateCapPassword).toHaveBeenCalledWith("video_123", {+ password: "secret",+ });+ expect(onUpdated).toHaveBeenCalledWith(updated);+ });++ it("uses a native action sheet to remove an existing password", async () => {+ const protectedCap = { ...cap, protected: true };+ const updated = { ...protectedCap, protected: false };+ const updateCapPassword = vi.fn(async () => updated);+ const onUpdated = vi.fn();++ showCapPasswordActions({+ cap: protectedCap,+ client: { updateCapPassword } as unknown as MobileApiClient,+ onUpdated,+ });++ expect(+ reactNativeMock.ActionSheetIOS.showActionSheetWithOptions,+ ).toHaveBeenCalledWith(+ expect.objectContaining({+ cancelButtonIndex: 2,+ destructiveButtonIndex: 1,+ options: ["Change password", "Remove password", "Cancel"],+ title: "Password protected",+ userInterfaceStyle: "light",+ }),+ expect.any(Function),+ );++ const callback =+ reactNativeMock.ActionSheetIOS.showActionSheetWithOptions.mock+ .calls[0]?.[1];+ callback?.(1);+ await Promise.resolve();+ await Promise.resolve();++ expect(updateCapPassword).toHaveBeenCalledWith("video_123", {+ password: null,+ });+ expect(onUpdated).toHaveBeenCalledWith(updated);+ });+});diff --git a/apps/mobile/src/caps/passwordActions.ts b/apps/mobile/src/caps/passwordActions.tsnew file mode 100644index 000000000..62eb4e0f8--- /dev/null+++ b/apps/mobile/src/caps/passwordActions.ts@@ -0,0 +1,97 @@+import {+ ActionSheetIOS,+ Alert,+ type AlertButton,+ Platform,+} from "react-native";+import type { MobileApiClient, MobileCapSummary } from "@/api/mobile";+import { colors } from "@/theme";++type CapPasswordActionsInput = {+ cap: MobileCapSummary;+ client: MobileApiClient;+ onUpdated: (cap: MobileCapSummary) => void | Promise<void>;+};++const getPasswordErrorMessage = (error: unknown) =>+ error instanceof Error ? error.message : "Unable to update this password.";++const savePassword = async ({+ cap,+ client,+ onUpdated,+ password,+}: CapPasswordActionsInput & { password: string | null }) => {+ try {+ const updated = await client.updateCapPassword(cap.id, { password });+ await onUpdated(updated);+ } catch (error) {+ Alert.alert("Password update failed", getPasswordErrorMessage(error));+ }+};++const promptForPassword = (input: CapPasswordActionsInput) => {+ const title = input.cap.protected ? "Change password" : "Add password";++ if (Platform.OS !== "ios") {+ Alert.alert("Password", "Password editing is available on iOS.");+ return;+ }++ Alert.prompt(+ title,+ "Set a password for this Cap link.",+ [+ { text: "Cancel", style: "cancel" },+ {+ text: "Save",+ onPress: (value?: string) => {+ const password = value?.trim() ?? "";+ if (!password) {+ Alert.alert("Password required", "Enter a password for this Cap.");+ return;+ }+ void savePassword({ ...input, password });+ },+ },+ ],+ "secure-text",+ );+};++export const showCapPasswordActions = (input: CapPasswordActionsInput) => {+ if (!input.cap.protected) {+ promptForPassword(input);+ return;+ }++ if (Platform.OS === "ios") {+ ActionSheetIOS.showActionSheetWithOptions(+ {+ cancelButtonIndex: 2,+ destructiveButtonIndex: 1,+ options: ["Change password", "Remove password", "Cancel"],+ title: "Password protected",+ tintColor: colors.blue11,+ userInterfaceStyle: "light",+ },+ (index) => {+ if (index === 0) promptForPassword(input);+ if (index === 1) void savePassword({ ...input, password: null });+ },+ );+ return;+ }++ const buttons: AlertButton[] = [+ {+ text: "Remove password",+ style: "destructive",+ onPress: () => {+ void savePassword({ ...input, password: null });+ },+ },+ { text: "Cancel", style: "cancel" },+ ];+ Alert.alert("Password protected", undefined, buttons);+};diff --git a/apps/mobile/src/caps/saveCapVideo.ts b/apps/mobile/src/caps/saveCapVideo.tsnew file mode 100644index 000000000..dc52b4a42--- /dev/null+++ b/apps/mobile/src/caps/saveCapVideo.ts@@ -0,0 +1,30 @@+import * as FileSystem from "expo-file-system/legacy";+import * as MediaLibrary from "expo-media-library";+import type { MobileApiClient } from "@/api/mobile";++export class PhotosPermissionDeniedError extends Error {+ constructor() {+ super("Photos access needed");+ this.name = "PhotosPermissionDeniedError";+ }+}++const safeFileName = (fileName: string) =>+ fileName.replace(/[^\w.\- ]+/g, "").trim() || "Cap.mp4";++export const saveCapVideoToPhotos = async (+ client: MobileApiClient,+ capId: string,+) => {+ const permission = await MediaLibrary.requestPermissionsAsync();+ if (!permission.granted) throw new PhotosPermissionDeniedError();++ const download = await client.getDownload(capId);+ const target = `${FileSystem.documentDirectory}${safeFileName(+ download.fileName,+ )}`;+ const result = await FileSystem.downloadAsync(download.url, target);+ await MediaLibrary.saveToLibraryAsync(result.uri);++ return download.fileName;+};diff --git a/apps/mobile/src/caps/titleActions.test.ts b/apps/mobile/src/caps/titleActions.test.tsnew file mode 100644index 000000000..0d9622a5a--- /dev/null+++ b/apps/mobile/src/caps/titleActions.test.ts@@ -0,0 +1,93 @@+import { Video } from "@cap/web-domain";+import { beforeEach, describe, expect, it, vi } from "vitest";+import type { MobileApiClient, MobileCapSummary } from "@/api/mobile";+import { showCapTitleActions } from "./titleActions";++const reactNativeMock = vi.hoisted(() => ({+ Alert: {+ alert: vi.fn(),+ prompt: vi.fn(),+ },+ Platform: {+ OS: "ios",+ },+}));++vi.mock("react-native", () => reactNativeMock);++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: null,+ thumbnailUrl: null,+ folderId: null,+ public: true,+ protected: false,+ viewCount: 0,+ commentCount: 0,+ reactionCount: 0,+ upload: null,+};++describe("showCapTitleActions", () => {+ beforeEach(() => {+ reactNativeMock.Alert.alert.mockClear();+ reactNativeMock.Alert.prompt.mockClear();+ reactNativeMock.Platform.OS = "ios";+ });++ it("uses a native prompt to rename a Cap", async () => {+ const updated = { ...cap, title: "Roadmap review" };+ const updateCapTitle = vi.fn(async () => updated);+ const onUpdated = vi.fn();++ showCapTitleActions({+ cap,+ client: { updateCapTitle } as unknown as MobileApiClient,+ onUpdated,+ });++ expect(reactNativeMock.Alert.prompt).toHaveBeenCalledWith(+ "Rename Cap",+ undefined,+ expect.any(Array),+ "plain-text",+ "Launch review",+ );++ const buttons = reactNativeMock.Alert.prompt.mock.calls[0]?.[2];+ const saveButton = Array.isArray(buttons) ? buttons[1] : undefined;+ saveButton?.onPress?.(" Roadmap review ");+ await Promise.resolve();+ await Promise.resolve();++ expect(updateCapTitle).toHaveBeenCalledWith("video_123", {+ title: "Roadmap review",+ });+ expect(onUpdated).toHaveBeenCalledWith(updated);+ });++ it("rejects blank Cap titles before calling the API", () => {+ const updateCapTitle = vi.fn();++ showCapTitleActions({+ cap,+ client: { updateCapTitle } as unknown as MobileApiClient,+ onUpdated: vi.fn(),+ });++ const buttons = reactNativeMock.Alert.prompt.mock.calls[0]?.[2];+ const saveButton = Array.isArray(buttons) ? buttons[1] : undefined;+ saveButton?.onPress?.(" ");++ expect(updateCapTitle).not.toHaveBeenCalled();+ expect(reactNativeMock.Alert.alert).toHaveBeenCalledWith(+ "Title required",+ "Enter a title for this Cap.",+ );+ });+});diff --git a/apps/mobile/src/caps/titleActions.ts b/apps/mobile/src/caps/titleActions.tsnew file mode 100644index 000000000..245243a83--- /dev/null+++ b/apps/mobile/src/caps/titleActions.ts@@ -0,0 +1,53 @@+import { Alert, Platform } from "react-native";+import type { MobileApiClient, MobileCapSummary } from "@/api/mobile";++type CapTitleActionsInput = {+ cap: MobileCapSummary;+ client: MobileApiClient;+ onUpdated: (cap: MobileCapSummary) => void | Promise<void>;+};++const getTitleErrorMessage = (error: unknown) =>+ error instanceof Error ? error.message : "Unable to rename this Cap.";++const saveTitle = async ({+ cap,+ client,+ onUpdated,+ title,+}: CapTitleActionsInput & { title: string }) => {+ try {+ const updated = await client.updateCapTitle(cap.id, { title });+ await onUpdated(updated);+ } catch (error) {+ Alert.alert("Rename failed", getTitleErrorMessage(error));+ }+};++export const showCapTitleActions = (input: CapTitleActionsInput) => {+ if (Platform.OS !== "ios") {+ Alert.alert("Rename Cap", "Title editing is available on iOS.");+ return;+ }++ Alert.prompt(+ "Rename Cap",+ undefined,+ [+ { text: "Cancel", style: "cancel" },+ {+ text: "Save",+ onPress: (value?: string) => {+ const title = value?.trim() ?? "";+ if (!title) {+ Alert.alert("Title required", "Enter a title for this Cap.");+ return;+ }+ void saveTitle({ ...input, title });+ },+ },+ ],+ "plain-text",+ input.cap.title,+ );+};