/* Copyright 2024 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ import { forwardRef, useCallback, useMemo } from "react"; import { useObservableEagerState } from "observable-hooks"; import classNames from "classnames"; import { OneOnOneLayout as OneOnOneLayoutModel } from "../state/CallViewModel"; import { CallLayout, GridTileModel, arrangeTiles } from "./CallLayout"; import styles from "./OneOnOneLayout.module.css"; import { DragCallback, useUpdateLayout } from "./Grid"; /** * An implementation of the "one-on-one" layout, in which the remote participant * is shown at maximum size, overlaid by a small view of the local participant. */ export const makeOneOnOneLayout: CallLayout = ({ minBounds, pipAlignment, }) => ({ scrollingOnTop: false, fixed: forwardRef(function OneOnOneLayoutFixed(_props, ref) { useUpdateLayout(); return
; }), scrolling: forwardRef(function OneOnOneLayoutScrolling({ model, Slot }, ref) { useUpdateLayout(); const { width, height } = useObservableEagerState(minBounds); const pipAlignmentValue = useObservableEagerState(pipAlignment); const { tileWidth, tileHeight } = useMemo( () => arrangeTiles(width, height, 1), [width, height], ); const remoteTileModel: GridTileModel = useMemo( () => ({ type: "grid", vm: model.remote }), [model.remote], ); const localTileModel: GridTileModel = useMemo( () => ({ type: "grid", vm: model.local }), [model.local], ); const onDragLocalTile: DragCallback = useCallback( ({ xRatio, yRatio }) => pipAlignment.next({ block: yRatio < 0.5 ? "start" : "end", inline: xRatio < 0.5 ? "start" : "end", }), [], ); return (
); }), });