2024-05-17 16:38:00 -04:00
|
|
|
/*
|
|
|
|
|
Copyright 2024 New Vector Ltd
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-30 13:06:24 -04:00
|
|
|
import { CSSProperties, forwardRef, useMemo } 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-07-03 15:08:30 -04:00
|
|
|
import {
|
|
|
|
|
CallLayout,
|
|
|
|
|
GridTileModel,
|
|
|
|
|
TileModel,
|
|
|
|
|
arrangeTiles,
|
|
|
|
|
} from "./CallLayout";
|
|
|
|
|
import { SpotlightPortraitLayout as SpotlightPortraitLayoutModel } from "../state/CallViewModel";
|
|
|
|
|
import styles from "./SpotlightPortraitLayout.module.css";
|
2024-05-30 13:06:24 -04:00
|
|
|
import { useReactiveState } from "../useReactiveState";
|
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-05-30 13:06:24 -04:00
|
|
|
const { width, height } = useObservableEagerState(minBounds);
|
|
|
|
|
const tileModel: TileModel = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
type: "spotlight",
|
|
|
|
|
vms: model.spotlight,
|
2024-07-03 15:08:30 -04:00
|
|
|
maximised: true,
|
2024-05-30 13:06:24 -04:00
|
|
|
}),
|
2024-07-03 15:08:30 -04:00
|
|
|
[model.spotlight],
|
2024-05-30 13:06:24 -04:00
|
|
|
);
|
|
|
|
|
const [generation] = useReactiveState<number>(
|
|
|
|
|
(prev) => (prev === undefined ? 0 : prev + 1),
|
2024-07-22 10:52:20 -04:00
|
|
|
[model.grid.length, width, height, model.spotlight],
|
2024-05-30 13:06:24 -04:00
|
|
|
);
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-05-30 13:06:24 -04:00
|
|
|
return (
|
2024-07-03 15:08:30 -04:00
|
|
|
<div ref={ref} data-generation={generation} className={styles.layer}>
|
2024-05-30 13:06:24 -04:00
|
|
|
<div className={styles.spotlight}>
|
|
|
|
|
<Slot className={styles.slot} id="spotlight" model={tileModel} />
|
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,
|
|
|
|
|
) {
|
|
|
|
|
const { width, height } = useObservableEagerState(minBounds);
|
2024-07-03 15:08:30 -04:00
|
|
|
const { gap, tileWidth, tileHeight } = arrangeTiles(
|
|
|
|
|
width,
|
|
|
|
|
0,
|
|
|
|
|
model.grid.length,
|
|
|
|
|
);
|
2024-05-30 13:06:24 -04:00
|
|
|
const tileModels: GridTileModel[] = useMemo(
|
|
|
|
|
() => model.grid.map((vm) => ({ type: "grid", vm })),
|
|
|
|
|
[model.grid],
|
|
|
|
|
);
|
|
|
|
|
const [generation] = useReactiveState<number>(
|
|
|
|
|
(prev) => (prev === undefined ? 0 : prev + 1),
|
|
|
|
|
[model.spotlight.length, model.grid, width, height],
|
|
|
|
|
);
|
2024-05-17 16:38:00 -04:00
|
|
|
|
2024-05-30 13:06:24 -04:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
ref={ref}
|
|
|
|
|
data-generation={generation}
|
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, {
|
|
|
|
|
[styles.withIndicators]: model.spotlight.length > 1,
|
|
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
<div className={styles.grid}>
|
|
|
|
|
{tileModels.map((m) => (
|
|
|
|
|
<Slot
|
|
|
|
|
key={m.vm.id}
|
|
|
|
|
className={styles.slot}
|
|
|
|
|
id={m.vm.id}
|
|
|
|
|
model={m}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
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
|
|
|
});
|