Skip to content

Commit 618e7dd

Browse files
committed
fix(dogfood): Implement custom responsive grid for PiP
1 parent 0c6f5b0 commit 618e7dd

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

sample-apps/react/react-dogfood/components/AdaptivePipGrid.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import {
2828
/** Gap between tiles, in px. Keep in sync with the SCSS gap. */
2929
const GAP = 4;
3030
/**
31-
* The aspect ratio tiles settle on when the window has room for it, matching
32-
* the main-layout grids (`ParticipantView`'s own `aspect-ratio: 4/3`).
31+
* The aspect ratio tiles use whenever it fits at a useful size, matching the
32+
* main-layout grids (`ParticipantView`'s own `aspect-ratio: 4/3`).
3333
*/
3434
const TARGET_ASPECT = 4 / 3;
3535
/**
@@ -164,6 +164,7 @@ export const AdaptivePipGrid = (props: AdaptivePipGridProps) => {
164164
}
165165

166166
const selectedGroup = pages[page];
167+
const selectedGroupSize = selectedGroup?.length ?? 0;
167168
const mirror = mirrorLocalParticipantVideo ? undefined : false;
168169

169170
/**
@@ -206,7 +207,9 @@ export const AdaptivePipGrid = (props: AdaptivePipGridProps) => {
206207
);
207208
}, [containerElement]);
208209

209-
useLayoutEffect(applyGeometry);
210+
useLayoutEffect(() => {
211+
applyGeometry();
212+
}, [applyGeometry, selectedGroupSize]);
210213

211214
useEffect(() => {
212215
if (!containerElement) return;
@@ -342,8 +345,8 @@ const getTiling = (count: number, width: number, height: number): Tiling => {
342345
/**
343346
* How far the tile aspect ratio may stray from `TARGET_ASPECT`, as a function
344347
* of how much room the container has. A cramped window gets the full Meet-like
345-
* band so the grid can fill it; a spacious one is pinned to `TARGET_ASPECT` so
346-
* tiles look like the main-layout grid instead of cropped portrait strips.
348+
* band so the grid can fill it, but `fitTile` still prefers `TARGET_ASPECT`
349+
* whenever it fits above the minimum useful tile size.
347350
*/
348351
const getAspectBounds = (width: number, height: number) => {
349352
const smaller = Math.min(width, height);
@@ -376,9 +379,25 @@ const fitTile = (
376379
return { tileWidth: 0, tileHeight: 0 };
377380
}
378381

382+
const targetTile = fitTileWithAspect(cellWidth, cellHeight, TARGET_ASPECT);
383+
if (
384+
targetTile.tileWidth >= MIN_TILE_WIDTH &&
385+
targetTile.tileHeight >= MIN_TILE_HEIGHT
386+
) {
387+
return targetTile;
388+
}
389+
379390
const cellAspect = cellWidth / cellHeight;
380391
const aspect = Math.min(bounds.max, Math.max(bounds.min, cellAspect));
392+
return fitTileWithAspect(cellWidth, cellHeight, aspect);
393+
};
381394

395+
const fitTileWithAspect = (
396+
cellWidth: number,
397+
cellHeight: number,
398+
aspect: number,
399+
) => {
400+
const cellAspect = cellWidth / cellHeight;
382401
return cellAspect > aspect
383402
? {
384403
tileWidth: Math.floor(cellHeight * aspect),

0 commit comments

Comments
 (0)