2024-05-17 16:38:00 -04:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-09-06 10:22:13 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
Please see LICENSE in the repository root for full details.
|
2024-05-17 16:38:00 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type CSSProperties, forwardRef } from "react";
|
2024-05-17 16:38:00 -04:00
|
|
|
import { useObservableEagerState } from "observable-hooks";
|
2024-05-30 13:06:24 -04:00
|
|
|
import classNames from "classnames";
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type CallLayout, arrangeTiles } from "./CallLayout";
|
|
|
|
|
import { type SpotlightPortraitLayout as SpotlightPortraitLayoutModel } from "../state/CallViewModel";
|
2024-07-03 15:08:30 -04:00
|
|
|
import styles from "./SpotlightPortraitLayout.module.css";
|
2024-07-25 12:50:28 -04:00
|
|
|
import { useUpdateLayout } from "./Grid";
|
2024-05-17 16:38:00 -04:00
|
|
|
|
|
|
|
|
interface GridCSSProperties extends CSSProperties {
|
2024-07-03 15:08:30 -04:00
|
|
|
"--grid-gap": string;
|
|
|
|
|
"--grid-tile-width": string;
|
|
|
|
|
"--grid-tile-height": string;
|
2024-05-17 16:38:00 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 11:33:20 -04:00
|
|
|
/**
|
|
|
|
|
* An implementation of the "spotlight portrait" layout, in which the spotlight
|
|
|
|
|
* tile is shown across the top of the screen, and the grid of participants
|
|
|
|
|
* scrolls behind it.
|
|
|
|
|
*/
|
2024-07-03 15:08:30 -04:00
|
|
|
export const makeSpotlightPortraitLayout: CallLayout<
|
|
|
|
|
SpotlightPortraitLayoutModel
|
|
|
|
|
> = ({ minBounds }) => ({
|
|
|
|
|
scrollingOnTop: false,
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-07-03 15:08:30 -04:00
|
|
|
fixed: forwardRef(function SpotlightPortraitLayoutFixed(
|
|
|
|
|
{ model, Slot },
|
|
|
|
|
ref,
|
|
|
|
|
) {
|
2024-07-25 12:50:28 -04:00
|
|
|
useUpdateLayout();
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-05-30 13:06:24 -04:00
|
|
|
return (
|
2024-07-24 16:57:20 -04:00
|
|
|
<div ref={ref} className={styles.layer}>
|
2024-05-30 13:06:24 -04:00
|
|
|
<div className={styles.spotlight}>
|
2024-11-06 04:36:48 -05:00
|
|
|
<Slot
|
|
|
|
|
className={styles.slot}
|
|
|
|
|
id="spotlight"
|
|
|
|
|
model={model.spotlight}
|
|
|
|
|
/>
|
2024-05-17 16:38:00 -04:00
|
|
|
</div>
|
2024-05-30 13:06:24 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}),
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-07-03 15:08:30 -04:00
|
|
|
scrolling: forwardRef(function SpotlightPortraitLayoutScrolling(
|
2024-05-30 13:06:24 -04:00
|
|
|
{ model, Slot },
|
|
|
|
|
ref,
|
|
|
|
|
) {
|
2024-07-25 12:50:28 -04:00
|
|
|
useUpdateLayout();
|
2024-07-24 16:57:20 -04:00
|
|
|
const { width } = useObservableEagerState(minBounds);
|
2024-07-03 15:08:30 -04:00
|
|
|
const { gap, tileWidth, tileHeight } = arrangeTiles(
|
|
|
|
|
width,
|
2024-07-26 06:50:44 -04:00
|
|
|
// TODO: We pretend that the minimum height is the width, because the
|
|
|
|
|
// actual minimum height is difficult to calculate
|
|
|
|
|
width,
|
2024-07-03 15:08:30 -04:00
|
|
|
model.grid.length,
|
|
|
|
|
);
|
2024-11-06 04:36:48 -05:00
|
|
|
const withIndicators =
|
|
|
|
|
useObservableEagerState(model.spotlight.media).length > 1;
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-05-30 13:06:24 -04:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
ref={ref}
|
2024-06-07 16:59:56 -04:00
|
|
|
className={styles.layer}
|
2024-07-03 15:08:30 -04:00
|
|
|
style={
|
|
|
|
|
{
|
|
|
|
|
"--grid-gap": `${gap}px`,
|
|
|
|
|
"--grid-tile-width": `${Math.floor(tileWidth)}px`,
|
|
|
|
|
"--grid-tile-height": `${Math.floor(tileHeight)}px`,
|
|
|
|
|
} as GridCSSProperties
|
|
|
|
|
}
|
2024-05-30 13:06:24 -04:00
|
|
|
>
|
2024-05-17 16:38:00 -04:00
|
|
|
<div
|
2024-05-30 13:06:24 -04:00
|
|
|
className={classNames(styles.spotlight, {
|
2024-11-06 04:36:48 -05:00
|
|
|
[styles.withIndicators]: withIndicators,
|
2024-05-30 13:06:24 -04:00
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
<div className={styles.grid}>
|
2024-11-06 04:36:48 -05:00
|
|
|
{model.grid.map((m) => (
|
2024-05-30 13:06:24 -04:00
|
|
|
<Slot
|
2024-11-06 04:36:48 -05:00
|
|
|
key={m.id}
|
2024-05-30 13:06:24 -04:00
|
|
|
className={styles.slot}
|
2024-11-06 04:36:48 -05:00
|
|
|
id={m.id}
|
2024-05-30 13:06:24 -04:00
|
|
|
model={m}
|
2024-11-06 04:36:48 -05:00
|
|
|
onVisibilityChange={m.setVisible}
|
2024-05-30 13:06:24 -04:00
|
|
|
/>
|
|
|
|
|
))}
|
2024-05-17 16:38:00 -04:00
|
|
|
</div>
|
2024-05-30 13:06:24 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}),
|
2024-05-17 16:38:00 -04:00
|
|
|
});
|