Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 3x 63x 63x 63x 23x 23x 23x 63x | // SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Max Boksem. See NOTICE for additional terms under GPLv3 section 7.
import { useState, useEffect } from "react";
import { getPlatform, layoutModeFor, readViewport } from "@/lib/platform";
export const usePlatform = () => {
const [platform] = useState(getPlatform);
const [layoutMode, setLayoutMode] = useState(() => layoutModeFor(platform, readViewport()));
// An iPad changes layout when it rotates or enters Split View. React skips
// the render when the mode stays the same.
useEffect(() => {
const onResize = () => setLayoutMode(layoutModeFor(platform, readViewport()));
window.addEventListener("resize", onResize);
return () => window.removeEventListener("resize", onResize);
}, [platform]);
return { platform, layoutMode };
};
|