Implement the new spotlight layout
This commit is contained in:
55
src/grid/CallLayout.ts
Normal file
55
src/grid/CallLayout.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
|
||||
import { MediaViewModel } from "../state/MediaViewModel";
|
||||
import { LayoutSystem } from "./Grid";
|
||||
import { Alignment } from "../room/InCallView";
|
||||
|
||||
export interface Bounds {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface CallLayoutInputs {
|
||||
/**
|
||||
* The minimum bounds of the layout area.
|
||||
*/
|
||||
minBounds: Observable<Bounds>;
|
||||
/**
|
||||
* The alignment of the floating tile, if any.
|
||||
*/
|
||||
floatingAlignment: BehaviorSubject<Alignment>;
|
||||
}
|
||||
|
||||
export interface CallLayoutOutputs<Model> {
|
||||
/**
|
||||
* The visually fixed (non-scrolling) layer of the layout.
|
||||
*/
|
||||
fixed: LayoutSystem<Model, MediaViewModel[], HTMLDivElement>;
|
||||
/**
|
||||
* The layer of the layout that can overflow and be scrolled.
|
||||
*/
|
||||
scrolling: LayoutSystem<Model, MediaViewModel, HTMLDivElement>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A layout system for media tiles.
|
||||
*/
|
||||
export type CallLayout<Model> = (
|
||||
inputs: CallLayoutInputs,
|
||||
) => CallLayoutOutputs<Model>;
|
||||
@@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
.fixed,
|
||||
.scrolling {
|
||||
margin-inline: var(--inline-content-inset);
|
||||
}
|
||||
|
||||
.scrolling {
|
||||
box-sizing: border-box;
|
||||
block-size: 100%;
|
||||
@@ -22,7 +27,6 @@ limitations under the License.
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
gap: var(--gap);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.scrolling > .slot {
|
||||
|
||||
@@ -15,21 +15,15 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { CSSProperties, forwardRef, useMemo } from "react";
|
||||
import { BehaviorSubject, Observable, distinctUntilChanged } from "rxjs";
|
||||
import { distinctUntilChanged } from "rxjs";
|
||||
import { useObservableEagerState } from "observable-hooks";
|
||||
|
||||
import { GridLayout as GridLayoutModel } from "../state/CallViewModel";
|
||||
import { MediaViewModel } from "../state/MediaViewModel";
|
||||
import { LayoutSystem, Slot } from "./Grid";
|
||||
import { Slot } from "./Grid";
|
||||
import styles from "./GridLayout.module.css";
|
||||
import { useReactiveState } from "../useReactiveState";
|
||||
import { Alignment } from "../room/InCallView";
|
||||
import { useInitial } from "../useInitial";
|
||||
|
||||
export interface Bounds {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
import { CallLayout } from "./CallLayout";
|
||||
|
||||
interface GridCSSProperties extends CSSProperties {
|
||||
"--gap": string;
|
||||
@@ -37,19 +31,14 @@ interface GridCSSProperties extends CSSProperties {
|
||||
"--height": string;
|
||||
}
|
||||
|
||||
interface GridLayoutSystems {
|
||||
scrolling: LayoutSystem<GridLayoutModel, MediaViewModel, HTMLDivElement>;
|
||||
fixed: LayoutSystem<GridLayoutModel, MediaViewModel[], HTMLDivElement>;
|
||||
}
|
||||
|
||||
const slotMinHeight = 130;
|
||||
const slotMaxAspectRatio = 17 / 9;
|
||||
const slotMinAspectRatio = 4 / 3;
|
||||
|
||||
export const gridLayoutSystems = (
|
||||
minBounds: Observable<Bounds>,
|
||||
floatingAlignment: BehaviorSubject<Alignment>,
|
||||
): GridLayoutSystems => ({
|
||||
export const makeGridLayout: CallLayout<GridLayoutModel> = ({
|
||||
minBounds,
|
||||
floatingAlignment,
|
||||
}) => ({
|
||||
// The "fixed" (non-scrolling) part of the layout is where the spotlight tile
|
||||
// lives
|
||||
fixed: {
|
||||
|
||||
89
src/grid/SpotlightLayout.module.css
Normal file
89
src/grid/SpotlightLayout.module.css
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
.fixed,
|
||||
.scrolling {
|
||||
margin-inline: var(--inline-content-inset);
|
||||
display: grid;
|
||||
--grid-slot-width: 180px;
|
||||
--grid-gap: 20px;
|
||||
grid-template-columns: 1fr calc(
|
||||
var(--grid-columns) * var(--grid-slot-width) + (var(--grid-columns) - 1) *
|
||||
var(--grid-gap)
|
||||
);
|
||||
grid-template-rows: minmax(1fr, auto);
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.scrolling {
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.spotlight {
|
||||
container: spotlight / size;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
/* CSS makes us put a condition here, even though all we want to do is
|
||||
unconditionally select the container so we can use cq units */
|
||||
@container spotlight (width > 0) {
|
||||
.spotlight > .slot {
|
||||
inline-size: min(100cqi, 100cqb * (17 / 9));
|
||||
block-size: min(100cqb, 100cqi / (4 / 3));
|
||||
}
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--grid-gap);
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
.grid > .slot {
|
||||
inline-size: var(--grid-slot-width);
|
||||
block-size: 135px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.fixed,
|
||||
.scrolling {
|
||||
margin-inline: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.spotlight {
|
||||
inline-size: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
margin-block-end: var(--cpd-space-4x);
|
||||
}
|
||||
|
||||
.grid {
|
||||
margin-inline: var(--inline-content-inset);
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
.grid > .slot {
|
||||
--grid-columns: 2;
|
||||
--grid-slot-width: calc(
|
||||
(100% - (var(--grid-columns) - 1) * var(--grid-gap)) / var(--grid-columns)
|
||||
);
|
||||
block-size: unset;
|
||||
aspect-ratio: 4 / 3;
|
||||
}
|
||||
}
|
||||
89
src/grid/SpotlightLayout.tsx
Normal file
89
src/grid/SpotlightLayout.tsx
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
import { CSSProperties, forwardRef } from "react";
|
||||
import { useObservableEagerState } from "observable-hooks";
|
||||
|
||||
import { CallLayout } from "./CallLayout";
|
||||
import { SpotlightLayout as SpotlightLayoutModel } from "../state/CallViewModel";
|
||||
import { useReactiveState } from "../useReactiveState";
|
||||
import styles from "./SpotlightLayout.module.css";
|
||||
import { Slot } from "./Grid";
|
||||
|
||||
interface GridCSSProperties extends CSSProperties {
|
||||
"--grid-columns": number;
|
||||
}
|
||||
|
||||
const getGridColumns = (gridLength: number): number =>
|
||||
gridLength > 20 ? 2 : 1;
|
||||
|
||||
export const makeSpotlightLayout: CallLayout<SpotlightLayoutModel> = ({
|
||||
minBounds,
|
||||
}) => ({
|
||||
fixed: {
|
||||
tiles: (model) => new Map([["spotlight", model.spotlight]]),
|
||||
Layout: forwardRef(function SpotlightLayoutFixed({ model }, ref) {
|
||||
const { width, height } = useObservableEagerState(minBounds);
|
||||
const gridColumns = getGridColumns(model.grid.length);
|
||||
const [generation] = useReactiveState<number>(
|
||||
(prev) => (prev === undefined ? 0 : prev + 1),
|
||||
[model.grid.length, width, height],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-generation={generation}
|
||||
className={styles.fixed}
|
||||
style={{ "--grid-columns": gridColumns, height } as GridCSSProperties}
|
||||
>
|
||||
<div className={styles.spotlight}>
|
||||
<Slot className={styles.slot} tile="spotlight" />
|
||||
</div>
|
||||
<div className={styles.grid} />
|
||||
</div>
|
||||
);
|
||||
}),
|
||||
},
|
||||
|
||||
scrolling: {
|
||||
tiles: (model) => new Map(model.grid.map((tile) => [tile.id, tile])),
|
||||
Layout: forwardRef(function SpotlightLayoutScrolling({ model }, ref) {
|
||||
const { width, height } = useObservableEagerState(minBounds);
|
||||
const gridColumns = getGridColumns(model.grid.length);
|
||||
const [generation] = useReactiveState<number>(
|
||||
(prev) => (prev === undefined ? 0 : prev + 1),
|
||||
[model.grid, width, height],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-generation={generation}
|
||||
className={styles.scrolling}
|
||||
style={{ "--grid-columns": gridColumns } as GridCSSProperties}
|
||||
>
|
||||
<div className={styles.spotlight} />
|
||||
<div className={styles.grid}>
|
||||
{model.grid.map((tile) => (
|
||||
<Slot key={tile.id} className={styles.slot} tile={tile.id} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}),
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user