Skip to content

Commit 9e7eb10

Browse files
committed
feat(studio): fullscreen preview mode (F key)
Add distraction-free fullscreen mode using the HTML5 Fullscreen API. Press F to enter fullscreen (Esc to exit). When active, the composition fills the screen — timeline, sidebars, and editing overlays are hidden while all playback shortcuts (Space, J/K/L, arrows, etc.) remain functional. A fullscreen toggle button is also added to player controls. Closes heygen-com#995
1 parent 114b83b commit 9e7eb10

3 files changed

Lines changed: 118 additions & 6 deletions

File tree

‎packages/studio/src/components/nle/NLELayout.tsx‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { useState, useCallback, useRef, useEffect, memo, type ReactNode } from "react";
1+
import {
2+
useState,
3+
useCallback,
4+
useRef,
5+
useEffect,
6+
useSyncExternalStore,
7+
memo,
8+
type ReactNode,
9+
} from "react";
210
import { useMountEffect } from "../../hooks/useMountEffect";
311
import { useTimelinePlayer, PlayerControls, Timeline, usePlayerStore } from "../../player";
412
import type { TimelineElement } from "../../player";
@@ -71,6 +79,15 @@ const MIN_TIMELINE_H = 100;
7179
const DEFAULT_TIMELINE_H = 220;
7280
const MIN_PREVIEW_H = 120;
7381

