fix(channel): stabilize quick-view grids and room navigation

This commit is contained in:
AAA committed 2026-11-12 08:28:29 -04:00
1 parent cd8a11870b
commit 9e6e8acc89
5 files changed
+42 -10

No files matched your search

+15 -3
View File
@@ -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<HTMLElement>('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<HTMLVideoElement>('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);
+9 -3
View File
@@ -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;
+6 -3
View File
@@ -195,7 +195,7 @@ export function ChannelRoomPage({ channel, selected, onSelect, appControl, layou
onClose={closeRoomSettings} />}
{newRoomName !== null && <ChannelRoomCreateDialog channel={channel} initialName={newRoomName}
onCreated={selectRoom} onClose={() => setNewRoomName(null)} />}
<main ref={workspaceElement} className="c3-shell" data-layout={layout} data-pane={layout === "quick" ? "room" : mobilePane} data-view={sharingView ? "share" : "workspace"} data-sidebars={sidebarsInline ? "inline" : "overlay"} data-overview={overview || undefined}
<main ref={workspaceElement} className="c3-shell" data-layout={layout} data-pane={mobilePane} data-view={sharingView ? "share" : "workspace"} data-sidebars={sidebarsInline ? "inline" : "overlay"} data-overview={overview || undefined}
data-companion={companionVisible ? mobilePane === "people" || !visibleScreens.length ? "people" : toolSurface.open ? "none" : "chat" : "none"}>
<header className="c3-site-bar"><div className="c3-site-identity">
{layout === "quick" ? <span className="c3-site-home"><BrandMark size={30} motion="once" /></span>
@@ -204,13 +204,16 @@ export function ChannelRoomPage({ channel, selected, onSelect, appControl, layou
: <Tooltip overflow={{ text: state?.channel.name ?? "Piik", selector: "strong" }}><span className="c3-site-name-readonly"><ChannelIdentityMark icon={state?.channel.icon ?? "couch"} size={22} /><strong>{state?.channel.name ?? "Piik"}</strong></span></Tooltip>}</div>
<LedStrip state={connected ? "live" : connection === "closed" ? "bad" : "busy"}
label={connectionLabel} comic={connected ? "signal-connected" : "signal-connecting"} />
{layout === "quick" && <Btn id="c3-rooms-trigger" icon="couch" quiet size="compact"
title={{ text: copy("房间列表", "Rooms") }} cap={{ text: copy("房间", "Rooms") }} hint="hint-room-list"
controls="c3-room-list" expanded={mobilePane === "rooms"} onClick={showRooms} />}
</div><div className="lr-top c3-global-tools">
<HeaderControls appControl={appControl} personalControls={<>
{onLayoutChange && <ChannelInterfaceControl value={layout} onChange={onLayoutChange} />}
<ChannelFeedbackSounds channel={channel} />
</>} />
</div></header>
{layout !== "quick" && <aside id="c3-room-list" className="c3-sidebar" onKeyDown={event => {
<aside id="c3-room-list" className="c3-sidebar" onKeyDown={event => {
if (!sidebarsInline && mobilePane === "rooms" && event.key === "Escape" && !event.defaultPrevented) {
event.preventDefault(); setMobilePane("room");
}
@@ -233,7 +236,7 @@ export function ChannelRoomPage({ channel, selected, onSelect, appControl, layou
{state && !rooms.length && <p className="c3-room-list-empty">{copy("暂无可进入的房间", "No rooms available yet")}</p>}
</div>
</div>
</aside>}
</aside>
<div className="c3-personal"><div ref={voiceSlot} className="c3-room-slot" />
{self && <div className="c3-identity"><PawnSvg color={participantColor(self.id)} identity={self.id} avatar={self.avatar ?? undefined} />
<div><strong>{self.name}</strong><small>{copy("你的名字", "Your name")}</small></div>
+3 -1
View File
@@ -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); }
+9
View File
@@ -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);
});