From ca5ffaae99018b6ba09344c1936f4a753caeb8f9 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Sun, 1 Nov 2026 15:57:55 +0000 Subject: [PATCH 1/2] fix(web): keep the frame's aspect in the Android 3D view when a hinge device isn't on its inner display Any Android device with a hinge got the fold model, even when its frame was a regular phone or tablet display. The frame was stretched across a near-square inner screen, and leaving the fold aspect range never swapped the model back. Use the fold model while the hinge is closed (the cover screen shows) or the frame has an inner-display aspect. Otherwise use the phone model, and switch between them when frames, hinge angle, profile or the imported model change. An unfold keeps the fold body until the inner frame arrives. Co-Authored-By: Claude Opus 5.5 --- .../src/device/phoneViewer.test.ts | 36 +++++++++++++-- .../client-runtime/src/device/phoneViewer.ts | 44 +++++++++++++------ 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/packages/client-runtime/src/device/phoneViewer.test.ts b/packages/client-runtime/src/device/phoneViewer.test.ts index 9d8280ca9acd3..1c54c2a64d30d 100644 --- a/packages/client-runtime/src/device/phoneViewer.test.ts +++ b/packages/client-runtime/src/device/phoneViewer.test.ts @@ -80,9 +80,9 @@ vi.mock("./modelScene.ts", async () => { }; }); -import { Group, Quaternion } from "three"; +import { Box3, Group, Quaternion, Vector3 } from "three"; import { createPhoneViewer } from "./phoneViewer.ts"; -import { type DeviceShapeProfile } from "./shapeProfile.ts"; +import { ANDROID_PHONE_SHAPE, type DeviceShapeProfile } from "./shapeProfile.ts"; afterEach(() => { vi.restoreAllMocks(); @@ -91,7 +91,7 @@ afterEach(() => { models.pending.length = 0; }); -function fixture(profile?: DeviceShapeProfile) { +function fixture(profile?: DeviceShapeProfile, foldAngle?: number) { const pending = new Map(); let id = 0; let now = 0; @@ -111,6 +111,7 @@ function fixture(profile?: DeviceShapeProfile) { onUnavailable, onFramingAspect, ...(profile ? { profile } : {}), + ...(foldAngle === undefined ? {} : { foldAngle }), }); const draw = (time = now) => { now = time; @@ -152,3 +153,32 @@ it("rejects incompatible accessories and releases an accessory that finishes aft expect(dispose).toHaveBeenCalledOnce(); viewer.dispose(); }); + +it("uses the fold model only for a closed hinge or an inner display frame", () => { + const { viewer, draw, source, state } = fixture(ANDROID_PHONE_SHAPE, 180); + const shown = () => { + draw(); + const phone = state.frames.at(-1)!.phone!; + const size = new Box3().setFromObject(phone).getSize(new Vector3()); + return { + fold: phone.getObjectByName("continuous-inner-screen") !== undefined, + aspect: size.x / size.y, + }; + }; + const showFrame = (width: number, height: number) => { + source.width = width; + source.height = height; + viewer.setScreen({ width, height, orientation: "portrait" }); + viewer.frameUpdated(); + return shown(); + }; + expect(shown()).toEqual({ fold: false, aspect: expect.closeTo(1206 / 2622, 1) }); + expect(showFrame(2076, 2152)).toEqual({ fold: true, aspect: expect.closeTo(2076 / 2152, 1) }); + expect(showFrame(1080, 2400)).toEqual({ fold: false, aspect: expect.closeTo(1080 / 2400, 1) }); + viewer.setFoldAngle(0); + expect(shown().fold).toBe(true); + viewer.setFoldAngle(180); + expect(shown().fold).toBe(true); + expect(showFrame(2400, 1080).fold).toBe(false); + viewer.dispose(); +}); diff --git a/packages/client-runtime/src/device/phoneViewer.ts b/packages/client-runtime/src/device/phoneViewer.ts index af45745f8e484..5eab96f8c2db7 100644 --- a/packages/client-runtime/src/device/phoneViewer.ts +++ b/packages/client-runtime/src/device/phoneViewer.ts @@ -98,8 +98,6 @@ export function createPhoneViewer(options: { let layout = phoneDisplayLayout(screen, options.source.width, options.source.height); let profile = options.profile ?? IOS_PHONE_SHAPE; let foldAngle = options.foldAngle ?? null; - let orientationAngle = - foldAngle !== null && profile.id.startsWith("android") ? 0 : layout.rotation; let orientationTurn: { from: number; to: number; startedAt: number } | null = null; let imported: Awaited> | null = null; let modelSource = options.model ?? null; @@ -110,6 +108,9 @@ export function createPhoneViewer(options: { let foldAspect = isFoldInnerAspect(rawAspect()) ? rawAspect() : DEFAULT_FOLD_INNER_ASPECT; const createFoldScene = (angle: number, displayLayout = layout) => createAndroidFoldScene(texture, displayLayout, angle, foldAspect); + // Closed, the fold shows its cover screen. Open, only an inner display frame fits the fold body. + const fitsFold = (angle: number, nextProfile = profile) => + nextProfile.id.startsWith("android") && (angle < 90 || isFoldInnerAspect(rawAspect())); const visibleFoldAngle = (fallback: number) => { if (!foldTurn) return fallback; const progress = Math.min(1, (performance.now() - foldTurn.startedAt) / ANDROID_FOLD_TURN_MS); @@ -117,9 +118,10 @@ export function createPhoneViewer(options: { return foldTurn.from + (foldTurn.to - foldTurn.from) * eased; }; let phone: ReturnType | ReturnType = - foldAngle !== null && profile.id.startsWith("android") + foldAngle !== null && fitsFold(foldAngle) ? createFoldScene(foldAngle) : createPhoneScene(texture, layout, profile); + let orientationAngle = "setAngle" in phone ? 0 : layout.rotation; scene.add(phone.root); let disposed = false; const rest = new Quaternion(); @@ -238,17 +240,22 @@ export function createPhoneViewer(options: { const frameAspect = rawAspect(); const innerChanged = isFoldInnerAspect(frameAspect) && frameAspect !== foldAspect; if (innerChanged) foldAspect = frameAspect; - if (!imported && "setAngle" in phone && innerChanged) { - const angle = visibleFoldAngle(foldAngle ?? 180); + const wasFold = "setAngle" in phone; + const foldTo = + !imported && foldAngle !== null && fitsFold(foldAngle, nextProfile) ? foldAngle : null; + if (foldTo !== null && (!wasFold || innerChanged)) { + const angle = wasFold ? visibleFoldAngle(foldTo) : foldTo; + if (!wasFold) foldTurn = null; scene.remove(phone.root); phone.dispose(); phone = createFoldScene(angle, next); scene.add(phone.root); } else if ( !imported && - !("setAngle" in phone) && - (nextProfile !== profile || next.aspect !== layout.aspect) + foldTo === null && + (wasFold || nextProfile !== profile || next.aspect !== layout.aspect) ) { + foldTurn = null; scene.remove(phone.root); phone.dispose(); phone = createPhoneScene(texture, next, nextProfile); @@ -256,7 +263,10 @@ export function createPhoneViewer(options: { } else { phone.setDisplay(texture, next); } - if (next.rotation !== layout.rotation) { + if ("setAngle" in phone !== wasFold) { + orientationTurn = null; + orientationAngle = wasFold ? next.rotation : 0; + } else if (next.rotation !== layout.rotation) { if (nextProfile.id.startsWith("android") && !("setAngle" in phone) && !reducedMotion()) { const difference = Math.atan2( Math.sin(next.rotation - orientationAngle), @@ -287,7 +297,7 @@ export function createPhoneViewer(options: { ? null : model ? createImportedPhoneScene(model.asset, texture, layout) - : foldAngle !== null && profile.id.startsWith("android") + : foldAngle !== null && fitsFold(foldAngle) ? createFoldScene(foldAngle) : createPhoneScene(texture, layout, profile); foldTurn = null; @@ -301,6 +311,8 @@ export function createPhoneViewer(options: { if (imported) phone.orientation.add(accessory.asset); else accessory.asset.removeFromParent(); } + orientationTurn = null; + orientationAngle = "setAngle" in phone ? 0 : layout.rotation; applyPose(); fit(true); scheduler.invalidate(); @@ -350,17 +362,19 @@ export function createPhoneViewer(options: { const previous = foldAngle; foldAngle = next; if (imported) return; - if (next === null || !("setAngle" in phone)) { + const swap = (nextPhone: typeof phone) => { scene.remove(phone.root); phone.dispose(); - phone = next === null ? createPhoneScene(texture, layout, profile) : createFoldScene(next); + phone = nextPhone; scene.add(phone.root); orientationTurn = null; - orientationAngle = next === null ? layout.rotation : 0; + orientationAngle = "setAngle" in phone ? 0 : layout.rotation; foldTurn = null; applyPose(); fit(true); - } else { + }; + // An unfold turns the hinge before the cover frame becomes the inner one; the frame decides after. + if (next !== null && "setAngle" in phone) { const from = visibleFoldAngle(previous ?? next); if (reducedMotion()) { foldTurn = null; @@ -369,6 +383,10 @@ export function createPhoneViewer(options: { } else { foldTurn = { from, to: next, startedAt: performance.now() }; } + } else if (next !== null && fitsFold(next)) { + swap(createFoldScene(next)); + } else if ("setAngle" in phone) { + swap(createPhoneScene(texture, layout, profile)); } scheduler.invalidate(); }, From bf948c0acb6d04803db71a13418eeedf357c6cfb Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Sun, 1 Nov 2026 16:10:15 +0000 Subject: [PATCH 2/2] fix(web): Android 3D view uses the fold model only for an inner display frame A closed hinge still picked the fold model, so a tablet or phone frame was stretched over its narrow cover screen. Opening the hinge kept that fold body, and a later frame of the same size never swapped it back. Pick the fold model from the frame alone: an inner display aspect folds, any other frame gets the regular phone model, whatever the hinge angle. The constructor, frame updates, hinge changes and the model fallback all use that rule. Co-Authored-By: Claude Opus 5.5 --- .../src/device/phoneViewer.test.ts | 31 +++++++++++++------ .../client-runtime/src/device/phoneViewer.ts | 24 +++++++------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/client-runtime/src/device/phoneViewer.test.ts b/packages/client-runtime/src/device/phoneViewer.test.ts index 1c54c2a64d30d..cd792075876b7 100644 --- a/packages/client-runtime/src/device/phoneViewer.test.ts +++ b/packages/client-runtime/src/device/phoneViewer.test.ts @@ -154,31 +154,42 @@ it("rejects incompatible accessories and releases an accessory that finishes aft viewer.dispose(); }); -it("uses the fold model only for a closed hinge or an inner display frame", () => { - const { viewer, draw, source, state } = fixture(ANDROID_PHONE_SHAPE, 180); +it("uses the fold model only for an inner display frame, whatever the hinge angle", () => { + const { viewer, draw, source, state } = fixture(ANDROID_PHONE_SHAPE, 0); + let time = 0; const shown = () => { - draw(); + draw((time += 1000)); const phone = state.frames.at(-1)!.phone!; const size = new Box3().setFromObject(phone).getSize(new Vector3()); return { fold: phone.getObjectByName("continuous-inner-screen") !== undefined, - aspect: size.x / size.y, + fitsFrame: Math.abs(Math.log(size.x / size.y / (source.width / source.height))) < 0.1, }; }; const showFrame = (width: number, height: number) => { source.width = width; source.height = height; - viewer.setScreen({ width, height, orientation: "portrait" }); + viewer.setScreen({ + width, + height, + orientation: width > height ? "landscape_left" : "portrait", + }); viewer.frameUpdated(); return shown(); }; - expect(shown()).toEqual({ fold: false, aspect: expect.closeTo(1206 / 2622, 1) }); - expect(showFrame(2076, 2152)).toEqual({ fold: true, aspect: expect.closeTo(2076 / 2152, 1) }); - expect(showFrame(1080, 2400)).toEqual({ fold: false, aspect: expect.closeTo(1080 / 2400, 1) }); + const phoneModel = { fold: false, fitsFrame: true }; + expect(shown()).toEqual(phoneModel); + viewer.setFoldAngle(180); + expect(shown()).toEqual(phoneModel); + viewer.frameUpdated(); + expect(shown()).toEqual(phoneModel); + expect(showFrame(2076, 2152)).toEqual({ fold: true, fitsFrame: true }); viewer.setFoldAngle(0); expect(shown().fold).toBe(true); + expect(showFrame(1920, 1200)).toEqual(phoneModel); viewer.setFoldAngle(180); - expect(shown().fold).toBe(true); - expect(showFrame(2400, 1080).fold).toBe(false); + expect(shown()).toEqual(phoneModel); + expect(showFrame(2076, 2152)).toEqual({ fold: true, fitsFrame: true }); + expect(showFrame(1080, 2400)).toEqual(phoneModel); viewer.dispose(); }); diff --git a/packages/client-runtime/src/device/phoneViewer.ts b/packages/client-runtime/src/device/phoneViewer.ts index 5eab96f8c2db7..73d8bc07ccc09 100644 --- a/packages/client-runtime/src/device/phoneViewer.ts +++ b/packages/client-runtime/src/device/phoneViewer.ts @@ -108,9 +108,9 @@ export function createPhoneViewer(options: { let foldAspect = isFoldInnerAspect(rawAspect()) ? rawAspect() : DEFAULT_FOLD_INNER_ASPECT; const createFoldScene = (angle: number, displayLayout = layout) => createAndroidFoldScene(texture, displayLayout, angle, foldAspect); - // Closed, the fold shows its cover screen. Open, only an inner display frame fits the fold body. - const fitsFold = (angle: number, nextProfile = profile) => - nextProfile.id.startsWith("android") && (angle < 90 || isFoldInnerAspect(rawAspect())); + // Only an inner display frame fits the fold body; the cover screen would stretch any other frame. + const fitsFold = (nextProfile = profile) => + nextProfile.id.startsWith("android") && isFoldInnerAspect(rawAspect()); const visibleFoldAngle = (fallback: number) => { if (!foldTurn) return fallback; const progress = Math.min(1, (performance.now() - foldTurn.startedAt) / ANDROID_FOLD_TURN_MS); @@ -118,7 +118,7 @@ export function createPhoneViewer(options: { return foldTurn.from + (foldTurn.to - foldTurn.from) * eased; }; let phone: ReturnType | ReturnType = - foldAngle !== null && fitsFold(foldAngle) + foldAngle !== null && fitsFold() ? createFoldScene(foldAngle) : createPhoneScene(texture, layout, profile); let orientationAngle = "setAngle" in phone ? 0 : layout.rotation; @@ -241,8 +241,7 @@ export function createPhoneViewer(options: { const innerChanged = isFoldInnerAspect(frameAspect) && frameAspect !== foldAspect; if (innerChanged) foldAspect = frameAspect; const wasFold = "setAngle" in phone; - const foldTo = - !imported && foldAngle !== null && fitsFold(foldAngle, nextProfile) ? foldAngle : null; + const foldTo = !imported && foldAngle !== null && fitsFold(nextProfile) ? foldAngle : null; if (foldTo !== null && (!wasFold || innerChanged)) { const angle = wasFold ? visibleFoldAngle(foldTo) : foldTo; if (!wasFold) foldTurn = null; @@ -297,7 +296,7 @@ export function createPhoneViewer(options: { ? null : model ? createImportedPhoneScene(model.asset, texture, layout) - : foldAngle !== null && fitsFold(foldAngle) + : foldAngle !== null && fitsFold() ? createFoldScene(foldAngle) : createPhoneScene(texture, layout, profile); foldTurn = null; @@ -373,8 +372,11 @@ export function createPhoneViewer(options: { applyPose(); fit(true); }; - // An unfold turns the hinge before the cover frame becomes the inner one; the frame decides after. - if (next !== null && "setAngle" in phone) { + if (next === null || !fitsFold()) { + if ("setAngle" in phone) swap(createPhoneScene(texture, layout, profile)); + } else if (!("setAngle" in phone)) { + swap(createFoldScene(next)); + } else { const from = visibleFoldAngle(previous ?? next); if (reducedMotion()) { foldTurn = null; @@ -383,10 +385,6 @@ export function createPhoneViewer(options: { } else { foldTurn = { from, to: next, startedAt: performance.now() }; } - } else if (next !== null && fitsFold(next)) { - swap(createFoldScene(next)); - } else if ("setAngle" in phone) { - swap(createPhoneScene(texture, layout, profile)); } scheduler.invalidate(); },