diff --git a/src/grid/Grid.tsx b/src/grid/Grid.tsx index 4b084db5..c524d928 100644 --- a/src/grid/Grid.tsx +++ b/src/grid/Grid.tsx @@ -128,10 +128,10 @@ const LayoutContext = createContext(null); * Enables Grid to react to layout changes. You must call this in your Layout * component or else Grid will not be reactive. */ -export function useLayout(): void { +export function useUpdateLayout(): void { const context = useContext(LayoutContext); if (context === null) - throw new Error("useLayout called outside of a Grid layout component"); + throw new Error("useUpdateLayout called outside a Grid layout context"); // On every render, tell Grid that the layout may have changed useEffect(() => @@ -240,7 +240,7 @@ export function Grid< const [gridRoot, gridRef2] = useState(null); const gridRef = useMergedRefs(gridRef1, gridRef2); - const [layoutRoot, layoutRef] = useState(null); + const [layoutRoot, setLayoutRoot] = useState(null); const [generation, setGeneration] = useState(null); const tiles = useInitial(() => new Map>()); const prefersReducedMotion = usePrefersReducedMotion(); @@ -490,7 +490,12 @@ export function Grid< style={style} > - + {tileTransitions((spring, { id, model, onDrag, width, height }) => ( = ({ // The "fixed" (non-scrolling) part of the layout is where the spotlight tile // lives fixed: forwardRef(function GridLayoutFixed({ model, Slot }, ref) { - useLayout(); + useUpdateLayout(); const alignment = useObservableEagerState( useInitial(() => spotlightAlignment.pipe( @@ -95,7 +95,7 @@ export const makeGridLayout: CallLayout = ({ // The scrolling part of the layout is where all the grid tiles live scrolling: forwardRef(function GridLayout({ model, Slot }, ref) { - useLayout(); + useUpdateLayout(); const { width, height: minHeight } = useObservableEagerState(minBounds); const { gap, tileWidth, tileHeight } = useMemo( () => arrangeTiles(width, minHeight, model.grid.length), diff --git a/src/grid/OneOnOneLayout.tsx b/src/grid/OneOnOneLayout.tsx index a7b72c3b..4401ae49 100644 --- a/src/grid/OneOnOneLayout.tsx +++ b/src/grid/OneOnOneLayout.tsx @@ -21,7 +21,7 @@ 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, useLayout } from "./Grid"; +import { DragCallback, useUpdateLayout } from "./Grid"; /** * An implementation of the "one-on-one" layout, in which the remote participant @@ -34,12 +34,12 @@ export const makeOneOnOneLayout: CallLayout = ({ scrollingOnTop: false, fixed: forwardRef(function OneOnOneLayoutFixed(_props, ref) { - useLayout(); + useUpdateLayout(); return
; }), scrolling: forwardRef(function OneOnOneLayoutScrolling({ model, Slot }, ref) { - useLayout(); + useUpdateLayout(); const { width, height } = useObservableEagerState(minBounds); const pipAlignmentValue = useObservableEagerState(pipAlignment); const { tileWidth, tileHeight } = useMemo( diff --git a/src/grid/SpotlightExpandedLayout.tsx b/src/grid/SpotlightExpandedLayout.tsx index 00513ee6..146eb151 100644 --- a/src/grid/SpotlightExpandedLayout.tsx +++ b/src/grid/SpotlightExpandedLayout.tsx @@ -19,7 +19,7 @@ import { useObservableEagerState } from "observable-hooks"; import { SpotlightExpandedLayout as SpotlightExpandedLayoutModel } from "../state/CallViewModel"; import { CallLayout, GridTileModel, SpotlightTileModel } from "./CallLayout"; -import { DragCallback, useLayout } from "./Grid"; +import { DragCallback, useUpdateLayout } from "./Grid"; import styles from "./SpotlightExpandedLayout.module.css"; /** @@ -35,7 +35,7 @@ export const makeSpotlightExpandedLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); const spotlightTileModel: SpotlightTileModel = useMemo( () => ({ type: "spotlight", vms: model.spotlight, maximised: true }), [model.spotlight], @@ -56,7 +56,7 @@ export const makeSpotlightExpandedLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); const pipAlignmentValue = useObservableEagerState(pipAlignment); const pipTileModel: GridTileModel | undefined = useMemo( diff --git a/src/grid/SpotlightLandscapeLayout.tsx b/src/grid/SpotlightLandscapeLayout.tsx index 896843b1..fb73884d 100644 --- a/src/grid/SpotlightLandscapeLayout.tsx +++ b/src/grid/SpotlightLandscapeLayout.tsx @@ -21,7 +21,7 @@ import classNames from "classnames"; import { CallLayout, GridTileModel, TileModel } from "./CallLayout"; import { SpotlightLandscapeLayout as SpotlightLandscapeLayoutModel } from "../state/CallViewModel"; import styles from "./SpotlightLandscapeLayout.module.css"; -import { useLayout } from "./Grid"; +import { useUpdateLayout } from "./Grid"; /** * An implementation of the "spotlight landscape" layout, in which the spotlight @@ -37,7 +37,7 @@ export const makeSpotlightLandscapeLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); useObservableEagerState(minBounds); const tileModel: TileModel = useMemo( () => ({ @@ -62,7 +62,7 @@ export const makeSpotlightLandscapeLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); useObservableEagerState(minBounds); const tileModels: GridTileModel[] = useMemo( () => model.grid.map((vm) => ({ type: "grid", vm })), diff --git a/src/grid/SpotlightPortraitLayout.tsx b/src/grid/SpotlightPortraitLayout.tsx index 0c8dee83..656d3de3 100644 --- a/src/grid/SpotlightPortraitLayout.tsx +++ b/src/grid/SpotlightPortraitLayout.tsx @@ -26,7 +26,7 @@ import { } from "./CallLayout"; import { SpotlightPortraitLayout as SpotlightPortraitLayoutModel } from "../state/CallViewModel"; import styles from "./SpotlightPortraitLayout.module.css"; -import { useLayout } from "./Grid"; +import { useUpdateLayout } from "./Grid"; interface GridCSSProperties extends CSSProperties { "--grid-gap": string; @@ -48,7 +48,7 @@ export const makeSpotlightPortraitLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); const tileModel: TileModel = useMemo( () => ({ type: "spotlight", @@ -71,7 +71,7 @@ export const makeSpotlightPortraitLayout: CallLayout< { model, Slot }, ref, ) { - useLayout(); + useUpdateLayout(); const { width } = useObservableEagerState(minBounds); const { gap, tileWidth, tileHeight } = arrangeTiles( width,