82+
function subscribeFullscreen(cb: () => void) {
83+
document.addEventListener("fullscreenchange", cb);
84+
return () => document.removeEventListener("fullscreenchange", cb);
85+
}
86+
87+
function getFullscreenElement() {
88+
return document.fullscreenElement;
89+
}
90+
7491
export function shouldDisableTimelineWhileCompositionLoading(compositionLoading: boolean): boolean {
7592
return compositionLoading;
7693
}
@@ -248,9 +265,20 @@ export const NLELayout = memo(function NLELayout({
248265
onCompositionLoadingChangeParent?.(compositionLoading);
249266
}, [compositionLoading, onCompositionLoadingChangeParent]);
250267

268+
const fullscreenElement = useSyncExternalStore(subscribeFullscreen, getFullscreenElement);
251269
const isTimelineVisible = timelineVisible ?? true;
252270
const isDragging = useRef(false);
253271
const containerRef = useRef<HTMLDivElement>(null);
272+
const isFullscreen = fullscreenElement === containerRef.current && fullscreenElement != null;
273+
274+
const toggleFullscreen = useCallback(() => {
275+
if (!containerRef.current) return;
276+
if (document.fullscreenElement) {
277+
void document.exitFullscreen();
278+
} else {
279+
void containerRef.current.requestFullscreen();
280+
}
281+
}, []);
254282

255283
const currentLevel = compositionStack[compositionStack.length - 1];
256284
const directUrl = compositionStack.length > 1 ? currentLevel.previewUrl : undefined;
@@ -312,6 +340,7 @@ export const NLELayout = memo(function NLELayout({
312340
className="flex flex-col h-full min-h-0 bg-neutral-950"
313341
onKeyDown={handleKeyDown}
314342
tabIndex={-1}
343+
data-studio-fullscreen-target=""
315344
>
316345
{/* Preview + player controls */}
317346
<div className="flex-1 min-h-0 flex flex-col">
@@ -326,20 +355,26 @@ export const NLELayout = memo(function NLELayout({
326355
refreshKey={refreshKey}
327356
suppressLoadingOverlay={hasLoadedOnceRef.current}
328357
/>
329-
{previewOverlay}
358+
{!isFullscreen && previewOverlay}
330359
</div>
331360
<div className="bg-neutral-950 border-t border-neutral-800/50 flex-shrink-0">
332-
{compositionStack.length > 1 && (
361+
{!isFullscreen && compositionStack.length > 1 && (
333362
<CompositionBreadcrumb
334363
stack={compositionStack}
335364
onNavigate={handleNavigateComposition}
336365
/>
337366
)}
338-
<PlayerControls onTogglePlay={togglePlay} onSeek={seek} disabled={timelineDisabled} />
367+
<PlayerControls
368+
onTogglePlay={togglePlay}
369+
onSeek={seek}
370+
disabled={timelineDisabled}
371+
isFullscreen={isFullscreen}
372+
onToggleFullscreen={toggleFullscreen}
373+
/>
339374
</div>
340375
</div>
341376

342-
{isTimelineVisible ? (
377+
{!isFullscreen && isTimelineVisible ? (
343378
<>
344379
{/* Resize divider */}
345380
<div
@@ -396,7 +431,7 @@ export const NLELayout = memo(function NLELayout({
396431
)}
397432
</div>
398433
</>
399-
) : onToggleTimeline ? (
434+
) : !isFullscreen && onToggleTimeline ? (
400435
<div className="flex-shrink-0 border-t border-neutral-800/50 bg-neutral-950/96">
401436
<div className="flex h-10 items-center justify-between px-3">
402437
<div className="text-[10px] font-medium uppercase tracking-[0.16em] text-neutral-500">

‎packages/studio/src/hooks/useAppHotkeys.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ export function useAppHotkeys({
248248
}
249249
}
250250

251+
// F — toggle fullscreen preview
252+
if (
253+
event.key.toLowerCase() === "f" &&
254+
!event.metaKey &&
255+
!event.ctrlKey &&
256+
!event.altKey &&
257+
!event.shiftKey &&
258+
!isEditableTarget(event.target)
259+
) {
260+
event.preventDefault();
261+
if (document.fullscreenElement) {
262+
void document.exitFullscreen();
263+
} else {
264+
document.querySelector<HTMLElement>("[data-studio-fullscreen-target]")?.requestFullscreen();
265+
}
266+
return;
267+
}
268+
251269
// Delete / Backspace — remove selected element (timeline clip or preview selection)
252270
if (
253271
(event.key === "Delete" || event.key === "Backspace") &&

‎packages/studio/src/player/components/PlayerControls.tsx‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const SHORTCUT_SECTIONS = [
2020
{ key: "⇧L", label: "Toggle loop" },
2121
{ key: "←/→", label: "Step 1 frame" },
2222
{ key: "⇧←/⇧→", label: "Step 10 frames" },
23+
{ key: "F", label: "Toggle fullscreen" },
2324
],
2425
},
2526
{
@@ -49,12 +50,16 @@ interface PlayerControlsProps {
4950
onTogglePlay: () => void;
5051
onSeek: (time: number) => void;
5152
disabled?: boolean;
53+
isFullscreen?: boolean;
54+
onToggleFullscreen?: () => void;
5255
}
5356

5457
export const PlayerControls = memo(function PlayerControls({
5558
onTogglePlay,
5659
onSeek,
5760
disabled = false,
61+
isFullscreen = false,
62+
onToggleFullscreen,
5863
}: PlayerControlsProps) {
5964
// Subscribe to only the fields we render — each selector prevents cascading re-renders
6065
const isPlaying = usePlayerStore((s) => s.isPlaying);
@@ -595,6 +600,60 @@ export const PlayerControls = memo(function PlayerControls({
595600
</svg>
596601
</button>
597602

603+
{/* Fullscreen toggle */}
604+
{onToggleFullscreen && (
605+
<button
606+
type="button"
607+
onClick={() => {
608+
trackStudioEvent("playback", { action: "fullscreen_toggle", active: !isFullscreen });
609+
onToggleFullscreen();
610+
}}
611+
className={`h-7 w-7 flex-shrink-0 flex items-center justify-center rounded-md border transition-colors ${
612+
isFullscreen
613+
? "text-studio-accent bg-studio-accent/10 border-studio-accent/30"
614+
: "border-neutral-700 text-neutral-400 hover:border-neutral-500 hover:bg-neutral-800"
615+
}`}
616+
title={isFullscreen ? "Exit fullscreen (F)" : "Enter fullscreen (F)"}
617+
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
618+
>
619+
{isFullscreen ? (
620+
<svg
621+
width="13"
622+
height="13"
623+
viewBox="0 0 24 24"
624+
fill="none"
625+
stroke="currentColor"
626+
strokeWidth="2"
627+
strokeLinecap="round"
628+
strokeLinejoin="round"
629+
aria-hidden="true"
630+
>
631+
<path d="M8 3v3a2 2 0 0 1-2 2H3" />
632+
<path d="M21 8h-3a2 2 0 0 1-2-2V3" />
633+
<path d="M3 16h3a2 2 0 0 1 2 2v3" />
634+
<path d="M16 21v-3a2 2 0 0 1 2-2h3" />
635+
</svg>
636+
) : (
637+
<svg
638+
width="13"
639+
height="13"
640+
viewBox="0 0 24 24"
641+
fill="none"
642+
stroke="currentColor"
643+
strokeWidth="2"
644+
strokeLinecap="round"
645+
strokeLinejoin="round"
646+
aria-hidden="true"
647+
>
648+
<path d="M8 3H5a2 2 0 0 0-2 2v3" />
649+
<path d="M21 8V5a2 2 0 0 0-2-2h-3" />
650+
<path d="M3 16v3a2 2 0 0 0 2 2h3" />
651+
<path d="M16 21h3a2 2 0 0 0 2-2v-3" />
652+
</svg>
653+
)}
654+
</button>
655+
)}
656+
598657
{/* Keyboard shortcuts + frame jump + work area — click to open panel */}
599658
<div ref={shortcutsPanelRef} className="relative flex-shrink-0">
600659
<button

0 commit comments

Comments
 (0)