Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): extend record screen and upload status UI
Richie McIlroyd2310f138fcb
diff --git a/apps/mobile/app/record.tsx b/apps/mobile/app/record.tsxindex 93cb640c5..481d25efc 100644--- a/apps/mobile/app/record.tsx+++ b/apps/mobile/app/record.tsx@@ -4,9 +4,16 @@ import {useMicrophonePermissions,} from "expo-camera";import * as Device from "expo-device";+import * as Haptics from "expo-haptics";import { router, Stack } from "expo-router";import { SymbolView } from "expo-symbols";-import { useCallback, useEffect, useRef, useState } from "react";+import {+ type RefObject,+ useCallback,+ useEffect,+ useRef,+ useState,+} from "react";import {ActionSheetIOS,ActivityIndicator,@@ -22,10 +29,17 @@ import {TextInput,View,} from "react-native";+import Animated, {+ useAnimatedStyle,+ useSharedValue,+ withSpring,+} from "react-native-reanimated";import {SafeAreaView,useSafeAreaInsets,} from "react-native-safe-area-context";+import { apiBaseUrl, useAuth } from "@/auth/AuthContext";+import { getProPlan } from "@/billing/pro";import { TeleprompterOverlay } from "@/recording/TeleprompterOverlay";import {clamp,@@ -35,16 +49,28 @@ import {teleprompterLimits,} from "@/recording/teleprompter";import { colors, fonts, radius, squircle } from "@/theme";-import { useRecordingUploads } from "@/uploads/recording-upload-provider";+import { useRecordingUploadActions } from "@/uploads/recording-upload-provider";import CapRecorderView, {type CapRecorderErrorEvent,type CapRecorderSegmentEvent,} from "../modules/cap-recorder";+import {+ type CapScreenRecorderAvailability,+ CapScreenRecorderView,+ cancelScreenRecording,+ getScreenRecordingAvailability,+ getScreenRecordingUpdates,+ prepareScreenRecording,+} from "../modules/cap-screen-recorder";type RecorderPhase = "ready" | "starting" | "recording" | "finishing";+type RecordingMode = "camera" | "screen";const recordingVideoBitrate = 2_500_000;+const screenRecordingVideoBitrate = 1_800_000;const recordingSegmentDurationSeconds = 2;+const freeRecordingDurationSeconds = 5 * 60;+const capturePressSpring = { damping: 18, stiffness: 320, mass: 0.7 } as const;const recordingMonthNames = ["Jan","Feb",@@ -67,6 +93,133 @@ const createRecordingFileName = (recordedAt: Date) => {return `Cap Recording - ${recordedAt.getDate()} ${month} ${recordedAt.getFullYear()} at ${hours}.${minutes}.mp4`;};+const screenModeContent = (+ phase: RecorderPhase,+ availability: CapScreenRecorderAvailability | null,+ prepared: boolean,+) => {+ if (availability?.available === false) {+ return {+ title: "Screen recording unavailable",+ text:+ availability.reason ??+ "Screen recording is unavailable on this iPhone.",+ };+ }+ if (phase === "recording") {+ return {+ title: "Recording your screen",+ text: "Cap is returning Home. Stop from the red screen-sharing indicator or Control Center.",+ };+ }+ if (phase === "finishing") {+ return {+ title: "Finishing up",+ text: "Your recording will upload from Home.",+ };+ }+ if (phase === "starting") {+ return {+ title: "Getting your recording ready",+ text: "Cap is preparing a smooth, upload-ready screen recording.",+ };+ }+ if (prepared) {+ return {+ title: "Ready to record",+ text: "Tap record, then confirm Start Broadcast. Cap returns Home as soon as recording begins.",+ };+ }+ return {+ title: "Record your screen",+ text: "Cap records your screen and microphone, then uploads automatically when you stop.",+ };+};++type ModeSwitcherProps = {+ disabled: boolean;+ mode: RecordingMode;+ onChange: (mode: RecordingMode) => void;+};++function ModeSwitcher({ disabled, mode, onChange }: ModeSwitcherProps) {+ const selection = useSharedValue(mode === "camera" ? 0 : 1);++ useEffect(() => {+ selection.value = withSpring(mode === "camera" ? 0 : 1, {+ damping: 20,+ stiffness: 260,+ mass: 0.75,+ });+ }, [mode, selection]);++ const indicatorStyle = useAnimatedStyle(() => ({+ transform: [{ translateX: selection.value * 112 }],+ }));++ return (+ <View+ accessibilityRole="tablist"+ style={[+ styles.modeSwitcher,+ disabled ? styles.modeSwitcherDisabled : null,+ ]}+ >+ <Animated.View style={[styles.modeIndicator, indicatorStyle]} />+ <Pressable+ accessibilityRole="tab"+ accessibilityLabel="Camera recording"+ accessibilityState={{ disabled, selected: mode === "camera" }}+ disabled={disabled}+ onPress={() => onChange("camera")}+ style={styles.modeOption}+ >+ <SymbolView+ name="camera.fill"+ size={15}+ tintColor={+ mode === "camera" ? colors.gray12 : "rgba(255,255,255,0.58)"+ }+ weight="semibold"+ />+ <Text+ style={[+ styles.modeLabel,+ mode === "camera" ? styles.modeLabelSelected : null,+ ]}+ >+ Camera+ </Text>+ </Pressable>+ <Pressable+ accessibilityRole="tab"+ accessibilityLabel="Screen recording"+ accessibilityState={{ disabled, selected: mode === "screen" }}+ disabled={disabled}+ onPress={() => onChange("screen")}+ style={styles.modeOption}+ >+ <SymbolView+ name="rectangle.on.rectangle"+ size={15}+ tintColor={+ mode === "screen" ? colors.gray12 : "rgba(255,255,255,0.58)"+ }+ weight="semibold"+ />+ <Text+ style={[+ styles.modeLabel,+ mode === "screen" ? styles.modeLabelSelected : null,+ ]}+ >+ Screen+ </Text>+ </Pressable>+ </View>+ );+}+type CircleButtonProps = {accessibilityLabel: string;disabled?: boolean;@@ -171,14 +324,73 @@ function StepperRow({);}+type RecorderTimerPillProps = {+ phase: RecorderPhase;+ startedAt: RefObject<number | null>;+ durationLimitSeconds: number | null;+};++function RecorderTimerPill({+ phase,+ startedAt,+ durationLimitSeconds,+}: RecorderTimerPillProps) {+ const [elapsedSeconds, setElapsedSeconds] = useState(0);++ useEffect(() => {+ if (phase === "ready") {+ setElapsedSeconds(0);+ return;+ }+ if (phase !== "recording") return;+ const updateElapsed = () => {+ if (startedAt.current === null) return;+ setElapsedSeconds((Date.now() - startedAt.current) / 1000);+ };+ updateElapsed();+ const interval = setInterval(updateElapsed, 500);+ return () => clearInterval(interval);+ }, [phase, startedAt]);++ return (+ <View+ accessibilityLabel={+ durationLimitSeconds === null+ ? `Recording time ${formatRecordingDuration(elapsedSeconds)}`+ : `Recording time ${formatRecordingDuration(elapsedSeconds)} of ${formatRecordingDuration(durationLimitSeconds)}`+ }+ style={styles.timerPill}+ >+ {phase === "recording" || phase === "finishing" ? (+ <View style={styles.recordingDot} />+ ) : null}+ <Text style={styles.timerText}>+ {formatRecordingDuration(elapsedSeconds)}+ {durationLimitSeconds === null+ ? ""+ : ` / ${formatRecordingDuration(durationLimitSeconds)}`}+ </Text>+ </View>+ );+}+export default function RecordScreen() {- const recordingUploads = useRecordingUploads();+ const auth = useAuth();+ const recordingUploads = useRecordingUploadActions();const insets = useSafeAreaInsets();+ const captureScale = useSharedValue(1);+ const captureAnimatedStyle = useAnimatedStyle(() => ({+ transform: [{ scale: captureScale.value }],+ }));const cameraRef = useRef<CapRecorderView>(null);const permissionRequestStarted = useRef(false);const discardRecording = useRef(false);const activeRecordingId = useRef<string | null>(null);const recordingStartedAt = useRef<number | null>(null);+ const automaticStopStarted = useRef(false);+ const screenCompletionStarted = useRef(false);+ const screenPreparationAttempted = useRef(false);+ const screenUpdateInFlight = useRef(false);const [cameraPermission, requestCameraPermission, getCameraPermission] =useCameraPermissions();const [@@ -188,10 +400,16 @@ export default function RecordScreen() {] = useMicrophonePermissions();const [permissionRequestFinished, setPermissionRequestFinished] =useState(false);+ const [mode, setMode] = useState<RecordingMode>("camera");const [phase, setPhase] = useState<RecorderPhase>("ready");+ const [screenAvailability, setScreenAvailability] =+ useState<CapScreenRecorderAvailability | null>(null);+ const [screenPrepared, setScreenPrepared] = useState(false);+ const [recordingDurationLimit, setRecordingDurationLimit] = useState<+ number | null+ >(freeRecordingDurationSeconds);const [cameraReady, setCameraReady] = useState(false);const [facing, setFacing] = useState<CameraType>("front");- const [elapsedSeconds, setElapsedSeconds] = useState(0);const [error, setError] = useState<string | null>(null);const [script, setScript] = useState("");const [fontSize, setFontSize] = useState<number>(@@ -214,10 +432,28 @@ export default function RecordScreen() {const isPhysicalDevice = Device.isDevice;const permissionStateLoaded =cameraPermission !== null && microphonePermission !== null;- const cameraActive = permissionsGranted;+ const cameraActive = mode === "camera" && permissionsGranted;const hasScript = script.trim().length > 0;const waitingForPermission =!permissionStateLoaded || !permissionRequestFinished;+ const loadRecordingDurationLimit = useCallback(async () => {+ if (!auth.apiKey) {+ setRecordingDurationLimit(freeRecordingDurationSeconds);+ return freeRecordingDurationSeconds;+ }+ try {+ const plan = await getProPlan({+ apiKey: auth.apiKey,+ baseUrl: apiBaseUrl,+ });+ const limit = plan.upgraded ? null : freeRecordingDurationSeconds;+ setRecordingDurationLimit(limit);+ return limit;+ } catch {+ setRecordingDurationLimit(freeRecordingDurationSeconds);+ return freeRecordingDurationSeconds;+ }+ }, [auth.apiKey]);const requestPermissions = useCallback(async () => {setPermissionRequestFinished(false);const nextCameraPermission = cameraPermission?.granted@@ -266,24 +502,38 @@ export default function RecordScreen() {}, [getCameraPermission, getMicrophonePermission, isPhysicalDevice]);useEffect(() => {- if (phase !== "recording" || recordingStartedAt.current === null) return;- const updateElapsed = () => {- if (recordingStartedAt.current === null) return;- setElapsedSeconds((Date.now() - recordingStartedAt.current) / 1000);- };- updateElapsed();- const interval = setInterval(updateElapsed, 500);- return () => clearInterval(interval);- }, [phase]);+ void loadRecordingDurationLimit();+ }, [loadRecordingDurationLimit]);++ useEffect(() => {+ if (!isPhysicalDevice) {+ setScreenAvailability({+ available: false,+ minimumSystemVersion: "15.1",+ reason: "Screen recording requires a physical iPhone.",+ });+ return;+ }+ void getScreenRecordingAvailability()+ .then(setScreenAvailability)+ .catch(() =>+ setScreenAvailability({+ available: false,+ minimumSystemVersion: "15.1",+ reason: "Screen recording is unavailable in this build.",+ }),+ );+ }, [isPhysicalDevice]);const startRecording = useCallback(async () => {if (!cameraRef.current || !cameraReady || phase !== "ready") return;discardRecording.current = false;- setElapsedSeconds(0);+ automaticStopStarted.current = false;setError(null);setPhase("starting");let createdId: string | null = null;try {+ await loadRecordingDurationLimit();const created = await recordingUploads.beginRecording({fileName: createRecordingFileName(new Date()),width: 720,@@ -299,6 +549,7 @@ export default function RecordScreen() {});recordingStartedAt.current = Date.now();setPhase("recording");+ void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);setTeleprompterRestartKey((current) => current + 1);setTeleprompterPlaying(hasScript);} catch (recordingError) {@@ -315,7 +566,235 @@ export default function RecordScreen() {);setPhase("ready");}- }, [cameraReady, hasScript, phase, recordingUploads]);+ }, [+ cameraReady,+ hasScript,+ loadRecordingDurationLimit,+ phase,+ recordingUploads,+ ]);++ const prepareScreenCapture = useCallback(async () => {+ if (+ mode !== "screen" ||+ phase !== "ready" ||+ screenPrepared ||+ screenPreparationAttempted.current ||+ !auth.apiKey ||+ screenAvailability?.available !== true+ ) {+ return;+ }+ screenPreparationAttempted.current = true;+ setError(null);+ setPhase("starting");+ screenCompletionStarted.current = false;+ let createdId: string | null = null;+ try {+ const durationLimit = await loadRecordingDurationLimit();+ const created = await recordingUploads.beginRecording({+ fileName: createRecordingFileName(new Date()),+ width: 720,+ height: 1280,+ fps: 30,+ uploadOwner: "external",+ });+ createdId = created.id;+ activeRecordingId.current = created.id;+ await prepareScreenRecording({+ recordingId: created.id,+ width: 720,+ height: 1280,+ videoBitrate: screenRecordingVideoBitrate,+ segmentDurationSeconds: recordingSegmentDurationSeconds,+ maximumDurationSeconds: durationLimit,+ });+ setScreenPrepared(true);+ setPhase("ready");+ } catch (recordingError) {+ if (createdId) {+ await cancelScreenRecording(createdId).catch(() => undefined);+ await recordingUploads.discardRecording(createdId);+ }+ activeRecordingId.current = null;+ setScreenPrepared(false);+ setPhase("ready");+ setError(+ recordingError instanceof Error+ ? recordingError.message+ : "Cap could not start the screen recording.",+ );+ }+ }, [+ auth.apiKey,+ loadRecordingDurationLimit,+ mode,+ phase,+ recordingUploads,+ screenAvailability?.available,+ screenPrepared,+ ]);++ const finishScreenCaptureUI = useCallback(() => {+ activeRecordingId.current = null;+ recordingStartedAt.current = null;+ setScreenPrepared(false);+ setPhase("ready");+ router.dismissAll();+ router.replace("/(tabs)");+ }, []);++ const reconcileScreenCapture = useCallback(async () => {+ const id = activeRecordingId.current;+ if (+ !id ||+ screenUpdateInFlight.current ||+ screenCompletionStarted.current+ ) {+ return;+ }+ screenUpdateInFlight.current = true;+ try {+ const updates = await getScreenRecordingUpdates(id);+ if (updates.status === "prepared") {+ setScreenPrepared(true);+ return;+ }+ if (updates.status === "recording") {+ if (recordingStartedAt.current === null) {+ recordingStartedAt.current = Date.now();+ }+ screenCompletionStarted.current = true;+ void Haptics.notificationAsync(+ Haptics.NotificationFeedbackType.Success,+ );+ finishScreenCaptureUI();+ return;+ }+ if (updates.status === "uploading") {+ screenCompletionStarted.current = true;+ finishScreenCaptureUI();+ return;+ }+ if (updates.status === "uploaded") {+ screenCompletionStarted.current = true;+ finishScreenCaptureUI();+ return;+ }+ if (updates.status === "finished") {+ screenCompletionStarted.current = true;+ for (const segment of updates.segments) {+ recordingUploads.addSegment(id, segment);+ }+ recordingUploads.finishRecording(id, {+ durationSeconds: updates.durationSeconds ?? 0.1,+ totalBytes: updates.totalBytes,+ });+ finishScreenCaptureUI();+ return;+ }+ if (updates.status === "cancelled") {+ screenCompletionStarted.current = true;+ await cancelScreenRecording(id).catch(() => undefined);+ await recordingUploads.discardRecording(id);+ activeRecordingId.current = null;+ recordingStartedAt.current = null;+ screenCompletionStarted.current = false;+ screenPreparationAttempted.current = false;+ setScreenPrepared(false);+ setPhase("ready");+ return;+ }+ if (updates.status === "failed" || updates.status === "missing") {+ screenCompletionStarted.current = true;+ await cancelScreenRecording(id).catch(() => undefined);+ await recordingUploads.discardRecording(id);+ activeRecordingId.current = null;+ recordingStartedAt.current = null;+ screenCompletionStarted.current = false;+ setScreenPrepared(false);+ setPhase("ready");+ setError(+ updates.error ??+ (updates.status === "missing"+ ? "The screen recording could not be recovered."+ : "The screen recording stopped unexpectedly."),+ );+ }+ } catch (recordingError) {+ setError(+ recordingError instanceof Error+ ? recordingError.message+ : "Cap could not read the screen recording.",+ );+ } finally {+ screenUpdateInFlight.current = false;+ }+ }, [finishScreenCaptureUI, recordingUploads]);++ useEffect(() => {+ if (mode !== "screen" || !screenPrepared || !activeRecordingId.current) {+ return;+ }+ void reconcileScreenCapture();+ const interval = setInterval(() => {+ void reconcileScreenCapture();+ }, 750);+ return () => clearInterval(interval);+ }, [mode, reconcileScreenCapture, screenPrepared]);++ useEffect(() => {+ if (+ mode !== "screen" ||+ phase !== "ready" ||+ screenPrepared ||+ screenAvailability?.available !== true+ ) {+ return;+ }+ void prepareScreenCapture();+ }, [+ mode,+ phase,+ prepareScreenCapture,+ screenAvailability?.available,+ screenPrepared,+ ]);++ const cancelPreparedScreenCapture = useCallback(async () => {+ const id = activeRecordingId.current;+ if (!id) return true;+ const updates = await getScreenRecordingUpdates(id).catch(() => null);+ if (updates?.status === "recording") {+ finishScreenCaptureUI();+ return false;+ }+ await cancelScreenRecording(id).catch(() => undefined);+ await recordingUploads.discardRecording(id);+ activeRecordingId.current = null;+ recordingStartedAt.current = null;+ screenCompletionStarted.current = false;+ screenPreparationAttempted.current = false;+ setScreenPrepared(false);+ setPhase("ready");+ return true;+ }, [finishScreenCaptureUI, recordingUploads]);++ const changeMode = useCallback(+ async (nextMode: RecordingMode) => {+ if (nextMode === mode || phase !== "ready") return;+ if (mode === "screen" && activeRecordingId.current) {+ const cancelled = await cancelPreparedScreenCapture();+ if (!cancelled) return;+ }+ setError(null);+ setCameraReady(false);+ screenPreparationAttempted.current = false;+ setMode(nextMode);+ void Haptics.selectionAsync();+ },+ [cancelPreparedScreenCapture, mode, phase],+ );const stopRecording = useCallback(async () => {if (phase !== "recording") return;@@ -336,8 +815,11 @@ export default function RecordScreen() {recordingUploads.finishRecording(id, result);activeRecordingId.current = null;recordingStartedAt.current = null;- setElapsedSeconds(0);setPhase("ready");+ void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);+ router.dismissAll();+ router.replace("/(tabs)");+ return;} catch (recordingError) {if (id) {await recordingUploads.discardRecording(id);@@ -353,7 +835,56 @@ export default function RecordScreen() {}}, [phase, recordingUploads]);+ useEffect(() => {+ if (+ mode !== "camera" ||+ phase !== "recording" ||+ recordingDurationLimit === null+ ) {+ return;+ }+ const stopAtLimit = () => {+ if (+ recordingStartedAt.current === null ||+ automaticStopStarted.current ||+ Date.now() - recordingStartedAt.current < recordingDurationLimit * 1000+ ) {+ return;+ }+ automaticStopStarted.current = true;+ void stopRecording();+ };+ stopAtLimit();+ const interval = setInterval(stopAtLimit, 250);+ return () => clearInterval(interval);+ }, [mode, phase, recordingDurationLimit, stopRecording]);+const closeRecorder = useCallback(() => {+ if (mode === "screen") {+ if (phase === "recording") {+ ActionSheetIOS.showActionSheetWithOptions(+ {+ cancelButtonIndex: 0,+ message:+ "Use the red screen-sharing indicator or Control Center to stop. Cap will finish the upload in the background.",+ options: ["Keep recording"],+ title: "Screen recording is active",+ userInterfaceStyle: "dark",+ },+ () => undefined,+ );+ return;+ }+ if (phase === "starting" || phase === "finishing") return;+ if (activeRecordingId.current) {+ void cancelPreparedScreenCapture().then((cancelled) => {+ if (cancelled) router.back();+ });+ return;+ }+ router.back();+ return;+ }if (phase === "recording") {ActionSheetIOS.showActionSheetWithOptions({@@ -374,7 +905,7 @@ export default function RecordScreen() {}if (phase === "starting" || phase === "finishing") return;router.back();- }, [phase, stopRecording]);+ }, [cancelPreparedScreenCapture, mode, phase, stopRecording]);const openEditor = useCallback(() => {if (phase !== "ready") return;@@ -415,7 +946,6 @@ export default function RecordScreen() {}activeRecordingId.current = null;recordingStartedAt.current = null;- setElapsedSeconds(0);setTeleprompterPlaying(false);setPhase("ready");void recordingUploads.discardRecording(id);@@ -463,28 +993,23 @@ export default function RecordScreen() {);}- if (!permissionsGranted) {- const missingAccess = cameraPermission?.granted- ? "microphone"- : "camera and microphone";- return (- <View style={styles.permissionScreen}>- <Stack.Screen options={recorderScreenOptions} />- <StatusBar barStyle="light-content" />- <Pressable- accessibilityRole="button"- accessibilityLabel="Close recorder"- onPress={() => router.back()}- style={[styles.permissionClose, { top: insets.top + 8 }]}- >- <SymbolView- name="xmark"- size={18}- tintColor={colors.white}- weight="semibold"- />- </Pressable>- <View style={styles.permissionContent}>+ return (+ <View style={styles.screen}>+ <Stack.Screen options={recorderScreenOptions} />+ <StatusBar barStyle="light-content" />+ {mode === "camera" && permissionsGranted ? (+ <CapRecorderView+ active={cameraActive}+ facing={facing}+ onCameraReady={handleCameraReady}+ onRecordingError={handleRecordingError}+ onRecordingSegment={handleRecordingSegment}+ ref={cameraRef}+ style={StyleSheet.absoluteFill}+ />+ ) : null}+ {mode === "camera" && !permissionsGranted ? (+ <View style={styles.inlinePermissionContent}><View style={styles.permissionIcon}><SymbolViewname="video.fill"@@ -495,8 +1020,8 @@ export default function RecordScreen() {</View><Text style={styles.permissionTitle}>Camera and microphone</Text><Text style={styles.permissionText}>- Cap needs {missingAccess} access to record your video. Your- teleprompter stays on screen and is not recorded.+ Cap needs camera and microphone access for camera recordings. You+ can still switch to Screen below.</Text>{waitingForPermission ? (<ActivityIndicator color={colors.white} />@@ -514,23 +1039,29 @@ export default function RecordScreen() {</Pressable>)}</View>- </View>- );- }-- return (- <View style={styles.screen}>- <Stack.Screen options={recorderScreenOptions} />- <StatusBar barStyle="light-content" />- <CapRecorderView- active={cameraActive}- facing={facing}- onCameraReady={handleCameraReady}- onRecordingError={handleRecordingError}- onRecordingSegment={handleRecordingSegment}- ref={cameraRef}- style={StyleSheet.absoluteFill}- />+ ) : null}+ {mode === "screen" ? (+ <View style={styles.screenCanvas}>+ <View style={styles.permissionIcon}>+ <SymbolView+ name={+ phase === "recording"+ ? "record.circle.fill"+ : "rectangle.on.rectangle"+ }+ size={32}+ tintColor={phase === "recording" ? "#ff453a" : colors.white}+ weight="medium"+ />+ </View>+ <Text style={styles.permissionTitle}>+ {screenModeContent(phase, screenAvailability, screenPrepared).title}+ </Text>+ <Text style={styles.permissionText}>+ {screenModeContent(phase, screenAvailability, screenPrepared).text}+ </Text>+ </View>+ ) : null}<ViewpointerEvents="box-none"style={[styles.topBar, { paddingTop: insets.top + 8 }]}@@ -541,20 +1072,14 @@ export default function RecordScreen() {onPress={closeRecorder}symbol="xmark"/>- <View- accessibilityLabel={`Recording time ${formatRecordingDuration(elapsedSeconds)}`}- style={styles.timerPill}- >- {phase === "recording" || phase === "finishing" ? (- <View style={styles.recordingDot} />- ) : null}- <Text style={styles.timerText}>- {formatRecordingDuration(elapsedSeconds)}- </Text>- </View>+ <RecorderTimerPill+ durationLimitSeconds={recordingDurationLimit}+ phase={phase}+ startedAt={recordingStartedAt}+ /><View style={styles.topBarSpacer} /></View>- {hasScript ? (+ {mode === "camera" && hasScript && permissionsGranted ? (<TeleprompterOverlayfontSize={fontSize}onTogglePlayback={() => setTeleprompterPlaying((current) => !current)}@@ -573,53 +1098,128 @@ export default function RecordScreen() {pointerEvents="box-none"style={[styles.bottomControls, { paddingBottom: insets.bottom + 18 }]}>- <CircleButton- accessibilityLabel={- hasScript ? "Edit teleprompter" : "Add teleprompter"- }- disabled={phase !== "ready"}- onPress={openEditor}- symbol="text.alignleft"- />- <Pressable- accessibilityRole="button"- accessibilityLabel={- phase === "recording" ? "Stop recording" : "Start recording"- }- accessibilityState={{- disabled:- !cameraReady || phase === "starting" || phase === "finishing",- }}- disabled={- !cameraReady || phase === "starting" || phase === "finishing"- }- onPress={() => {- if (phase === "recording") void stopRecording();- else void startRecording();- }}- style={({ pressed }) => [- styles.captureButton,- pressed ? styles.captureButtonPressed : null,- ]}- >- {phase === "starting" || phase === "finishing" ? (- <ActivityIndicator color={colors.white} />- ) : (- <View- style={- phase === "recording" ? styles.captureStop : styles.captureStart+ <View style={styles.captureRow}>+ {mode === "camera" ? (+ <CircleButton+ accessibilityLabel={+ hasScript ? "Edit teleprompter" : "Add teleprompter"}+ disabled={phase !== "ready" || !permissionsGranted}+ onPress={openEditor}+ symbol="text.alignleft"/>+ ) : (+ <View style={styles.topBarSpacer} />)}- </Pressable>- <CircleButton- accessibilityLabel="Switch camera"+ {mode === "camera" ? (+ <Animated.View style={captureAnimatedStyle}>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={+ phase === "recording" ? "Stop recording" : "Start recording"+ }+ accessibilityState={{+ disabled:+ !cameraReady ||+ phase === "starting" ||+ phase === "finishing",+ }}+ disabled={+ !cameraReady || phase === "starting" || phase === "finishing"+ }+ onPressIn={() => {+ void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);+ captureScale.value = withSpring(0.92, capturePressSpring);+ }}+ onPressOut={() => {+ captureScale.value = withSpring(1, capturePressSpring);+ }}+ onPress={() => {+ if (phase === "recording") void stopRecording();+ else void startRecording();+ }}+ style={styles.captureButton}+ >+ {phase === "starting" || phase === "finishing" ? (+ <ActivityIndicator color={colors.white} />+ ) : (+ <View+ style={+ phase === "recording"+ ? styles.captureStop+ : styles.captureStart+ }+ />+ )}+ </Pressable>+ </Animated.View>+ ) : (+ <Animated.View style={captureAnimatedStyle}>+ {screenPrepared ? (+ <View style={styles.captureButton}>+ <CapScreenRecorderView+ enabled+ style={styles.screenSystemPicker}+ />+ <View+ pointerEvents="none"+ style={[styles.captureStart, styles.screenCaptureGlyph]}+ />+ </View>+ ) : (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={+ screenPreparationAttempted.current+ ? "Retry screen recording setup"+ : "Prepare screen recording"+ }+ accessibilityState={{+ disabled:+ phase !== "ready" ||+ !auth.apiKey ||+ screenAvailability?.available !== true,+ }}+ disabled={+ phase !== "ready" ||+ !auth.apiKey ||+ screenAvailability?.available !== true+ }+ onPress={() => {+ screenPreparationAttempted.current = false;+ void prepareScreenCapture();+ }}+ style={styles.captureButton}+ >+ {phase !== "ready" ? (+ <ActivityIndicator color={colors.white} />+ ) : (+ <View style={styles.captureStart} />+ )}+ </Pressable>+ )}+ </Animated.View>+ )}+ {mode === "camera" ? (+ <CircleButton+ accessibilityLabel="Switch camera"+ disabled={phase !== "ready" || !permissionsGranted}+ onPress={() => {+ setCameraReady(false);+ setFacing((current) =>+ current === "front" ? "back" : "front",+ );+ }}+ symbol="camera.rotate"+ />+ ) : (+ <View style={styles.topBarSpacer} />+ )}+ </View>+ <ModeSwitcherdisabled={phase !== "ready"}- onPress={() => {- setCameraReady(false);- setFacing((current) => (current === "front" ? "back" : "front"));- }}- symbol="camera.rotate"+ mode={mode}+ onChange={(nextMode) => void changeMode(nextMode)}/></View><Modal@@ -811,12 +1411,58 @@ const styles = StyleSheet.create({right: 0,bottom: 0,zIndex: 5,- paddingHorizontal: 28,+ paddingHorizontal: 20,paddingTop: 24,+ alignItems: "center",+ gap: 18,+ backgroundColor: "rgba(0,0,0,0.18)",+ },+ captureRow: {+ width: "100%",flexDirection: "row",alignItems: "center",justifyContent: "space-between",- backgroundColor: "rgba(0,0,0,0.12)",+ paddingHorizontal: 8,+ },+ modeSwitcher: {+ width: 232,+ height: 48,+ padding: 4,+ borderRadius: radius.full,+ flexDirection: "row",+ backgroundColor: "rgba(12,14,18,0.78)",+ borderWidth: StyleSheet.hairlineWidth,+ borderColor: "rgba(255,255,255,0.18)",+ },+ modeSwitcherDisabled: {+ opacity: 0.58,+ },+ modeIndicator: {+ position: "absolute",+ top: 4,+ left: 4,+ width: 112,+ height: 40,+ borderRadius: radius.full,+ backgroundColor: colors.white,+ },+ modeOption: {+ zIndex: 1,+ width: 112,+ height: 40,+ borderRadius: radius.full,+ flexDirection: "row",+ alignItems: "center",+ justifyContent: "center",+ gap: 7,+ },+ modeLabel: {+ fontFamily: fonts.medium,+ fontSize: 14,+ color: "rgba(255,255,255,0.58)",+ },+ modeLabelSelected: {+ color: colors.gray12,},captureButton: {width: 82,@@ -827,15 +1473,19 @@ const styles = StyleSheet.create({alignItems: "center",justifyContent: "center",},- captureButtonPressed: {- transform: [{ scale: 0.95 }],- },captureStart: {width: 62,height: 62,borderRadius: radius.full,backgroundColor: "#ff3b30",},+ screenSystemPicker: {+ ...StyleSheet.absoluteFillObject,+ zIndex: 1,+ },+ screenCaptureGlyph: {+ zIndex: 2,+ },captureStop: {width: 31,height: 31,@@ -848,7 +1498,7 @@ const styles = StyleSheet.create({zIndex: 6,left: 24,right: 24,- bottom: 146,+ bottom: 224,borderRadius: radius.md,backgroundColor: "rgba(102,15,20,0.86)",borderWidth: StyleSheet.hairlineWidth,@@ -885,6 +1535,14 @@ const styles = StyleSheet.create({justifyContent: "center",paddingHorizontal: 34,},+ inlinePermissionContent: {+ ...StyleSheet.absoluteFillObject,+ alignItems: "center",+ justifyContent: "center",+ paddingHorizontal: 34,+ paddingBottom: 174,+ backgroundColor: "#08090c",+ },permissionIcon: {width: 72,height: 72,@@ -928,6 +1586,14 @@ const styles = StyleSheet.create({fontSize: 16,color: colors.gray12,},+ screenCanvas: {+ ...StyleSheet.absoluteFillObject,+ alignItems: "center",+ justifyContent: "center",+ paddingHorizontal: 34,+ paddingBottom: 174,+ backgroundColor: "#08090c",+ },editorSafeArea: {flex: 1,backgroundColor: colors.appBackground,diff --git a/apps/mobile/src/components/recording-upload-status.tsx b/apps/mobile/src/components/recording-upload-status.tsxindex 3fe82d3f2..d2f7a2ae7 100644--- a/apps/mobile/src/components/recording-upload-status.tsx+++ b/apps/mobile/src/components/recording-upload-status.tsx@@ -1,97 +1,171 @@+import * as Haptics from "expo-haptics";import { router, useSegments } from "expo-router";-import { SymbolView } from "expo-symbols";+import { useCallback, useEffect, useRef, useState } from "react";import { Pressable, StyleSheet, Text, View } from "react-native";+import Animated, {+ useAnimatedStyle,+ useSharedValue,+ withSpring,+} from "react-native-reanimated";import { useSafeAreaInsets } from "react-native-safe-area-context";import { useAuth } from "@/auth/AuthContext";+import {+ UPLOAD_CARD_HEIGHT,+ UploadStackCard,+} from "@/components/recording-upload-card";import { colors, fonts, radius } from "@/theme";-import { useRecordingUploads } from "@/uploads/recording-upload-provider";-import { recordingUploadProgress } from "@/uploads/recording-upload-queue";+import {+ useRecordingUploadActions,+ useRecordingUploadDisplayQueue,+} from "@/uploads/recording-upload-provider";+import type { RecordingUploadJob } from "@/uploads/recording-upload-queue";++const AnimatedPressable = Animated.createAnimatedComponent(Pressable);+const EXPAND_SPRING = { damping: 20, mass: 0.7, stiffness: 220 };export function RecordingUploadStatus() {const insets = useSafeAreaInsets();const auth = useAuth();const segments = useSegments();- const { queue, retryRecording } = useRecordingUploads();- const job = [...queue.jobs].reverse()[0];- if (!job || auth.status !== "signedIn" || job.status === "recording") {- return null;- }+ const queue = useRecordingUploadDisplayQueue();+ const { retryRecording, discardRecording, dismissRecording } =+ useRecordingUploadActions();+ const [expanded, setExpanded] = useState(false);+ const expandProgress = useSharedValue(0);+ const previousStatuses = useRef(+ new Map<string, RecordingUploadJob["status"]>(),+ );- const percent = Math.round(recordingUploadProgress(job) * 100);- const canRetry = job.status === "failed" && job.durationSeconds !== null;const isRecorder = segments[0] === "record";- const label =- job.status === "failed"- ? canRetry- ? "Upload paused · Tap to retry"- : "Recording could not be recovered"- : job.status === "processing"- ? "Creating your share link"- : job.status === "complete"- ? "Recording ready"- : `Uploading recording · ${percent}%`;- const symbol =- job.status === "failed"- ? "exclamationmark.icloud.fill"- : job.status === "complete"- ? "checkmark.icloud.fill"- : "icloud.and.arrow.up.fill";+ const cards = [...queue.jobs].reverse();+ const total = cards.length;++ useEffect(() => {+ for (const job of queue.jobs) {+ const previous = previousStatuses.current.get(job.id);+ if (previous !== "complete" && job.status === "complete") {+ void Haptics.notificationAsync(+ Haptics.NotificationFeedbackType.Success,+ );+ }+ previousStatuses.current.set(job.id, job.status);+ }+ for (const id of [...previousStatuses.current.keys()]) {+ if (!queue.jobs.some((job) => job.id === id)) {+ previousStatuses.current.delete(id);+ }+ }+ }, [queue.jobs]);++ useEffect(() => {+ expandProgress.value = withSpring(expanded ? 1 : 0, EXPAND_SPRING);+ }, [expanded, expandProgress]);++ useEffect(() => {+ if (expanded && (isRecorder || total <= 1)) setExpanded(false);+ }, [expanded, isRecorder, total]);++ const openCap = useCallback((id: string) => {+ setExpanded(false);+ router.push({ pathname: "/caps/[id]", params: { id } });+ }, []);+ const collapse = useCallback(() => setExpanded(false), []);+ const expand = useCallback(() => setExpanded(true), []);++ const scrimStyle = useAnimatedStyle(() => ({+ opacity: expandProgress.value,+ }));+ const badgeStyle = useAnimatedStyle(() => ({+ opacity: 1 - expandProgress.value,+ }));++ if (auth.status !== "signedIn" || total === 0) return null;++ const visible = isRecorder+ ? cards.slice(0, 1)+ : expanded+ ? cards+ : cards.slice(0, 3);return (- <View pointerEvents="box-none" style={styles.container}>- <Pressable- accessibilityRole="button"- accessibilityLabel={label}- onPress={() => {- if (canRetry) retryRecording(job.id);- else if (job.status === "complete") {- router.push({ pathname: "/caps/[id]", params: { id: job.id } });- }- }}- style={({ pressed }) => [- styles.pill,+ <View pointerEvents="box-none" style={styles.overlay}>+ {isRecorder ? null : (+ <AnimatedPressable+ accessibilityLabel="Collapse uploads"+ accessibilityRole="button"+ onPress={collapse}+ pointerEvents={expanded ? "auto" : "none"}+ style={[styles.scrim, scrimStyle]}+ />+ )}+ <View+ pointerEvents="box-none"+ style={[+ styles.anchor,isRecorder? { top: insets.top + 62 }- : { bottom: insets.bottom + 82 },- pressed ? styles.pillPressed : null,+ : { bottom: insets.bottom + 96 },]}>- <SymbolView name={symbol} size={16} tintColor={colors.white} />- <Text numberOfLines={1} style={styles.label}>- {label}- </Text>- </Pressable>+ {visible.map((job, index) => (+ <UploadStackCard+ key={job.id}+ expandProgress={expandProgress}+ expanded={isRecorder ? false : expanded}+ index={index}+ job={job}+ onDiscard={discardRecording}+ onDismiss={dismissRecording}+ onOpen={openCap}+ onRequestExpand={expand}+ onRetry={retryRecording}+ total={isRecorder ? 1 : total}+ />+ ))}+ {isRecorder || total <= 3 ? null : (+ <Animated.View+ pointerEvents="none"+ style={[styles.badge, badgeStyle]}+ >+ <Text style={styles.badgeText}>+{total - 3}</Text>+ </Animated.View>+ )}+ </View></View>);}const styles = StyleSheet.create({- container: {+ overlay: {...StyleSheet.absoluteFillObject,zIndex: 100,- alignItems: "center",- justifyContent: "flex-end",},- pill: {+ scrim: {+ ...StyleSheet.absoluteFillObject,+ backgroundColor: "rgba(0,0,0,0.28)",+ },+ anchor: {position: "absolute",- maxWidth: "88%",- height: 42,- paddingHorizontal: 15,+ left: 16,+ right: 16,+ height: UPLOAD_CARD_HEIGHT,+ },+ badge: {+ position: "absolute",+ top: -10,+ right: 4,+ minWidth: 24,+ height: 20,+ paddingHorizontal: 7,borderRadius: radius.full,- borderCurve: "continuous",- flexDirection: "row",alignItems: "center",- gap: 8,- backgroundColor: "rgba(18,18,20,0.9)",- boxShadow: "0 5px 18px rgba(0,0,0,0.2)",- },- pillPressed: {- opacity: 0.82,- transform: [{ scale: 0.98 }],+ justifyContent: "center",+ backgroundColor: "rgba(18,18,20,0.92)",},- label: {+ badgeText: {color: colors.white,fontFamily: fonts.medium,- fontSize: 14,+ fontSize: 11,+ fontVariant: ["tabular-nums"],},});diff --git a/apps/mobile/src/screens/record.test.tsx b/apps/mobile/src/screens/record.test.tsxindex ff0303e6a..1a1bd0082 100644--- a/apps/mobile/src/screens/record.test.tsx+++ b/apps/mobile/src/screens/record.test.tsx@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";import { TeleprompterOverlay } from "@/recording/TeleprompterOverlay";import RecordScreen from "../../app/record";import CapRecorderView from "../../modules/cap-recorder";+import { CapScreenRecorderView } from "../../modules/cap-screen-recorder";type HostProps = {children?: ReactNode;@@ -16,6 +17,19 @@ const cameraState = vi.hoisted(() => ({stopRecording: vi.fn(),}));+const screenRecordingState = vi.hoisted(() => ({+ availability: vi.fn(() =>+ Promise.resolve({+ available: true,+ minimumSystemVersion: "15.1",+ reason: null as string | null,+ }),+ ),+ cancelRecording: vi.fn(() => Promise.resolve()),+ getUpdates: vi.fn(),+ prepareRecording: vi.fn(() => Promise.resolve()),+}));+const permissionState = vi.hoisted(() => ({cameraGranted: true,microphoneGranted: true,@@ -27,6 +41,8 @@ const permissionState = vi.hoisted(() => ({const routerState = vi.hoisted(() => ({back: vi.fn(),+ dismissAll: vi.fn(),+ replace: vi.fn(),}));const stackState = vi.hoisted(() => ({@@ -37,6 +53,19 @@ const deviceState = vi.hoisted(() => ({isDevice: true,}));+const authState = vi.hoisted(() => ({+ apiKey: "mobile-key" as string | null,+}));++const billingState = vi.hoisted(() => ({+ getProPlan: vi.fn(() =>+ Promise.resolve({+ upgraded: false,+ stripeSubscriptionStatus: null as string | null,+ }),+ ),+}));+const uploadState = vi.hoisted(() => ({beginRecording: vi.fn(() =>Promise.resolve({ id: "cap_123", shareUrl: "https://cap.so/s/cap_123" }),@@ -135,12 +164,45 @@ vi.mock("../../modules/cap-recorder", async () => {return { default: CapRecorderView };});+vi.mock("../../modules/cap-screen-recorder", async () => {+ const React = await import("react");+ return {+ CapScreenRecorderView: (props: HostProps) =>+ React.createElement("CapScreenRecorderView", props),+ cancelScreenRecording: screenRecordingState.cancelRecording,+ getScreenRecordingAvailability: screenRecordingState.availability,+ getScreenRecordingUpdates: screenRecordingState.getUpdates,+ prepareScreenRecording: screenRecordingState.prepareRecording,+ };+});+vi.mock("expo-device", () => ({get isDevice() {return deviceState.isDevice;},}));+vi.mock("expo-haptics", () => ({+ impactAsync: vi.fn(() => Promise.resolve()),+ notificationAsync: vi.fn(() => Promise.resolve()),+ selectionAsync: vi.fn(() => Promise.resolve()),+ ImpactFeedbackStyle: { Light: "light", Medium: "medium", Heavy: "heavy" },+ NotificationFeedbackType: { Success: "success" },+}));++vi.mock("react-native-reanimated", async () => {+ const React = await import("react");+ return {+ default: {+ View: ({ children, ...props }: HostProps) =>+ React.createElement("Animated.View", props, children),+ },+ useAnimatedStyle: (factory: () => unknown) => factory(),+ useSharedValue: (value: unknown) => ({ value }),+ withSpring: (value: unknown) => value,+ };+});+vi.mock("expo-router", async () => {const React = await import("react");return {@@ -170,9 +232,16 @@ vi.mock("@/recording/TeleprompterOverlay", async () => {});vi.mock("@/uploads/recording-upload-provider", () => ({- useRecordingUploads: () => uploadState,+ useRecordingUploadActions: () => uploadState,}));+vi.mock("@/auth/AuthContext", () => ({+ apiBaseUrl: "https://cap.so",+ useAuth: () => authState,+}));++vi.mock("@/billing/pro", () => billingState);+const renderComponent = async (node: ReactElement,): Promise<ReactTestRenderer> => {@@ -183,8 +252,31 @@ const renderComponent = async (return renderer as unknown as ReactTestRenderer;};+const flushMicrotasks = async () => {+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+};++const selectAndPrepareScreenRecording = async (renderer: ReactTestRenderer) => {+ await act(async () => {+ await flushMicrotasks();+ renderer.root+ .findByProps({ accessibilityLabel: "Screen recording" })+ .props.onPress();+ await flushMicrotasks();+ });+};+describe("RecordScreen", () => {beforeEach(() => {+ authState.apiKey = "mobile-key";+ billingState.getProPlan.mockReset();+ billingState.getProPlan.mockResolvedValue({+ upgraded: false,+ stripeSubscriptionStatus: null,+ });cameraState.startRecording.mockReset();cameraState.startRecording.mockResolvedValue(undefined);cameraState.stopRecording.mockReset();@@ -194,6 +286,8 @@ describe("RecordScreen", () => {totalBytes: 1_400_000,});routerState.back.mockReset();+ routerState.dismissAll.mockReset();+ routerState.replace.mockReset();stackState.options.length = 0;uploadState.beginRecording.mockReset();uploadState.beginRecording.mockResolvedValue({@@ -221,6 +315,24 @@ describe("RecordScreen", () => {permissionState.requestCamera.mockResolvedValue(grantedPermission);permissionState.requestMicrophone.mockReset();permissionState.requestMicrophone.mockResolvedValue(grantedPermission);+ screenRecordingState.cancelRecording.mockReset();+ screenRecordingState.cancelRecording.mockResolvedValue(undefined);+ screenRecordingState.availability.mockReset();+ screenRecordingState.availability.mockResolvedValue({+ available: true,+ minimumSystemVersion: "15.1",+ reason: null,+ });+ screenRecordingState.prepareRecording.mockReset();+ screenRecordingState.prepareRecording.mockResolvedValue(undefined);+ screenRecordingState.getUpdates.mockReset();+ screenRecordingState.getUpdates.mockResolvedValue({+ status: "prepared",+ segments: [],+ durationSeconds: null,+ totalBytes: 0,+ error: null,+ });});it("renders the native segmented iOS camera preview", async () => {@@ -234,6 +346,11 @@ describe("RecordScreen", () => {expect(renderer.root.findByProps({ accessibilityLabel: "Add teleprompter" }),).toBeTruthy();+ expect(+ renderer.root.findByProps({+ accessibilityLabel: "Recording time 0:00 of 5:00",+ }),+ ).toBeTruthy();});it("keeps native modal options stable when the camera becomes ready", async () => {@@ -307,6 +424,166 @@ describe("RecordScreen", () => {expect(Linking.openSettings).toHaveBeenCalledTimes(1);});+ it("prepares ReplayKit and exposes one native record control", async () => {+ permissionState.cameraGranted = false;+ permissionState.microphoneGranted = false;+ permissionState.requestCamera.mockResolvedValueOnce({+ canAskAgain: false,+ expires: "never",+ granted: false,+ status: "denied",+ });+ const renderer = await renderComponent(React.createElement(RecordScreen));++ await act(async () => {+ await flushMicrotasks();+ renderer.root+ .findByProps({ accessibilityLabel: "Screen recording" })+ .props.onPress();+ await flushMicrotasks();+ });++ expect(renderer.root.findAllByType(CapRecorderView)).toHaveLength(0);+ expect(uploadState.beginRecording).toHaveBeenCalledWith({+ fileName: expect.stringMatching(+ /^Cap Recording - \d{1,2} [A-Z][a-z]{2} \d{4} at \d{2}\.\d{2}\.mp4$/,+ ),+ width: 720,+ height: 1280,+ fps: 30,+ uploadOwner: "external",+ });+ expect(screenRecordingState.prepareRecording).toHaveBeenCalledWith({+ recordingId: "cap_123",+ width: 720,+ height: 1280,+ videoBitrate: 1_800_000,+ segmentDurationSeconds: 2,+ maximumDurationSeconds: 300,+ });+ expect(renderer.root.findByType(CapScreenRecorderView)).toBeTruthy();+ });++ it("disables screen capture with a clear system requirement", async () => {+ screenRecordingState.availability.mockResolvedValueOnce({+ available: false,+ minimumSystemVersion: "15.1",+ reason: "Screen recording is unavailable on this iPhone.",+ });+ const renderer = await renderComponent(React.createElement(RecordScreen));++ await act(async () => {+ await flushMicrotasks();+ renderer.root+ .findByProps({ accessibilityLabel: "Screen recording" })+ .props.onPress();+ await flushMicrotasks();+ });++ expect(+ renderer.root.findByProps({+ accessibilityLabel: "Prepare screen recording",+ }).props.accessibilityState,+ ).toEqual({ disabled: true });+ expect(uploadState.beginRecording).not.toHaveBeenCalled();+ });++ it("cancels a prepared ReplayKit recording when the recorder closes", async () => {+ const renderer = await renderComponent(React.createElement(RecordScreen));+ await selectAndPrepareScreenRecording(renderer);++ await act(async () => {+ renderer.root+ .findByProps({ accessibilityLabel: "Close recorder" })+ .props.onPress();+ await flushMicrotasks();+ });++ expect(screenRecordingState.cancelRecording).toHaveBeenCalledWith(+ "cap_123",+ );+ expect(uploadState.discardRecording).toHaveBeenCalledWith("cap_123");+ expect(routerState.back).toHaveBeenCalledTimes(1);+ expect(routerState.replace).not.toHaveBeenCalled();+ });++ it("returns home while the provider reconciles a native screen upload", async () => {+ vi.useFakeTimers();+ try {+ const renderer = await renderComponent(React.createElement(RecordScreen));+ await selectAndPrepareScreenRecording(renderer);+ screenRecordingState.getUpdates.mockResolvedValue({+ status: "uploaded",+ segments: [],+ durationSeconds: 8,+ totalBytes: 1_900_000,+ error: null,+ });++ await act(async () => {+ await vi.advanceTimersByTimeAsync(750);+ await flushMicrotasks();+ });++ expect(screenRecordingState.cancelRecording).not.toHaveBeenCalled();+ expect(routerState.replace).toHaveBeenCalledWith("/(tabs)");+ } finally {+ vi.useRealTimers();+ }+ });++ it("returns home as soon as the native screen upload starts finishing", async () => {+ vi.useFakeTimers();+ try {+ const renderer = await renderComponent(React.createElement(RecordScreen));+ await selectAndPrepareScreenRecording(renderer);+ screenRecordingState.getUpdates.mockResolvedValue({+ status: "uploading",+ segments: [],+ durationSeconds: 8,+ totalBytes: 1_900_000,+ error: null,+ });++ await act(async () => {+ await vi.advanceTimersByTimeAsync(750);+ await flushMicrotasks();+ });++ expect(uploadState.addSegment).not.toHaveBeenCalled();+ expect(uploadState.finishRecording).not.toHaveBeenCalled();+ expect(routerState.dismissAll).toHaveBeenCalledTimes(1);+ expect(routerState.replace).toHaveBeenCalledWith("/(tabs)");+ } finally {+ vi.useRealTimers();+ }+ });++ it("returns home once ReplayKit starts recording", async () => {+ vi.useFakeTimers();+ try {+ const renderer = await renderComponent(React.createElement(RecordScreen));+ await selectAndPrepareScreenRecording(renderer);+ screenRecordingState.getUpdates.mockResolvedValue({+ status: "recording",+ segments: [],+ durationSeconds: null,+ totalBytes: 0,+ error: null,+ });++ await act(async () => {+ await vi.advanceTimersByTimeAsync(750);+ await flushMicrotasks();+ });++ expect(routerState.dismissAll).toHaveBeenCalledTimes(1);+ expect(routerState.replace).toHaveBeenCalledWith("/(tabs)");+ } finally {+ vi.useRealTimers();+ }+ });+it("streams optimized segments and returns to a ready camera after stop", async () => {const renderer = await renderComponent(React.createElement(RecordScreen));@@ -334,7 +611,7 @@ describe("RecordScreen", () => {renderer.root.findByProps({ accessibilityLabel: "Start recording" }).props.onPress();- await Promise.resolve();+ await flushMicrotasks();});expect(uploadState.beginRecording).toHaveBeenCalledWith({fileName: expect.stringMatching(@@ -381,10 +658,63 @@ describe("RecordScreen", () => {segmentCount: 2,totalBytes: 1_400_000,});+ expect(routerState.dismissAll).toHaveBeenCalledTimes(1);+ expect(routerState.replace).toHaveBeenCalledWith("/(tabs)");+ expect(routerState.back).not.toHaveBeenCalled();+ });++ it("automatically stops Free plan recordings at five minutes", async () => {+ vi.useFakeTimers();+ vi.setSystemTime(new Date("2026-07-23T10:00:00.000Z"));+ try {+ const renderer = await renderComponent(React.createElement(RecordScreen));++ await act(async () => {+ renderer.root+ .findByProps({ accessibilityLabel: "Start recording" })+ .props.onPress();+ await flushMicrotasks();+ });+ expect(cameraState.stopRecording).not.toHaveBeenCalled();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(299_999);+ });+ expect(cameraState.stopRecording).not.toHaveBeenCalled();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(1);+ await flushMicrotasks();+ });++ expect(cameraState.stopRecording).toHaveBeenCalledTimes(1);+ expect(uploadState.finishRecording).toHaveBeenCalledTimes(1);+ } finally {+ vi.useRealTimers();+ }+ });++ it("shows existing Pro recordings as unlimited", async () => {+ billingState.getProPlan.mockResolvedValue({+ upgraded: true,+ stripeSubscriptionStatus: "active",+ });+ const renderer = await renderComponent(React.createElement(RecordScreen));++ await act(async () => {+ await flushMicrotasks();+ });+expect(- renderer.root.findByProps({ accessibilityLabel: "Start recording" }),+ renderer.root.findByProps({+ accessibilityLabel: "Recording time 0:00",+ }),).toBeTruthy();- expect(routerState.back).not.toHaveBeenCalled();+ expect(+ renderer.root.findAllByProps({+ accessibilityLabel: "Recording time 0:00 of 5:00",+ }),+ ).toHaveLength(0);});it("cleans up a failed native recording without disabling the preview", async () => {@@ -394,7 +724,7 @@ describe("RecordScreen", () => {renderer.root.findByProps({ accessibilityLabel: "Start recording" }).props.onPress();- await Promise.resolve();+ await flushMicrotasks();});await act(async () => {renderer.root.findByType(CapRecorderView).props.onRecordingError({