@devries-cameron20 / t3code-1 / commits / bfc7177f9f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): pause videos outside visible thread and PR content (#24268)

Julius Marminge committed Oct 25, 2026 at 23:59 UTC bfc7177f9f54b0a4b9d3571d30723a51cd4b31bd
8 files changed +417 -33
apps/mobile/src/components/MediaVideoPlayer.tsx
+12 -29
@@ -1,8 +1,7 @@
1 -import { useIsFocused } from "@react-navigation/native";
1 import { useEvent } from "expo";
2 import { useVideoPlayer, VideoView } from "expo-video";
3 import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
5 -import { AppState, Pressable, View } from "react-native";
4 +import { Pressable, View } from "react-native";
5
6 import { AppActivityIndicator } from "./ui/AppActivityIndicator";
7 import { AppText } from "./ui/AppText";
@@ -10,7 +9,7 @@ import { SymbolView } from "./ui/AppSymbol";
9 import { VideoThumbnailImage } from "./VideoThumbnailImage";
10 import { useMediaActions } from "../state/mediaActions";
11 import { type MediaActionsSource } from "../lib/mediaActionsSource";
13 -import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "../lib/videoAudioSession";
12 +import { useMediaVideoPlayback } from "../lib/useMediaVideoPlayback";
13 import { MediaActionsMenu } from "./MediaActionsMenu";
14 import { createAudioPlaybackSession } from "../lib/audioSession";
15
@@ -19,13 +18,9 @@ function LoadedMediaVideo(props: {
18 readonly resolvePlaybackUri?: () => Promise<string | null>;
19 readonly playRequested: boolean;
20 readonly paused: boolean;
21 + readonly visible: boolean;
22 readonly onPlaybackStart?: () => void;
23 }) {
24 - const focused = useIsFocused();
25 - const fullscreenVideoOpen = useFullscreenVideoOpen();
26 - const paused = props.paused || fullscreenVideoOpen;
27 - const active = useRef(focused && AppState.currentState === "active");
28 - const fullscreen = useRef(false);
24 const [attempt, setAttempt] = useState(0);
25 // Expo's Android player also reports completed playback as idle.
26 const [loadState, setLoadState] = useState<"pending" | "complete" | "error">("pending");
@@ -34,6 +29,8 @@ function LoadedMediaVideo(props: {
29 player.bufferOptions = { preferredForwardBufferDuration: 5 };
30 });
31 const playback = useMemo(() => createAudioPlaybackSession(player, true), [player]);
32 + const { active, fullscreen, createPlayRequest, onFullscreenEnter, onFullscreenExit } =
33 + useMediaVideoPlayback(player, props, playback);
34 const previousPlaybackRequested = useRef(false);
35 const onPlaybackStart = useEffectEvent(() => props.onPlaybackStart?.());
36 useEffect(() => {
@@ -64,31 +61,19 @@ function LoadedMediaVideo(props: {
61 playback.pause();
62 previousPlaybackRequested.current = false;
63 };
67 - }, [player, playback]);
64 + }, [active, fullscreen, player, playback]);
65 const { status } = useEvent(player, "statusChange", { status: player.status });
69 - const { isPlaying } = useEvent(player, "playingChange", { isPlaying: player.playing });
70 - useMediaAudioSessionHold(isPlaying);
66 const loadSource = useEffectEvent(async (signal: AbortSignal) => {
67 + const playIfUninterrupted = createPlayRequest();
68 const uri = props.resolvePlaybackUri ? await props.resolvePlaybackUri() : props.uri;
69 if (signal.aborted) return;
70 if (uri === null) throw new Error("Video unavailable");
71 playback.pause();
72 previousPlaybackRequested.current = false;
73 await player.replaceAsync({ uri, contentType: "progressive" });
78 - if (!signal.aborted && props.playRequested && active.current) await playback.play();
74 + if (!signal.aborted && props.playRequested) await playIfUninterrupted();
75 });
76
81 - useEffect(() => {
82 - active.current = focused && !paused && AppState.currentState === "active";
83 - if (!focused || paused || (!active.current && !fullscreen.current)) playback.pause();
84 - // RN reports both leaving the app and Android fullscreen as background; native handling distinguishes them.
85 - const subscription = AppState.addEventListener("change", (state) => {
86 - active.current = focused && !paused && state === "active";
87 - if (state === "inactive" || (state === "background" && !fullscreen.current)) playback.pause();
88 - });
89 - return () => subscription.remove();
90 - }, [focused, playback, paused]);
91 -
77 useEffect(() => {
78 const controller = new AbortController();
79 // oxlint-disable-next-line react/set-state-in-effect -- Starting a native media load publishes pending before its async result.
@@ -115,12 +100,8 @@ function LoadedMediaVideo(props: {
100 nativeControls
101 contentFit="contain"
102 fullscreenOptions={{ enable: true }}
118 - onFullscreenEnter={() => {
119 - fullscreen.current = true;
120 - }}
121 - onFullscreenExit={() => {
122 - fullscreen.current = false;
123 - }}
103 + onFullscreenEnter={onFullscreenEnter}
104 + onFullscreenExit={onFullscreenExit}
105 allowsPictureInPicture={false}
106 />
107 {loadState === "error" || (loadState === "complete" && status === "error") ? (
@@ -150,6 +131,7 @@ interface MediaVideoPlayerProps {
131 readonly name: string;
132 readonly thumbnailKey: string;
133 readonly thumbnailVisible?: boolean;
134 + readonly visible?: boolean;
135 readonly unavailable?: boolean;
136 readonly expanded?: boolean;
137 readonly autoPlay?: boolean;
@@ -176,6 +158,7 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
158 resolvePlaybackUri={props.resolvePlaybackUri}
159 playRequested={!props.expanded || props.autoPlay === true}
160 paused={(props.paused ?? false) || mediaActions.sharing}
161 + visible={props.visible ?? true}
162 onPlaybackStart={props.onPlaybackStart}
163 />
164 ) : (
apps/mobile/src/features/pull-requests/PullRequestMedia.tsx
+6 -1
@@ -22,6 +22,8 @@ import {
22 type FilePreviewItem,
23 } from "../../components/FilePreviewModal";
24
25 +export const PullRequestMediaVisibleContext = createContext(true);
26 +
27 export const PullRequestMediaContext = createContext<{
28 readonly environmentId: EnvironmentId;
29 readonly cwd: string;
@@ -54,6 +56,7 @@ export function PullRequestMedia(props: {
56 readonly compact?: boolean;
57 }) {
58 const media = usePullRequestMediaUrl(props.url);
59 + const visible = useContext(PullRequestMediaVisibleContext);
60 const context = useContext(PullRequestMediaContext);
61 const withGallery = useFilePreviewGallery();
62 const [image, setImage] = useState<FilePreviewSource | null>(null);
@@ -86,7 +89,7 @@ export function PullRequestMedia(props: {
89 <VideoAttachmentTile
90 name={name}
91 sourceIdentifier={props.url}
89 - thumbnailSource={media.uri}
92 + thumbnailSource={visible ? media.uri : null}
93 style={{ width: 176, height: 112, borderRadius: 16 }}
94 onPress={() =>
95 setVideo({
@@ -105,6 +108,8 @@ export function PullRequestMedia(props: {
108 unavailable={media.unavailable}
109 name={name}
110 thumbnailKey={props.url}
111 + thumbnailVisible={visible}
112 + visible={visible}
113 resolvePlaybackUri={media.resolvePlaybackUri}
114 />
115 )}
apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+4 -1
@@ -111,6 +111,7 @@ import {
111 } from "./PullRequestPresentation";
112 import { usePullRequestFilesSection } from "./PullRequestFiles";
113 import { PullRequestDescription } from "./PullRequestDescription";
114 +import { PullRequestMediaVisibleContext } from "./PullRequestMedia";
115 import { PullRequestMarkdownRepository } from "./PullRequestMarkdown";
116 import {
117 PullRequestStatusMenu,
@@ -795,7 +796,9 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
796 listAnimationsReady && !item.key.endsWith(":body") ? PR_ROW_EXIT : undefined
797 }
798 >
798 - {item.content}
799 + <PullRequestMediaVisibleContext value={section === tab}>
800 + {item.content}
801 + </PullRequestMediaVisibleContext>
802 </Animated.View>
803 )}
804 recycleItems={false}
apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
+1 -1
@@ -39,7 +39,7 @@ export function ThreadMarkdownVideo(props: {
39 name={source.name}
40 thumbnailKey={thumbnailKey}
41 thumbnailVisible={visible}
42 - paused={!visible}
42 + visible={visible}
43 onPlaybackStart={props.onPlaybackStart}
44 unavailable={"resource" in source && asset._tag === "Failure"}
45 actionsSource={source.actionsSource}
apps/mobile/src/lib/useMediaVideoPlayback.test.tsx new
+335
@@ -0,0 +1,335 @@
1 +import { act, type ReactNode } from "react";
2 +import { createRoot } from "react-dom/client";
3 +import type { AppStateStatus } from "react-native";
4 +import { expect, it, vi } from "vite-plus/test";
5 +import { EnvironmentId } from "@t3tools/contracts";
6 +
7 +const mocks = vi.hoisted(() => ({
8 + focused: true,
9 + appState: "active" as AppStateStatus,
10 + appStateListeners: new Set<(state: AppStateStatus) => void>(),
11 + players: [] as ReturnType<typeof createPlayer>[],
12 + refresh: vi.fn<() => Promise<string | null>>(),
13 + replace: vi.fn<() => Promise<void>>(),
14 + thumbnail: vi.fn<(key: string, source: unknown, signal: AbortSignal) => Promise<null>>(),
15 +}));
16 +vi.mock("@react-navigation/native", () => ({ useIsFocused: () => mocks.focused }));
17 +vi.mock("react-native", () => ({
18 + Platform: { OS: "ios" },
19 + StyleSheet: { absoluteFill: {} },
20 + View: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
21 + Pressable: ({
22 + children,
23 + onPress,
24 + accessibilityLabel,
25 + }: {
26 + children?: ReactNode;
27 + onPress?: () => void;
28 + accessibilityLabel?: string;
29 + }) => (
30 + <button aria-label={accessibilityLabel} onClick={onPress}>
31 + {children}
32 + </button>
33 + ),
34 + AppState: {
35 + get currentState() {
36 + return mocks.appState;
37 + },
38 + addEventListener: (_event: string, listener: (state: AppStateStatus) => void) => {
39 + mocks.appStateListeners.add(listener);
40 + return { remove: () => mocks.appStateListeners.delete(listener) };
41 + },
42 + },
43 +}));
44 +vi.mock("expo", async () => {
45 + const { useSyncExternalStore } = await import("react");
46 + return {
47 + requireOptionalNativeModule: () => null,
48 + useEvent: (player: ReturnType<typeof createPlayer>, event: string, initial: unknown) => {
49 + const playing = useSyncExternalStore(player.subscribe, () => player.playing);
50 + return event === "playingChange" ? { isPlaying: playing } : initial;
51 + },
52 + };
53 +});
54 +vi.mock("expo-video", async () => {
55 + const { useState } = await import("react");
56 + return {
57 + useVideoPlayer: (
58 + _source: unknown,
59 + initialize: (player: ReturnType<typeof createPlayer>) => void,
60 + ) =>
61 + useState(() => {
62 + const player = createPlayer();
63 + initialize(player);
64 + mocks.players.push(player);
65 + return player;
66 + })[0],
67 + VideoView: (props: { onFullscreenEnter: () => void; onFullscreenExit: () => void }) => (
68 + <div aria-label="Video">
69 + <button aria-label="Enter fullscreen" onClick={props.onFullscreenEnter} />
70 + <button aria-label="Exit fullscreen" onClick={props.onFullscreenExit} />
71 + </div>
72 + ),
73 + };
74 +});
75 +vi.mock("expo-audio", () => ({
76 + AudioModule: { setAudioSessionOwner: vi.fn() },
77 + setAudioModeAsync: vi.fn().mockResolvedValue(undefined),
78 + setIsAudioActiveAsync: vi.fn().mockResolvedValue(undefined),
79 +}));
80 +vi.mock("expo-image", () => ({ Image: () => null }));
81 +vi.mock("../components/ui/AppActivityIndicator", () => ({ AppActivityIndicator: () => null }));
82 +vi.mock("../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
83 +vi.mock("../components/ui/AppText", () => ({
84 + AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
85 +}));
86 +vi.mock("../components/MediaActionsMenu", () => ({
87 + MediaActionsMenu: ({ children }: { children?: ReactNode }) => children,
88 +}));
89 +vi.mock("../components/ui/NativePresentation", () => ({
90 + PresentationSource: ({ children }: { children?: ReactNode }) => children,
91 +}));
92 +vi.mock("../state/mediaActions", () => ({
93 + useMediaActions: () => ({ actions: [], sharing: false }),
94 +}));
95 +vi.mock("../state/assets", () => ({
96 + useAssetUrlState: () => ({ _tag: "Success", url: "https://media.example/clip.mp4" }),
97 + useRefreshAssetUrl: () => mocks.refresh,
98 +}));
99 +vi.mock("./localAttachmentPreview", () => ({ loadLocalAttachmentPreview: vi.fn() }));
100 +vi.mock("./videoThumbnails", () => ({
101 + cachedVideoThumbnail: () => null,
102 + loadVideoThumbnail: mocks.thumbnail,
103 +}));
104 +vi.mock("../components/FilePreviewGallery", () => ({
105 + useFilePreviewGallery: () => (value: unknown) => value,
106 +}));
107 +vi.mock("../components/FilePreviewModal", () => ({ FilePreviewModal: () => null }));
108 +vi.mock("../components/VideoPreviewModal", () => ({ VideoPreviewModal: () => null }));
109 +vi.mock("../features/threads/ThreadMarkdownImage", () => ({ ThreadMarkdownImageView: () => null }));
110 +
111 +import {
112 + ThreadMarkdownVideo,
113 + ThreadMediaVisibleContext,
114 +} from "../features/threads/ThreadMarkdownVideo";
115 +import {
116 + PullRequestMedia,
117 + PullRequestMediaContext,
118 + PullRequestMediaVisibleContext,
119 +} from "../features/pull-requests/PullRequestMedia";
120 +
121 +function createPlayer() {
122 + let playing = false;
123 + const listeners = new Set<() => void>();
124 + const playingListeners = new Set<(event: { isPlaying: boolean }) => void>();
125 + const setPlaying = (next: boolean) => {
126 + playing = next;
127 + for (const listener of listeners) listener();
128 + for (const listener of playingListeners) listener({ isPlaying: next });
129 + };
130 + return {
131 + currentTime: 0,
132 + status: "readyToPlay",
133 + get playing() {
134 + return playing;
135 + },
136 + play: vi.fn(() => setPlaying(true)),
137 + pause: vi.fn(() => setPlaying(false)),
138 + replaceAsync: vi.fn(() => mocks.replace()),
139 + addListener(event: string, listener: (event: { isPlaying: boolean }) => void) {
140 + if (event === "playingChange") playingListeners.add(listener);
141 + return { remove: () => playingListeners.delete(listener) };
142 + },
143 + subscribe(listener: () => void) {
144 + listeners.add(listener);
145 + return () => listeners.delete(listener);
146 + },
147 + };
148 +}
149 +
150 +function setup(kind: "thread" | "PR", compact = false) {
151 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
152 + mocks.focused = true;
153 + mocks.appState = "active";
154 + mocks.players = [];
155 + mocks.appStateListeners.clear();
156 + mocks.refresh.mockReset().mockResolvedValue("https://media.example/clip.mp4");
157 + mocks.replace.mockReset().mockResolvedValue();
158 + mocks.thumbnail.mockReset().mockResolvedValue(null);
159 + const container = document.createElement("div");
160 + const root = createRoot(container);
161 + const environmentId = EnvironmentId.make("test");
162 + return {
163 + render(visible = true) {
164 + act(() =>
165 + root.render(
166 + kind === "thread" ? (
167 + <ThreadMediaVisibleContext value={visible}>
168 + <ThreadMarkdownVideo
169 + source={{
170 + type: "media",
171 + name: "clip.mp4",
172 + mimeType: "video/mp4",
173 + environmentId,
174 + resource: {
175 + _tag: "github-media",
176 + cwd: "/project",
177 + url: "https://github.com/user-attachments/assets/video",
178 + },
179 + }}
180 + />
181 + </ThreadMediaVisibleContext>
182 + ) : (
183 + <PullRequestMediaContext value={{ environmentId, cwd: "/project" }}>
184 + <PullRequestMediaVisibleContext value={visible}>
185 + <PullRequestMedia
186 + url="https://github.com/user-attachments/assets/video"
187 + kind="video"
188 + compact={compact}
189 + />
190 + </PullRequestMediaVisibleContext>
191 + </PullRequestMediaContext>
192 + ),
193 + ),
194 + );
195 + },
196 + async open() {
197 + const button = container.querySelector("button");
198 + expect(button).not.toBeNull();
199 + await act(async () => button!.click());
200 + expect(mocks.players).toHaveLength(1);
201 + return mocks.players[0]!;
202 + },
203 + fullscreen(open: boolean) {
204 + const button = container.querySelector<HTMLButtonElement>(
205 + `[aria-label="${open ? "Enter" : "Exit"} fullscreen"]`,
206 + );
207 + expect(button).not.toBeNull();
208 + act(() => button!.click());
209 + },
210 + appState(state: AppStateStatus) {
211 + mocks.appState = state;
212 + act(() => {
213 + for (const listener of mocks.appStateListeners) listener(state);
214 + });
215 + },
216 + [Symbol.dispose]() {
217 + act(() => root.unmount());
218 + },
219 + };
220 +}
221 +
222 +it.each(["thread", "PR"] as const)(
223 + "retains the %s player and position while hidden and requires deliberate resume",
224 + async (kind) => {
225 + using screen = setup(kind);
226 + screen.render();
227 + const player = await screen.open();
228 + expect(player.playing).toBe(true);
229 + player.currentTime = 37;
230 + screen.render(false);
231 + expect(player.playing).toBe(false);
232 + screen.render(true);
233 + expect(mocks.players).toEqual([player]);
234 + expect(player.replaceAsync).toHaveBeenCalledTimes(1);
235 + expect(player.currentTime).toBe(37);
236 + expect(player.playing).toBe(false);
237 + },
238 +);
239 +
240 +it.each(["thread", "PR"] as const)(
241 + "does not start a hidden %s video when signing or native loading finishes late",
242 + async (kind) => {
243 + using screen = setup(kind);
244 + const signed = Promise.withResolvers<string | null>();
245 + const replaced = Promise.withResolvers<void>();
246 + mocks.refresh.mockReturnValue(signed.promise);
247 + mocks.replace.mockReturnValue(replaced.promise);
248 + screen.render();
249 + const player = await screen.open();
250 + screen.render(false);
251 + await act(async () => signed.resolve("https://media.example/renewed.mp4"));
252 + expect(player.replaceAsync).toHaveBeenCalledTimes(1);
253 + expect(player.play).not.toHaveBeenCalled();
254 + await act(async () => replaced.resolve());
255 + expect(player.play).not.toHaveBeenCalled();
256 + screen.render(true);
257 + expect(player.playing).toBe(false);
258 + expect(player.replaceAsync).toHaveBeenCalledTimes(1);
259 + },
260 +);
261 +
262 +it.each([false, true])(
263 + "stops inactive PR thumbnail requests (compact: %s) and restarts on return",
264 + async (compact) => {
265 + using screen = setup("PR", compact);
266 + screen.render(false);
267 + expect(mocks.thumbnail).not.toHaveBeenCalled();
268 + await act(async () => screen.render(true));
269 + expect(mocks.thumbnail).toHaveBeenCalledTimes(1);
270 + const signal = mocks.thumbnail.mock.calls[0]![2];
271 + expect(signal.aborted).toBe(false);
272 + screen.render(false);
273 + expect(signal.aborted).toBe(true);
274 + expect(mocks.thumbnail).toHaveBeenCalledTimes(1);
275 + await act(async () => screen.render(true));
276 + expect(mocks.thumbnail).toHaveBeenCalledTimes(2);
277 + },
278 +);
279 +
280 +it("pauses on screen blur and app inactivity without resuming on return", async () => {
281 + using screen = setup("thread");
282 + screen.render();
283 + const player = await screen.open();
284 + for (const reason of ["blur", "inactive", "background"] as const) {
285 + act(() => player.play());
286 + player.currentTime = 37;
287 + if (reason === "blur") {
288 + mocks.focused = false;
289 + screen.render();
290 + } else screen.appState(reason);
291 + expect(player.playing, reason).toBe(false);
292 + mocks.focused = true;
293 + screen.appState("active");
294 + screen.render();
295 + expect(player.playing, reason).toBe(false);
296 + expect(player.currentTime).toBe(37);
297 + }
298 + expect(player.replaceAsync).toHaveBeenCalledTimes(1);
299 +});
300 +
301 +it.each(["thread", "PR"] as const)(
302 + "keeps the %s play request cancelled when loading finishes after returning",
303 + async (kind) => {
304 + using screen = setup(kind);
305 + const signed = Promise.withResolvers<string | null>();
306 + const replaced = Promise.withResolvers<void>();
307 + mocks.refresh.mockReturnValue(signed.promise);
308 + mocks.replace.mockReturnValue(replaced.promise);
309 + screen.render();
310 + const player = await screen.open();
311 + screen.render(false);
312 + screen.render(true);
313 + await act(async () => signed.resolve("https://media.example/renewed.mp4"));
314 + await act(async () => replaced.resolve());
315 + expect(player.replaceAsync).toHaveBeenCalledTimes(1);
316 + expect(player.play).not.toHaveBeenCalled();
317 + act(() => player.play());
318 + expect(player.playing).toBe(true);
319 + },
320 +);
321 +
322 +it("pauses when native fullscreen exits while the app remains in the background", async () => {
323 + using screen = setup("thread");
324 + screen.render();
325 + const player = await screen.open();
326 + player.currentTime = 37;
327 + screen.fullscreen(true);
328 + screen.appState("background");
329 + expect(player.playing).toBe(true);
330 + screen.fullscreen(false);
331 + expect(player.playing).toBe(false);
332 + screen.appState("active");
333 + expect(player.playing).toBe(false);
334 + expect(player.currentTime).toBe(37);
335 +});
apps/mobile/src/lib/useMediaVideoPlayback.ts new
+56
@@ -0,0 +1,56 @@
1 +import { useIsFocused } from "@react-navigation/native";
2 +import { useEvent } from "expo";
3 +import type { VideoPlayer } from "expo-video";
4 +import { useCallback, useEffect, useRef } from "react";
5 +import { AppState } from "react-native";
6 +
7 +import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "./videoAudioSession";
8 +
9 +export function useMediaVideoPlayback(
10 + player: VideoPlayer,
11 + options: { readonly paused: boolean; readonly visible?: boolean },
12 + playback: { play(): Promise<void>; pause(): void },
13 +) {
14 + const focused = useIsFocused();
15 + const fullscreenVideoOpen = useFullscreenVideoOpen();
16 + const paused = options.paused || fullscreenVideoOpen || options.visible === false;
17 + const active = useRef(focused && !paused && AppState.currentState === "active");
18 + const fullscreen = useRef(false);
19 + const interruption = useRef(0);
20 + const { isPlaying } = useEvent(player, "playingChange", { isPlaying: player.playing });
21 + useMediaAudioSessionHold(isPlaying);
22 +
23 + useEffect(() => {
24 + active.current = focused && !paused && AppState.currentState === "active";
25 + if (!active.current) interruption.current += 1;
26 + if (!focused || paused || (!active.current && !fullscreen.current)) playback.pause();
27 + // Native background handling distinguishes Android's fullscreen activity
28 + // from leaving the app; React Native reports both as background.
29 + const subscription = AppState.addEventListener("change", (state) => {
30 + active.current = focused && !paused && state === "active";
31 + if (!active.current) interruption.current += 1;
32 + if (state === "inactive" || (state === "background" && !fullscreen.current)) playback.pause();
33 + });
34 + return () => subscription.remove();
35 + }, [focused, playback, paused]);
36 +
37 + const createPlayRequest = useCallback(() => {
38 + const requestedAt = interruption.current;
39 + const requestedWhileActive = active.current;
40 + // Returning to the content must not revive playback interrupted during loading.
41 + return () => {
42 + if (requestedWhileActive && active.current && requestedAt === interruption.current)
43 + return playback.play();
44 + };
45 + }, [playback]);
46 +
47 + const onFullscreenEnter = useCallback(() => {
48 + fullscreen.current = true;
49 + }, []);
50 + const onFullscreenExit = useCallback(() => {
51 + fullscreen.current = false;
52 + if (!active.current) playback.pause();
53 + }, [playback]);
54 +
55 + return { active, fullscreen, createPlayRequest, onFullscreenEnter, onFullscreenExit };
56 +}
apps/mobile/vite.config.ts
+1
@@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
4 import "vite-plus/test/config";
5
6 const reactTests = [
7 + "src/lib/useMediaVideoPlayback.test.tsx",
8 "src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
9 "src/lib/filePreview.test.ts",
10 "src/features/threads/thread-inspector-navigation.test.tsx",
scripts/effect-budget.json
+2 -1
@@ -7,7 +7,7 @@
7 "apps/mobile/src/components/FilePreview.ios.tsx": 1,
8 "apps/mobile/src/components/FilePreview.tsx": 1,
9 "apps/mobile/src/components/FilePreviewModal.tsx": 5,
10 - "apps/mobile/src/components/MediaVideoPlayer.tsx": 3,
10 + "apps/mobile/src/components/MediaVideoPlayer.tsx": 2,
11 "apps/mobile/src/components/PdfPreview.android.tsx": 1,
12 "apps/mobile/src/components/ProjectFavicon.tsx": 1,
13 "apps/mobile/src/components/VideoPreviewModal.ios.tsx": 6,
@@ -145,6 +145,7 @@
145 "apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx": 1,
146 "apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx": 1,
147 "apps/mobile/src/features/workspace/WorkspaceToolbar.tsx": 2,
148 + "apps/mobile/src/lib/useMediaVideoPlayback.ts": 1,
149 "apps/mobile/src/lib/attachmentDocument.ts": 4,
150 "apps/mobile/src/lib/useDelayedStatus.ts": 2,
151 "apps/mobile/src/lib/useUiRuntimeMemoryWarningGc.ts": 1,