Open History to see the last commit
1export interface ReservedRegion {
2 readonly kind: "division" | "occlusion";
3 readonly x: number;
4 readonly y: number;
5 readonly width: number;
6 readonly height: number;
7}
8
9export interface NativeLayoutMetrics {
10 readonly width: number;
11 readonly height: number;
12 readonly hasHinge?: boolean;
13 readonly horizontalSizeClass: "compact" | "regular";
14 readonly verticalBarEdge: "none" | "left" | "right";
15 readonly safeArea: {
16 readonly top: number;
17 readonly bottom: number;
18 readonly left: number;
19 readonly right: number;
20 };
21 readonly reservedRegions: ReadonlyArray<ReservedRegion>;
22}
23
24export function deriveBottomControlInsets(metrics: NativeLayoutMetrics | null) {
25 if (!metrics) return { left: 0, right: 0, bottom: 0 };
26 let left = metrics.safeArea.left;
27 let right = metrics.width - metrics.safeArea.right;
28 let bottom = metrics.height;
29 for (const region of metrics.reservedRegions) {
30 const x = Math.max(left, region.x);
31 const endX = Math.min(right, region.x + region.width);
32 const y = Math.max(0, region.y);
33 const endY = Math.min(bottom, region.y + region.height);
34 if (endX <= x || endY <= y) continue;
35 if (region.kind === "division" && region.height >= metrics.height / 2) {
36 if (right - endX >= x - left) left = endX;
37 else right = x;
38 } else if (endY >= bottom - metrics.safeArea.bottom) {
39 if (region.width >= right - left) bottom = y;
40 else if (right - endX >= x - left) left = endX;
41 else right = x;
42 }
43 }
44 return { left, right: metrics.width - right, bottom: metrics.height - bottom };
45}