Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): wire recording flow in app shell and cap detail
Richie McIlroy85ab343ddbcd
diff --git a/apps/mobile/app/(tabs)/index.tsx b/apps/mobile/app/(tabs)/index.tsxindex 817f7e3c7..bb95f17f5 100644--- a/apps/mobile/app/(tabs)/index.tsx+++ b/apps/mobile/app/(tabs)/index.tsx@@ -525,6 +525,16 @@ export default function CapsScreen() {</View>) : null}<View style={styles.actions}>+ <ActionButton+ label="Record Video"+ accessibilityHint="Opens the camera recorder"+ onPress={() => router.push("./record")}+ disabled={creatingFolder}+ size="sm"+ style={styles.actionButton}+ symbol="video.fill"+ variant="blue"+ /><ActionButtonlabel="New Folder"accessibilityLabel={folderCreationAccessibilityLabel}diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex b5794d72f..dc77e8242 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -1,7 +1,6 @@import "react-native-gesture-handler";import "react-native-reanimated";-import { useFonts } from "expo-font";import { Stack, useSegments } from "expo-router";import {ActivityIndicator,@@ -17,7 +16,9 @@ import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";import { AuthProvider, useAuth } from "@/auth/AuthContext";import { SignInPanel } from "@/auth/SignInPanel";import { signInTitleForSegments } from "@/auth/signInDestination";+import { RecordingUploadStatus } from "@/components/recording-upload-status";import { colors } from "@/theme";+import { RecordingUploadProvider } from "@/uploads/recording-upload-provider";function AppShell() {const auth = useAuth();@@ -59,25 +60,20 @@ function AppShell() {}export default function RootLayout() {- const [fontsLoaded] = useFonts({- "NeueMontreal-Regular": require("../../web/public/fonts/NeueMontreal-Regular.otf"),- "NeueMontreal-Medium": require("../../web/public/fonts/NeueMontreal-Medium.otf"),- "NeueMontreal-Bold": require("../../web/public/fonts/NeueMontreal-Bold.otf"),- });-- if (!fontsLoaded) return null;-return (<GestureHandlerRootViewstyle={{ flex: 1, backgroundColor: colors.appBackground }}><SafeAreaProvider><AuthProvider>- <StatusBar- backgroundColor={colors.appBackground}- barStyle="dark-content"- />- <AppShell />+ <RecordingUploadProvider>+ <StatusBar+ backgroundColor={colors.appBackground}+ barStyle="dark-content"+ />+ <AppShell />+ <RecordingUploadStatus />+ </RecordingUploadProvider></AuthProvider></SafeAreaProvider></GestureHandlerRootView>diff --git a/apps/mobile/app/caps/[id].tsx b/apps/mobile/app/caps/[id].tsxindex 4fb96c809..3de072842 100644--- a/apps/mobile/app/caps/[id].tsx+++ b/apps/mobile/app/caps/[id].tsx@@ -1,4 +1,5 @@import * as Clipboard from "expo-clipboard";+import { Image } from "expo-image";import { router, Stack, useLocalSearchParams } from "expo-router";import { type SFSymbol, SymbolView } from "expo-symbols";import { useVideoPlayer, VideoView } from "expo-video";@@ -6,8 +7,8 @@ import * as WebBrowser from "expo-web-browser";import { useCallback, useEffect, useMemo, useState } from "react";import {ActionSheetIOS,+ ActivityIndicator,Alert,- KeyboardAvoidingView,Linking,Platform,Pressable,@@ -69,6 +70,8 @@ const showPhotosSettingsAlert = () => {const getCapDetailErrorMessage = (error: unknown) =>error instanceof Error ? error.message : "Unable to load this Cap";+const reactionOptions = ["๐", "๐", "๐ฎ", "๐", "๐", "๐", "๐", "๐ฅ"];+type CapDetailOperation = "comment" | "save" | "visibility";type AnalyticsMetricProps = {@@ -103,6 +106,8 @@ export default function CapDetailScreen() {const [copied, setCopied] = useState(false);const [saved, setSaved] = useState(false);const [settingsVisible, setSettingsVisible] = useState(false);+ const [playbackLoading, setPlaybackLoading] = useState(false);+ const [playbackError, setPlaybackError] = useState<string | null>(null);const player = useVideoPlayer(null);const load = useCallback(async () => {@@ -130,9 +135,33 @@ export default function CapDetailScreen() {}, [load]);useEffect(() => {- if (!playback?.url) return;- player.replace(playback.url);- }, [playback?.url, player]);+ if (!playback?.url) {+ setPlaybackLoading(false);+ setPlaybackError(null);+ return;+ }++ let active = true;+ setPlaybackLoading(true);+ setPlaybackError(null);+ player+ .replaceAsync({+ uri: playback.url,+ contentType: playback.kind === "hls" ? "hls" : "progressive",+ })+ .then(() => {+ if (active) setPlaybackLoading(false);+ })+ .catch((error: unknown) => {+ if (!active) return;+ setPlaybackLoading(false);+ setPlaybackError(getCapDetailErrorMessage(error));+ });++ return () => {+ active = false;+ };+ }, [playback, player]);useEffect(() => {if (!copied) return;@@ -216,14 +245,18 @@ export default function CapDetailScreen() {content: trimmed,timestamp: null,});- setDetail({- ...detail,- comments: [...detail.comments, created],- cap: {- ...detail.cap,- commentCount: detail.cap.commentCount + 1,- },- });+ setDetail((current) =>+ current+ ? {+ ...current,+ comments: [...current.comments, created],+ cap: {+ ...current.cap,+ commentCount: current.cap.commentCount + 1,+ },+ }+ : current,+ );setComment("");} catch (error) {Alert.alert(@@ -242,14 +275,18 @@ export default function CapDetailScreen() {content: emoji,timestamp: null,});- setDetail({- ...detail,- comments: [...detail.comments, created],- cap: {- ...detail.cap,- reactionCount: detail.cap.reactionCount + 1,- },- });+ setDetail((current) =>+ current+ ? {+ ...current,+ comments: [...current.comments, created],+ cap: {+ ...current.cap,+ reactionCount: current.cap.reactionCount + 1,+ },+ }+ : current,+ );} catch (error) {Alert.alert("Reaction failed",@@ -400,10 +437,7 @@ export default function CapDetailScreen() {}return (- <KeyboardAvoidingView- style={styles.keyboard}- behavior={Platform.OS === "ios" ? "padding" : undefined}- >+ <View style={styles.container}><Stack.Screenoptions={{headerShown: true,@@ -446,7 +480,12 @@ export default function CapDetailScreen() {title: detail?.cap.title ?? "Cap",}}/>- <Screen loading={loading} scroll safeEdges={["left", "right"]}>+ <Screen+ automaticallyAdjustKeyboardInsets+ loading={loading}+ scroll+ safeEdges={["left", "right"]}+ >{loadError ? (<ViewaccessibilityLabel={`Cap detail error: ${loadError}`}@@ -476,12 +515,52 @@ export default function CapDetailScreen() {<><View style={styles.videoFrame}>{playback?.url ? (- <VideoView- player={player}- style={styles.video}- fullscreenOptions={{ enable: true }}- allowsPictureInPicture- />+ <>+ <VideoView+ allowsPictureInPicture+ contentFit="contain"+ fullscreenOptions={{ enable: true }}+ nativeControls+ player={player}+ style={styles.video}+ />+ {playbackLoading ? (+ <View style={styles.videoLoadingOverlay}>+ {detail.cap.thumbnailUrl ? (+ <Image+ cachePolicy="memory-disk"+ contentFit="cover"+ source={{ uri: detail.cap.thumbnailUrl }}+ style={StyleSheet.absoluteFillObject}+ />+ ) : null}+ <View style={styles.videoLoadingIndicator}>+ <ActivityIndicator color={colors.white} />+ </View>+ </View>+ ) : null}+ {playbackError ? (+ <View+ accessibilityRole="alert"+ style={styles.videoErrorOverlay}+ >+ <Text style={styles.videoErrorText}>+ Unable to play this video+ </Text>+ <ActionButton+ accessibilityHint="Reloads this video"+ label="Try again"+ onPress={() =>+ setPlayback((current) =>+ current ? { ...current } : current,+ )+ }+ symbol="arrow.clockwise"+ variant="secondary"+ />+ </View>+ ) : null}+ </>) : (<View style={styles.videoPlaceholder}><Text style={styles.placeholderText}>Processing video</Text>@@ -665,10 +744,11 @@ export default function CapDetailScreen() {<Text style={styles.countText}>{reactions.length}</Text></View><View style={styles.reactions}>- {["๐", "๐", "๐ฅ", "๐"].map((emoji) => (+ {reactionOptions.map((emoji) => (<ActionButtonkey={emoji}label={emoji}+ accessibilityLabel={`React with ${emoji}`}accessibilityHint="Adds this reaction"variant="secondary"onPress={() => createReaction(emoji)}@@ -778,12 +858,12 @@ export default function CapDetailScreen() {visibilityDisabledHint={sharingStatusHint}visibilityDisabledAccessibilityValue={sharingStatusAccessibilityValue}/>- </KeyboardAvoidingView>+ </View>);}const styles = StyleSheet.create({- keyboard: {+ container: {flex: 1,},headerAction: {@@ -814,6 +894,33 @@ const styles = StyleSheet.create({width: "100%",height: "100%",},+ videoLoadingOverlay: {+ ...StyleSheet.absoluteFillObject,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: colors.black,+ },+ videoLoadingIndicator: {+ width: 44,+ height: 44,+ borderRadius: radius.full,+ alignItems: "center",+ justifyContent: "center",+ backgroundColor: "rgba(0, 0, 0, 0.62)",+ },+ videoErrorOverlay: {+ ...StyleSheet.absoluteFillObject,+ alignItems: "center",+ justifyContent: "center",+ gap: 10,+ backgroundColor: "rgba(0, 0, 0, 0.86)",+ padding: 16,+ },+ videoErrorText: {+ fontFamily: fonts.medium,+ fontSize: 15,+ color: colors.white,+ },videoPlaceholder: {flex: 1,alignItems: "center",@@ -1035,10 +1142,13 @@ const styles = StyleSheet.create({},reactions: {flexDirection: "row",+ flexWrap: "wrap",gap: 8,},reactionButton: {- width: 52,+ flexBasis: "21%",+ flexGrow: 1,+ maxWidth: 80,},commentInputRow: {flexDirection: "row",diff --git a/apps/mobile/src/components/CapCard.test.ts b/apps/mobile/src/components/CapCard.test.tsindex fc441d203..e966ed662 100644--- a/apps/mobile/src/components/CapCard.test.ts+++ b/apps/mobile/src/components/CapCard.test.ts@@ -271,6 +271,38 @@ describe("CapCard", () => {expect(hasProp(tree, "name", "play.fill")).toBe(false);});+ it("caches thumbnails and falls back cleanly when loading fails", async () => {+ const renderer = await renderComponent(+ React.createElement(CapCard, {+ cap: {+ ...cap,+ thumbnailUrl: "https://cap.so/thumbnail.png",+ },+ onPress: vi.fn(),+ }),+ );+ const [image] = renderer.root.findAll(+ (node) => String(node.type) === "Image",+ );+ if (!image) throw new Error("Thumbnail was not rendered");++ expect(image.props).toMatchObject({+ cachePolicy: "memory-disk",+ contentFit: "cover",+ recyclingKey: cap.id,+ source: { uri: "https://cap.so/thumbnail.png" },+ });++ await act(async () => {+ image.props.onError();+ });++ expect(+ renderer.root.findAll((node) => String(node.type) === "Image"),+ ).toHaveLength(0);+ expect(hasProp(renderer.toJSON(), "fill", "#cecece")).toBe(true);+ });+it("exposes active upload progress as a native progressbar", async () => {const renderer = await renderComponent(React.createElement(CapCard, {diff --git a/apps/mobile/src/components/CapCard.tsx b/apps/mobile/src/components/CapCard.tsxindex 16b698c5b..db68dc164 100644--- a/apps/mobile/src/components/CapCard.tsx+++ b/apps/mobile/src/components/CapCard.tsx@@ -152,6 +152,9 @@ export function CapCard({}: CapCardProps) {const viewModel = getCapCardViewModel(cap, now);const [copyPressed, setCopyPressed] = useState(false);+ const [failedThumbnailUrl, setFailedThumbnailUrl] = useState<string | null>(+ null,+ );const copyResetTimer = useRef<ReturnType<typeof setTimeout> | null>(null);const hasCopyAction = Boolean(onCopyPress);const hasShareAction = Boolean(onSharePress);@@ -267,11 +270,18 @@ export function CapCard({) : null}</View>) : null}- {cap.thumbnailUrl ? (- <Image source={{ uri: cap.thumbnailUrl }} style={styles.thumbnail} />- ) : (- <CapThumbnailPlaceholder />- )}+ <CapThumbnailPlaceholder />+ {cap.thumbnailUrl && cap.thumbnailUrl !== failedThumbnailUrl ? (+ <Image+ cachePolicy="memory-disk"+ contentFit="cover"+ onError={() => setFailedThumbnailUrl(cap.thumbnailUrl)}+ recyclingKey={cap.id}+ source={{ uri: cap.thumbnailUrl }}+ style={styles.thumbnail}+ transition={160}+ />+ ) : null}{viewModel.uploadStatusText ? (<View pointerEvents="none" style={styles.uploadOverlay}><View style={styles.uploadStatusRow}>@@ -446,8 +456,7 @@ const styles = StyleSheet.create({borderBottomColor: colors.gray3,},thumbnail: {- width: "100%",- height: "100%",+ ...StyleSheet.absoluteFillObject,},emptyThumbnail: {flex: 1,diff --git a/apps/mobile/src/components/Screen.test.tsx b/apps/mobile/src/components/Screen.test.tsxindex 0e5fe2458..9a5a0ea6f 100644--- a/apps/mobile/src/components/Screen.test.tsx+++ b/apps/mobile/src/components/Screen.test.tsx@@ -17,11 +17,16 @@ 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> => {+const renderTree = async (node?: React.ReactElement): Promise<JsonNode> => {let renderer: TestRenderer.ReactTestRenderer | null = null;await act(async () => {renderer = TestRenderer.create(- <Screen title="Import" subtitle="Import videos from external sources." />,+ node ?? (+ <Screen+ title="Import"+ subtitle="Import videos from external sources."+ />+ ),);});return (renderer as TestRenderer.ReactTestRenderer | null)?.toJSON() ?? null;@@ -106,4 +111,20 @@ describe("Screen", () => {});expect(hasStyle(tree, { paddingBottom: 32 })).toBe(true);});++ it("can keep focused inputs visible above the keyboard", async () => {+ const tree = await renderTree(+ <Screen automaticallyAdjustKeyboardInsets scroll />,+ );++ expect(tree).toMatchObject({+ type: "SafeAreaView",+ children: [+ {+ type: "ScrollView",+ props: { automaticallyAdjustKeyboardInsets: true },+ },+ ],+ });+ });});diff --git a/apps/mobile/src/components/Screen.tsx b/apps/mobile/src/components/Screen.tsxindex 2e2e456e8..25472fd36 100644--- a/apps/mobile/src/components/Screen.tsx+++ b/apps/mobile/src/components/Screen.tsx@@ -20,6 +20,7 @@ type ScreenProps = {loading?: boolean;footer?: ReactNode;safeEdges?: Edge[];+ automaticallyAdjustKeyboardInsets?: boolean;};const defaultSafeEdges: Edge[] = ["top", "left", "right"];@@ -34,6 +35,7 @@ export function Screen({loading = false,footer,safeEdges = defaultSafeEdges,+ automaticallyAdjustKeyboardInsets = false,}: ScreenProps) {const content = (<>@@ -58,6 +60,7 @@ export function Screen({<SafeAreaView style={styles.safeArea} edges={safeEdges}>{scroll ? (<ScrollView+ automaticallyAdjustKeyboardInsets={automaticallyAdjustKeyboardInsets}contentInsetAdjustmentBehavior="automatic"contentContainerStyle={styles.scrollContent}keyboardDismissMode="interactive"diff --git a/apps/mobile/src/screens/cap-detail.test.tsx b/apps/mobile/src/screens/cap-detail.test.tsxindex c987b6fae..fb0b60b7c 100644--- a/apps/mobile/src/screens/cap-detail.test.tsx+++ b/apps/mobile/src/screens/cap-detail.test.tsx@@ -96,6 +96,10 @@ const authState = vi.hoisted((): { value: AuthStub | null } => ({value: null,}));+const videoPlayerState = vi.hoisted(() => ({+ replaceAsync: vi.fn(() => Promise.resolve()),+}));+const renderComponent = async (node: ReactElement,): Promise<ReactTestRenderer> => {@@ -162,7 +166,7 @@ vi.mock("react-native", async () => {Alert: {alert: vi.fn(),},- KeyboardAvoidingView: createHost("KeyboardAvoidingView"),+ ActivityIndicator: createHost("ActivityIndicator"),Linking: {openSettings: vi.fn(),},@@ -194,6 +198,14 @@ vi.mock("expo-clipboard", () => ({setStringAsync: vi.fn(),}));+vi.mock("expo-image", async () => {+ const React = await import("react");+ return {+ Image: (props: Record<string, unknown>) =>+ React.createElement("Image", props),+ };+});+vi.mock("expo-router", async () => {const React = await import("react");return {@@ -224,9 +236,7 @@ vi.mock("expo-video", async () => {return {VideoView: (props: Record<string, unknown>) =>React.createElement("VideoView", props),- useVideoPlayer: () => ({- replace: vi.fn(),- }),+ useVideoPlayer: () => videoPlayerState,};});@@ -308,15 +318,17 @@ vi.mock("@/components/Screen", async () => {const React = await import("react");return {Screen: ({+ automaticallyAdjustKeyboardInsets,children,loading,}: {+ automaticallyAdjustKeyboardInsets?: boolean;children?: ReactNode;loading?: boolean;}) =>React.createElement("Screen",- null,+ { automaticallyAdjustKeyboardInsets },loading ? React.createElement("Text", null, "Loading") : children,),};@@ -325,6 +337,7 @@ vi.mock("@/components/Screen", async () => {describe("Cap detail screen", () => {beforeEach(() => {vi.clearAllMocks();+ videoPlayerState.replaceAsync.mockResolvedValue(undefined);authState.value = createAuth();});@@ -407,6 +420,53 @@ describe("Cap detail screen", () => {).toBe(true);});+ it("loads segmented playback explicitly as HLS with native controls", async () => {+ const auth = createAuth();+ auth.client.getPlayback = vi.fn(() =>+ Promise.resolve({+ kind: "hls" as const,+ transcriptUrl: null,+ url: "https://cap.so/api/playlist?videoId=video_123",+ }),+ );+ authState.value = auth;++ const renderer = await renderComponent(+ React.createElement(CapDetailScreen),+ );++ expect(videoPlayerState.replaceAsync).toHaveBeenCalledWith({+ contentType: "hls",+ uri: "https://cap.so/api/playlist?videoId=video_123",+ });+ const video = renderer.root.find(+ (node) => String(node.type) === "VideoView",+ );+ expect(video.props).toMatchObject({+ allowsPictureInPicture: true,+ contentFit: "contain",+ nativeControls: true,+ });+ const screen = renderer.root.find((node) => String(node.type) === "Screen");+ expect(screen.props.automaticallyAdjustKeyboardInsets).toBe(true);+ });++ it("offers a full reaction set without clipping it to one row", async () => {+ const renderer = await renderComponent(+ React.createElement(CapDetailScreen),+ );++ for (const emoji of ["๐", "๐", "๐ฎ", "๐", "๐", "๐", "๐", "๐ฅ"]) {+ expect(+ renderer.root.findAll(+ (node) =>+ String(node.type) === "ActionButton" &&+ node.props.accessibilityLabel === `React with ${emoji}`,+ ),+ ).toHaveLength(1);+ }+ });+it("uses native affordances for the header menu and comment composer", async () => {const renderer = await renderComponent(React.createElement(CapDetailScreen),