Skip to content

Commit 876e6ec

Browse files
authored
fix toolbar rotate icons (#70)
1 parent ed87fb8 commit 876e6ec

4 files changed

Lines changed: 60 additions & 31 deletions

File tree

‎packages/client/src/app/AppShell.tsx‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,6 +2761,33 @@ export function AppShell({
27612761
}, 1800);
27622762
}
27632763

2764+
function rotateSelectedSimulator(direction: "left" | "right") {
2765+
if (!selectedSimulator) {
2766+
return;
2767+
}
2768+
if (selectedHasFixedOrientation) {
2769+
return;
2770+
}
2771+
const androidViewport = isAndroidSimulator(selectedSimulator);
2772+
const controlType = direction === "left" ? "rotateLeft" : "rotateRight";
2773+
const rotationDelta = direction === "left" ? -1 : 1;
2774+
beginZoomAnimation();
2775+
if (sendControl(selectedSimulator.udid, { type: controlType })) {
2776+
if (androidViewport) {
2777+
setRotationQuarterTurns(0);
2778+
window.setTimeout(() => {
2779+
void refresh();
2780+
}, 250);
2781+
} else {
2782+
setRotationQuarterTurns((current) =>
2783+
normalizeQuarterTurns(current + rotationDelta),
2784+
);
2785+
}
2786+
return;
2787+
}
2788+
setLocalError("Simulator control stream disconnected.");
2789+
}
2790+
27642791
async function submitPairing(event: FormEvent<HTMLFormElement>) {
27652792
event.preventDefault();
27662793
const code = pairingCode.trim();
@@ -2889,28 +2916,8 @@ export function AppShell({
28892916
setNewSimulatorOpen(true);
28902917
}}
28912918
onOpenUrlPrompt={promptForURL}
2892-
onRotateRight={() => {
2893-
if (!selectedSimulator) {
2894-
return;
2895-
}
2896-
if (selectedHasFixedOrientation) {
2897-
return;
2898-
}
2899-
const androidViewport = isAndroidSimulator(selectedSimulator);
2900-
beginZoomAnimation();
2901-
if (sendControl(selectedSimulator.udid, { type: "rotateRight" })) {
2902-
if (androidViewport) {
2903-
setRotationQuarterTurns(0);
2904-
window.setTimeout(() => {
2905-
void refresh();
2906-
}, 250);
2907-
} else {
2908-
setRotationQuarterTurns((current) => (current + 1) % 4);
2909-
}
2910-
return;
2911-
}
2912-
setLocalError("Simulator control stream disconnected.");
2913-
}}
2919+
onRotateLeft={() => rotateSelectedSimulator("left")}
2920+
onRotateRight={() => rotateSelectedSimulator("right")}
29142921
onToggleRecording={() => {
29152922
void toggleSimulatorRecording();
29162923
}}

‎packages/client/src/features/toolbar/Toolbar.tsx‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
LayersIcon as HierarchyIcon,
77
Link2Icon as OpenUrlIcon,
88
PlayIcon,
9-
ReloadIcon as RotateRightIcon,
9+
RotateCounterClockwiseIcon as RotateLeftIcon,
1010
StopIcon,
1111
} from "@radix-ui/react-icons";
1212
import { useEffect, useState, type RefObject } from "react";
@@ -43,6 +43,7 @@ interface ToolbarProps {
4343
onOpenBundlePrompt: () => void;
4444
onOpenNewSimulator: () => void;
4545
onOpenUrlPrompt: () => void;
46+
onRotateLeft: () => void;
4647
onRotateRight: () => void;
4748
onShutdown: () => void;
4849
onStreamEncoderChange: (encoder: StreamEncoder) => void;
@@ -104,6 +105,7 @@ export function Toolbar({
104105
onOpenBundlePrompt,
105106
onOpenNewSimulator,
106107
onOpenUrlPrompt,
108+
onRotateLeft,
107109
onRotateRight,
108110
onShutdown,
109111
onStreamEncoderChange,
@@ -279,14 +281,24 @@ export function Toolbar({
279281
<AppearanceIcon />
280282
</button>
281283
{canRotateSelectedSimulator ? (
282-
<button
283-
aria-label="Rotate Right"
284-
className="tbtn icon-btn toolbar-mobile-hidden"
285-
onClick={onRotateRight}
286-
title="Rotate Right"
287-
>
288-
<RotateRightIcon />
289-
</button>
284+
<>
285+
<button
286+
aria-label="Rotate Left"
287+
className="tbtn icon-btn toolbar-mobile-hidden toolbar-wide-hidden"
288+
onClick={onRotateLeft}
289+
title="Rotate Left"
290+
>
291+
<RotateLeftIcon />
292+
</button>
293+
<button
294+
aria-label="Rotate Right"
295+
className="tbtn icon-btn toolbar-mobile-hidden"
296+
onClick={onRotateRight}
297+
title="Rotate Right"
298+
>
299+
<RotateLeftIcon className="rotate-right-icon" />
300+
</button>
301+
</>
290302
) : null}
291303
</div>
292304
) : null}

‎packages/client/src/styles/components.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117
height: 16px;
118118
}
119119

120+
.toolbar-right .icon-btn .rotate-right-icon {
121+
transform: scaleX(-1);
122+
}
123+
120124
.state-dot {
121125
width: 6px;
122126
height: 6px;

‎packages/client/src/styles/layout.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
min-width: 0;
129129
}
130130

131+
@media (max-width: 960px) {
132+
.toolbar .toolbar-wide-hidden {
133+
display: none;
134+
}
135+
}
136+
131137
.main {
132138
position: relative;
133139
display: flex;

0 commit comments

Comments
 (0)