From 9e6e8acc89909bb59b89aa4bcf8ce843dada69a3 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:28:29 -0400 Subject: [PATCH] fix(channel): stabilize quick-view grids and room navigation --- src/client/channel/components/ChannelStage.tsx | 18 +++++++++++++++--- src/client/channel/stage-layout.ts | 12 +++++++++--- src/client/pages/ChannelPreviewPage.tsx | 9 ++++++--- src/client/pages/channel-preview.css | 4 +++- tests/channel-stage-layout.test.ts | 9 +++++++++ 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/client/channel/components/ChannelStage.tsx b/src/client/channel/components/ChannelStage.tsx index 645c074f5..e356c6662 100644 --- a/src/client/channel/components/ChannelStage.tsx +++ b/src/client/channel/components/ChannelStage.tsx @@ -128,17 +128,29 @@ export function ChannelStage({ sources, focusedId, canSubscribe, onFocus, onWatc const style = getComputedStyle(parent), children = [...parent.children] as HTMLElement[]; const padding = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom); const gap = parseFloat(style.rowGap) || 0; - const availableHeight = Math.min(parent.clientHeight, Math.max(160, window.innerHeight - parent.getBoundingClientRect().top)); + const layout = getComputedStyle(tiles); + const frame = tiles.querySelector('article:not([hidden]) > .c3-video, article:not([hidden]) > .c3-monitor-wait'); + const frameStyle = frame && getComputedStyle(frame); + const [ratioWidth, ratioHeight = 1] = frameStyle?.aspectRatio.split("/").map(Number) ?? []; + const natural = layout.gridAutoRows === "auto" && frameStyle ? { + ratio: ratioWidth / ratioHeight || 0, + insetX: parseFloat(frameStyle.borderLeftWidth) + parseFloat(frameStyle.borderRightWidth) + parseFloat(frameStyle.paddingLeft) + parseFloat(frameStyle.paddingRight), + insetY: parseFloat(frameStyle.borderTopWidth) + parseFloat(frameStyle.borderBottomWidth) + parseFloat(frameStyle.paddingTop) + parseFloat(frameStyle.paddingBottom), + minHeight: parseFloat(frameStyle.minHeight) || 0, + } : undefined; + // A natural grid's height is its output; neither it nor page scrolling sets its budget. + const availableHeight = natural + ? Math.max(160, window.innerHeight - (parent.getBoundingClientRect().top + window.scrollY)) + : parent.clientHeight; const height = availableHeight - padding - children.filter(child => child !== tiles).reduce((sum, child) => sum + child.offsetHeight, 0) - gap * (children.length - 1); const footer = Math.max(...[...tiles.querySelectorAll("article:not([hidden]) > footer")].map(node => node.getBoundingClientRect().height)) + 2; - const layout = getComputedStyle(tiles); const ratios = [...tiles.children].filter(tile => !(tile as HTMLElement).hidden).map(tile => { const video = tile.querySelector('video[data-selected="true"]'); return video?.videoWidth && video.videoHeight ? video.videoWidth / video.videoHeight : 16 / 9; }); setColumns(stageColumns(tiles.clientWidth, height, ratios, parseFloat(layout.columnGap) || 0, footer, - parseFloat(layout.getPropertyValue("--stage-tile-min")))); + parseFloat(layout.getPropertyValue("--stage-tile-min")), natural)); }; const observer = new ResizeObserver(measure); observer.observe(parent); diff --git a/src/client/channel/stage-layout.ts b/src/client/channel/stage-layout.ts index afeb25c70..171774e09 100644 --- a/src/client/channel/stage-layout.ts +++ b/src/client/channel/stage-layout.ts @@ -1,15 +1,21 @@ /** Choose the grid with the largest total contained picture area after source controls. */ // Geometry-based selection: https://github.com/jitsi/jitsi-meet/blob/master/react/features/filmstrip/functions.web.ts -export function stageColumns(width: number, height: number, ratios: readonly number[], gap: number, footer: number, minimumWidth: number): number { +export function stageColumns(width: number, height: number, ratios: readonly number[], gap: number, footer: number, minimumWidth: number, + natural?: { ratio: number; insetX: number; insetY: number; minHeight: number }): number { const count = ratios.length; let selected = 1, largest = 0, empty = Infinity; const maximum = Math.min(count, Math.max(1, Math.floor((width + gap) / (Math.min(width, minimumWidth) + gap)))); + if (natural) selected = maximum; for (let columns = 1; columns <= maximum; columns++) { const rows = Math.ceil(count / columns); const cellWidth = (width - (columns - 1) * gap) / columns - 2; - const videoHeight = (height - (rows - 1) * gap) / rows - footer; + const videoHeight = natural + ? Math.max(natural.minHeight, natural.ratio ? (cellWidth - natural.insetX) / natural.ratio : 0) + : (height - (rows - 1) * gap) / rows - footer; + // Intrinsic rows cannot shrink to the bounded height assumed by a media grid. + if (natural && rows * (videoHeight + natural.insetY + footer) + (rows - 1) * gap > height) continue; const area = ratios.reduce((total, ratio) => { - const pictureWidth = Math.max(0, Math.min(cellWidth, videoHeight * ratio)); + const pictureWidth = Math.max(0, Math.min(cellWidth - (natural?.insetX ?? 0), videoHeight * ratio)); return total + pictureWidth * pictureWidth / ratio; }, 0); const unused = rows * columns - count; diff --git a/src/client/pages/ChannelPreviewPage.tsx b/src/client/pages/ChannelPreviewPage.tsx index fb0cbf73e..cdc410246 100644 --- a/src/client/pages/ChannelPreviewPage.tsx +++ b/src/client/pages/ChannelPreviewPage.tsx @@ -195,7 +195,7 @@ export function ChannelRoomPage({ channel, selected, onSelect, appControl, layou onClose={closeRoomSettings} />} {newRoomName !== null && setNewRoomName(null)} />} -
{layout === "quick" ? @@ -204,13 +204,16 @@ export function ChannelRoomPage({ channel, selected, onSelect, appControl, layou : {state?.channel.name ?? "Piik"}}
+ {layout === "quick" && }
{onLayoutChange && } } />
- {layout !== "quick" &&
{self &&
{self.name}{copy("你的名字", "Your name")}
diff --git a/src/client/pages/channel-preview.css b/src/client/pages/channel-preview.css index e28d249ac..a083984e1 100644 --- a/src/client/pages/channel-preview.css +++ b/src/client/pages/channel-preview.css @@ -246,6 +246,8 @@ .c3-app:has(> .c3-shell[data-layout="quick"]) { height: auto; min-height: 100dvh; } .c3-shell[data-layout="quick"] { display: flex; flex-direction: column; flex: none; width: min(var(--c3-content-width), 1180px); min-height: 0; margin-bottom: 32px; border: 0; border-radius: 0; background: transparent; box-shadow: none; overflow: visible; container-type: inline-size; position: relative; gap: 16px; } .c3-shell[data-layout="quick"] > .c3-site-bar { order: 0; min-height: 58px; padding-inline: 0; background: transparent; } +.c3-shell[data-layout="quick"] > .c3-sidebar { order: 1; flex: none; width: min(100%, 990px); max-height: min(60dvh, 480px); margin-inline: auto; border: 1px solid var(--line); border-radius: var(--c3-surface-radius); background: var(--paper); } +.c3-shell[data-layout="quick"][data-pane="rooms"] .c3-main-body { visibility: visible; } .c3-shell[data-layout="quick"] .c3-main-body { order: 1; flex: none; width: min(100%, 990px); margin: 0 auto; overflow: visible; container-type: inline-size; } .c3-shell[data-layout="quick"] .c3-workspace { display: block; } .c3-shell[data-layout="quick"] .c3-main-body .c3-conversation { display: none; } @@ -253,7 +255,7 @@ .c3-shell[data-layout="quick"] .c3-workspace.has-screens > .c3-monitor:not(.is-theater) { container-type: inline-size; } .c3-shell[data-layout="quick"] .c3-monitor:not(.is-theater) .c3-monitor-grid { flex: none; min-height: 0; grid-auto-rows: auto; } .c3-shell[data-layout="quick"] .c3-monitor:not(.is-theater) .c3-monitor-tile:not(.is-thumbnail) { border: 0; background: transparent; box-shadow: none; } -.c3-shell[data-layout="quick"] .c3-monitor:not(.is-theater) .c3-monitor-tile:not(.is-thumbnail) > .c3-video:not(:fullscreen) { box-sizing: content-box; flex: none; min-height: 160px; aspect-ratio: 16 / 9; width: calc(100% - 2 * (var(--tv-frame-inset) + var(--tv-frame-border))); margin: 0; border: calc(var(--tv-frame-inset) + var(--tv-frame-border)) solid transparent; border-bottom-width: calc(var(--tv-frame-chin) + var(--tv-frame-border)); border-radius: var(--tv-frame-radius); background: var(--tv-frame-background); box-shadow: var(--tv-frame-shadow); } +.c3-shell[data-layout="quick"] .c3-monitor:not(.is-theater) .c3-monitor-tile:not(.is-thumbnail) > :is(.c3-video:not(:fullscreen), .c3-monitor-wait) { box-sizing: content-box; flex: none; padding: 0; min-height: 160px; aspect-ratio: 16 / 9; width: calc(100% - 2 * (var(--tv-frame-inset) + var(--tv-frame-border))); margin: 0; border: calc(var(--tv-frame-inset) + var(--tv-frame-border)) solid transparent; border-bottom-width: calc(var(--tv-frame-chin) + var(--tv-frame-border)); border-radius: var(--tv-frame-radius); background: var(--tv-frame-background); box-shadow: var(--tv-frame-shadow); } .c3-shell[data-layout="quick"] .c3-monitor:not(.is-theater) .c3-monitor-tile:not(.is-thumbnail) > .c3-video:not(:fullscreen) > video { border-radius: var(--tv-screen-radius); } .c3-shell[data-layout="quick"]:has(.c3-monitor-grid.is-grid) .c3-main-body { width: 100%; } .c3-shell[data-layout="quick"] .c3-monitor-grid.is-grid .c3-monitor-tile { --tv-frame-inset: 3px; --tv-frame-chin: 7px; --tv-frame-radius: var(--c3-surface-radius); } diff --git a/tests/channel-stage-layout.test.ts b/tests/channel-stage-layout.test.ts index f9551764e..aa054fdaa 100644 --- a/tests/channel-stage-layout.test.ts +++ b/tests/channel-stage-layout.test.ts @@ -8,3 +8,12 @@ test("maximizes the contained picture after reserving source controls, without a expect(stageColumns(920, 400, [16 / 9], 14, 62, 280)).toBe(1); expect(stageColumns(1541, 655, [9 / 16, 16 / 9, 9 / 16, 16 / 9], 14, 62, 280)).toBe(4); }); + +test("natural television rows must fit at their actual aspect ratio, independently of the previous layout", () => { + const natural = { ratio: 16 / 9, insetX: 10, insetY: 14, minHeight: 160 }; + const sources = Array(3).fill(16 / 9); + expect(stageColumns(966, 942, sources, 14, 2, 280)).toBe(1); + expect(stageColumns(966, 942, sources, 14, 2, 280, natural)).toBe(2); + expect(stageColumns(966, 726, sources, 14, 2, 280, natural)).toBe(2); + expect(stageColumns(360, 700, sources, 14, 2, 280, natural)).toBe(1); +});