Skip to content

Commit 1492bad

Browse files
fix(web): iPhone Duo fold controls follow the phone's orientation
The fold buttons sent native pose presets, which always put the device in portrait, so a horizontal phone opened into a landscape tablet. They now move only the hinge, and their glyphs and labels follow the phone: a vertical phone opens as a book into a landscape tablet, a horizontal one as a laptop into a portrait tablet. Laptop and Tent stay separate stand presets. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d8d037e commit 1492bad

2 files changed

Lines changed: 83 additions & 44 deletions

File tree

‎apps/web/src/components/device/DeviceDuoControls.tsx‎

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,95 @@
1-
import {
2-
DUO_POSES,
3-
type DuoCommand,
4-
type DuoControlState,
5-
} from "@t3tools/client-runtime/device/duo-control";
1+
import type { DuoCommand, DuoControlState } from "@t3tools/client-runtime/device/duo-control";
62
import type { DeviceScreenSize } from "@t3tools/client-runtime/device/stream";
73
import { DeviceDuoGlyph } from "./DeviceDuoGlyph";
84
import { Button } from "~/components/ui/button";
95
import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
106

11-
/** Physical presets live beside the device. Pinching supplies continuous hinge control. */
7+
const FOLDS = [
8+
{ id: "closed", angle: 0 },
9+
{ id: "half", angle: 90 },
10+
{ id: "open", angle: 180 },
11+
] as const;
12+
const STANDS = [
13+
{ id: "laptop", label: "Laptop stand" },
14+
{ id: "tent", label: "Tent stand" },
15+
] as const;
16+
17+
/**
18+
* Fold shapes move only the hinge, so the device opens around whichever edge it
19+
* currently rests on: a vertical phone opens as a book into a landscape tablet,
20+
* a horizontal one as a laptop into a portrait tablet. Stands are native presets
21+
* that also place the device. Pinching supplies continuous hinge control.
22+
*/
1223
export function DeviceDuoControls(props: {
1324
screen: DeviceScreenSize;
1425
state: DuoControlState;
1526
enabled: boolean;
1627
onCommand: (command: DuoCommand) => void;
1728
}) {
18-
const angle = props.screen.hingeAngle;
19-
const fold = angle == null ? null : angle === 0 ? "closed" : angle === 180 ? "open" : "book";
20-
const selected = (id: (typeof DUO_POSES)[number]["id"]) =>
21-
id === "laptop" || id === "tent" ? props.screen.hingePose === id : fold === id;
29+
const { screen } = props;
30+
const angle = screen.hingeAngle ?? (screen.screenId === 1 ? 0 : 180);
31+
const stand = screen.hingePose === "laptop" || screen.hingePose === "tent";
32+
// The inner panel is mounted a quarter turn from the cover.
33+
const landscape = screen.orientation.startsWith("landscape");
34+
const phoneVertical = screen.screenId === 3 ? landscape : !landscape;
35+
const fold = angle === 0 ? "closed" : angle === 180 ? "open" : "half";
36+
const foldLabels = {
37+
closed: "Closed",
38+
half: phoneVertical ? "Book" : "Laptop",
39+
open: "Open",
40+
};
41+
const button = (
42+
key: string,
43+
label: string,
44+
pressed: boolean,
45+
onClick: () => void,
46+
glyph: React.ReactNode,
47+
) => (
48+
<Tooltip key={key}>
49+
<TooltipTrigger
50+
render={
51+
<Button
52+
size="icon"
53+
variant={pressed ? "secondary" : "ghost"}
54+
disabled={!props.enabled}
55+
aria-label={label}
56+
aria-pressed={pressed}
57+
data-pressed={pressed ? "" : undefined}
58+
onClick={onClick}
59+
/>
60+
}
61+
>
62+
{glyph}
63+
</TooltipTrigger>
64+
<TooltipPopup side="left">{label}</TooltipPopup>
65+
</Tooltip>
66+
);
67+
const group =
68+
"pointer-events-auto flex shrink-0 flex-col items-center gap-1 rounded-full border border-border/50 bg-background/80 p-1 shadow-sm";
2269
return (
2370
<div aria-label="iPhone Duo stands" className="flex flex-col items-center gap-2">
24-
{([DUO_POSES.slice(0, 3), DUO_POSES.slice(3)] as const).map((poses, index) => (
25-
<div
26-
key={poses[0]?.id}
27-
role="group"
28-
aria-label={index === 0 ? "Fold shape" : "Device stance"}
29-
className="pointer-events-auto flex shrink-0 flex-col items-center gap-1 rounded-full border border-border/50 bg-background/80 p-1 shadow-sm"
30-
>
31-
{poses.map((pose) => (
32-
<Tooltip key={pose.id}>
33-
<TooltipTrigger
34-
render={
35-
<Button
36-
size="icon"
37-
variant={selected(pose.id) ? "secondary" : "ghost"}
38-
disabled={!props.enabled}
39-
aria-label={`${pose.label} stand`}
40-
aria-pressed={selected(pose.id)}
41-
data-pressed={selected(pose.id) ? "" : undefined}
42-
onClick={() => props.onCommand({ control: "pose", value: pose.id })}
43-
/>
44-
}
45-
>
46-
<DeviceDuoGlyph pose={pose.id} />
47-
</TooltipTrigger>
48-
<TooltipPopup side="left">
49-
{pose.label}
50-
{pose.id === "book" ? " / bookshelf" : ""}
51-
</TooltipPopup>
52-
</Tooltip>
53-
))}
54-
</div>
55-
))}
71+
<div role="group" aria-label="Fold shape" className={group}>
72+
{FOLDS.map(({ id, angle: value }) =>
73+
button(
74+
id,
75+
foldLabels[id],
76+
!stand && fold === id,
77+
() => props.onCommand({ control: "angle", value }),
78+
<DeviceDuoGlyph pose={id === "half" ? "book" : id} vertical={phoneVertical} />,
79+
),
80+
)}
81+
</div>
82+
<div role="group" aria-label="Device stance" className={group}>
83+
{STANDS.map(({ id, label }) =>
84+
button(
85+
id,
86+
label,
87+
screen.hingePose === id,
88+
() => props.onCommand({ control: "pose", value: id }),
89+
<DeviceDuoGlyph pose={id} />,
90+
),
91+
)}
92+
</div>
5693
{props.state.error ? (
5794
<Tooltip>
5895
<TooltipTrigger

‎apps/web/src/components/device/DeviceDuoGlyph.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DuoPose } from "@t3tools/client-runtime/device/duo-control";
2+
import { cn } from "~/lib/utils";
23

34
// Bitrig 0.25's toolbar glyphs. The fold outlines follow the native toolbar;
45
// the rounded stance contours are ported from SimulatorFoldingPoseGlyph's SwiftUI paths.
@@ -8,7 +9,8 @@ const stancePaths = {
89
tent: "M3.2522 2.7267 L18.7478 1.4816 L16.696 9.7017 C16.3782 10.9748 15.0649 12.0915 13.7626 12.1962 L2.983 13.0623 C1.6807 13.167 0.8826 12.2199 1.2004 10.9468 L3.2522 2.7267 Z M3.2522 2.7267 L18.7478 1.4816 L20.7996 10.6909 C21.1174 12.1172 20.3193 13.3581 19.017 13.4628 L8.2374 14.3289 C6.9351 14.4336 5.6218 13.3623 5.304 11.936 L3.2522 2.7267 Z",
910
} as const;
1011

11-
export function DeviceDuoGlyph({ pose }: { pose: DuoPose }) {
12+
/** Fold glyphs are drawn for a horizontal phone; `vertical` turns them a quarter for a vertical one. */
13+
export function DeviceDuoGlyph({ pose, vertical = false }: { pose: DuoPose; vertical?: boolean }) {
1214
const stance = pose === "laptop" || pose === "tent";
1315
return (
1416
<svg
@@ -18,7 +20,7 @@ export function DeviceDuoGlyph({ pose }: { pose: DuoPose }) {
1820
strokeWidth={stance ? 1.25 : 1.8}
1921
strokeLinecap="round"
2022
strokeLinejoin="round"
21-
className="size-7 shrink-0"
23+
className={cn("size-7 shrink-0", vertical && "rotate-90")}
2224
aria-hidden
2325
>
2426
{stance ? <path d={stancePaths[pose]} /> : null}

0 commit comments

Comments
 (0)