From aefbb304cfb13cb8c1d8c9a4911d1fa860a0dc43 Mon Sep 17 00:00:00 2001 From: bubulux Date: Wed, 25 Nov 2026 17:51:01 +0100 Subject: [PATCH] Device and camera: orientation of the Camera tab, lenses switched off, focal length along its bar (#426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Setup › Camera: the Camera tab's orientation per device (as held, landscape, portrait); the app keeps it while the tab is open (expo-screen-orientation) and turns freely on the other tabs. - Setup › This device: a lens a driver reports but the device does not have is switched off; no app offers it, the device file marks it off, and the Studio's layout preview leaves it out. The main lens stays. - The zoom preset's focal length control follows its bar: horizontal in a top or bottom bar, vertical in a side bar (+ at the top); − and + step a millimetre with room around them; never clipped. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/apps/Camera.tsx | 55 ++++++++++++++++++++++++++--- apps/mobile/src/apps/Setup.tsx | 11 ++++-- apps/mobile/src/device.ts | 16 ++++++++- apps/mobile/src/settings.ts | 2 ++ apps/studio/src/apps/DevicesApp.tsx | 2 +- apps/studio/src/apps/LayoutsApp.tsx | 2 +- docs/features/capture.md | 4 +-- packages/model/src/types.ts | 3 ++ 8 files changed, 83 insertions(+), 12 deletions(-) diff --git a/apps/mobile/src/apps/Camera.tsx b/apps/mobile/src/apps/Camera.tsx index d91e849..6a13e62 100644 --- a/apps/mobile/src/apps/Camera.tsx +++ b/apps/mobile/src/apps/Camera.tsx @@ -5,7 +5,7 @@ import { Camera as VisionCamera, CommonResolutions, useCameraDevices, useCameraP import { DELIVERIES, FORMATS, PRIMES, opticsFrame } from "@openclapper/fov-math"; import { CONTROLS, focalsOf, REFERENCE_STEPS, type Bar, type ControlId, type Distribution, type Edge, type LayoutBody, type LayoutItem, type PresetBody } from "@openclapper/model"; import { canCall, putFile } from "../api"; -import { lenses as lensStore, measureCamera } from "../device"; +import { measureCamera, useLensSet } from "../device"; import type { Lens } from "../lenses"; import { leavePreview } from "../link"; import { log } from "../log"; @@ -22,7 +22,8 @@ import { allLayouts, chooseLayout, useLayout } from "../camera/layouts"; import { captureFact, collecting, endCollection, frameBox, frames, liveView, nextFolder, startCollection, toggles, type FrameChoice } from "../camera/state"; import { Button, Empty, FIXED, Hint, Icon, ListRow, makeStyles, num, RADIUS, SectionLabel, Seg, Sheet, SheetList, SIZE, Slider, toast, type, useTheme, Block, type IconName } from "../ui"; import { registerApp } from "./registry"; -import { useCameraButtons } from "../settings"; +import * as ScreenOrientation from "expo-screen-orientation"; +import { settings, useCameraButtons } from "../settings"; /** * The camera (docs/features/camera-layouts.md, docs/rewrite/03-capture.md): the phone takes photos; everything else @@ -36,13 +37,21 @@ const JUSTIFY: Record { + if (!active || orient === "auto") return; + void ScreenOrientation.lockAsync(orient === "landscape" ? ScreenOrientation.OrientationLock.LANDSCAPE : ScreenOrientation.OrientationLock.PORTRAIT_UP).catch((e) => log("warn", "camera: orientation not locked", e)); + return () => { void ScreenOrientation.unlockAsync().catch(() => undefined); }; + }, [active, orient]); const s = useStyles(); const { width, height } = useWindowDimensions(); const project = useProject(); const prefs = usePrefs(); const perm = useCameraPermission(); const devices = useCameraDevices(); - const set = lensStore.use(); + const set = useLensSet(); const chosen = lensChoice.use(); const presets = usePresets(); const lib = useLibrary(); @@ -180,7 +189,7 @@ function Camera({ active }: { active: boolean }) { } if (i.control === "focal") { if (!frame || frame.kind === "aspect") return null; - if (preset?.lenses.kind === "zoom") return `${v} mm`} onChange={setFocal} />; + if (preset?.lenses.kind === "zoom") return ; if (i.display === "stepped" || frame.kind === "free") return { const k = focals.indexOf(frame.focal), n = focals[k < 0 ? 0 : k + d]; if (n) setFocal(n); }} />; return {focals.map((mm) => setFocal(mm)} text={String(mm)} />)}; } @@ -282,6 +291,38 @@ function Blackout({ box, w, h, color }: { box: { left: number; top: number; widt } /** A strip shown one value at a time: back, the value, on; three parts a thumb can hit, stacked in an upright bar. */ +/** + * A zoom lens's focal length on the camera (#426): along its bar, horizontal in a top or bottom bar, vertical in a side + * bar (longer at the top); − and + step one millimetre, the track is dragged. Never wider or taller than its bar allows. + */ +function ZoomRange({ vertical, value, min, max, onChange }: { vertical: boolean; value: number; min: number; max: number; onChange: (mm: number) => void }) { + const s = useStyles(); + const sizes = useCameraButtons(); + const LEN = 150; + const frac = max > min ? (value - min) / (max - min) : 0; + const at = (x: number, y: number) => { + const f = Math.min(1, Math.max(0, vertical ? 1 - y / LEN : x / LEN)); + const mm = Math.round(min + f * (max - min)); + if (mm !== value) onChange(mm); + }; + const track = ( + true} onMoveShouldSetResponder={() => true} onResponderTerminationRequest={() => false} + onResponderGrant={(e) => at(e.nativeEvent.locationX, e.nativeEvent.locationY)} onResponderMove={(e) => at(e.nativeEvent.locationX, e.nativeEvent.locationY)}> + + + + ); + const less = onChange(Math.max(min, value - 1))} />; + const more = = max} onPress={() => onChange(Math.min(max, value + 1))} />; + return ( + + {vertical ? <>{more}{track}{less} : <>{less}{track}{more}} + {`${value} mm`} + + ); +} + function Stepped({ vertical, value, label, onStep }: { vertical: boolean; value: string; label: string; onStep: (d: -1 | 1) => void }) { const s = useStyles(); return ( @@ -408,6 +449,12 @@ const useStyles = makeStyles(() => ({ strip: { flexDirection: "row", gap: 8, alignItems: "center" }, stripV: { flexDirection: "column" }, stepped: { flexDirection: "row", alignItems: "center", gap: 4, padding: 3, borderRadius: 28, borderWidth: 2, borderColor: FIXED.white, backgroundColor: FIXED.black }, + zoom: { flexDirection: "row", alignItems: "center", padding: 4, borderRadius: 28, backgroundColor: FIXED.black, borderWidth: 2, borderColor: FIXED.white }, + zoomV: { flexDirection: "column" }, + zoomTrack: { position: "relative" }, + zoomRail: { position: "absolute", borderRadius: 2, backgroundColor: FIXED.white, opacity: 0.6 }, + zoomThumb: { position: "absolute", width: 20, height: 20, borderRadius: 10, backgroundColor: FIXED.white }, + zoomValue: { ...type("caption", "bold"), color: FIXED.white, ...num, minWidth: 44, textAlign: "center" }, steppedValue: { ...type("label", "bold"), color: FIXED.white, minWidth: 44, textAlign: "center", ...num }, ctl: { alignItems: "center", gap: 2 }, ctlLabel: { ...type("caption", "bold"), fontSize: 10, color: FIXED.white, opacity: 0.85 }, diff --git a/apps/mobile/src/apps/Setup.tsx b/apps/mobile/src/apps/Setup.tsx index 2a41e97..64d9084 100644 --- a/apps/mobile/src/apps/Setup.tsx +++ b/apps/mobile/src/apps/Setup.tsx @@ -5,7 +5,7 @@ import { Pressable, Share, Text, View } from "react-native"; import { changePassword, signOut } from "../api"; import { isSignedIn, onAuthChange, signedInEmail } from "../auth"; import { API_URL, isConfigured } from "../config"; -import { device, lenses, renameDevice, reportedModel, setTabs } from "../device"; +import { device, lenses, lensesOff, renameDevice, reportedModel, setLensOff, setTabs } from "../device"; import { clearLog, logCount, logText } from "../log"; import { setPrefs, usePrefs, usePrefsPending, type Prefs } from "../prefs"; import { useExtensionsOn, useProject } from "../projects"; @@ -162,6 +162,7 @@ const hAov = (f: number) => Math.round((2 * Math.atan(36 / (2 * f)) * 180) / Mat function DevicePage({ back }: { back: () => void }) { const dev = device.use(); const set = lenses.use(); + const off = lensesOff.use(); const email = useEmail(); const [naming, setNaming] = useState(null); const body = dev.file?.body as { kind?: string; screen?: { portrait: { w: number; h: number } } | null } | undefined; @@ -172,9 +173,10 @@ function DevicePage({ back }: { back: () => void }) { {body?.kind && } {body?.screen && } {email && } - Real lenses, as the camera reports them + Real lenses, as the camera reports themSwitch off a lens the camera reports but the device does not have: no app offers it any more. {set.lenses.length ? set.lenses.map((l) => ( - + setLensOff(l.id, !on)} /> )) : Not read yet: open the camera once.} No digital zoom: every photo is the full picture of one real lens. setNaming(null)} doneLabel="Save" onDone={() => { renameDevice(naming ?? ""); setNaming(null); }}> @@ -249,6 +251,9 @@ function CameraPage({ back }: { back: () => void }) { Buttons on this device setSettings({ cameraButtons: v })} options={[{ id: "s", label: "Small" }, { id: "m", label: "Medium" }, { id: "l", label: "Large" }]} /> The size of the camera's buttons and shutter here only: small suits a phone, large a tablet. + Orientation of the camera + setSettings({ cameraOrientation: v })} options={[{ id: "auto", label: "As held" }, { id: "landscape", label: "Landscape" }, { id: "portrait", label: "Portrait" }]} /> + While the Camera tab is open the app keeps this orientation, however the device is held; the other tabs turn as usual. Camera layout on this device {allLayouts().map((l) => chooseLayout(l.id)} />)} diff --git a/apps/mobile/src/device.ts b/apps/mobile/src/device.ts index cecb240..48954ba 100644 --- a/apps/mobile/src/device.ts +++ b/apps/mobile/src/device.ts @@ -38,6 +38,20 @@ export const device = persisted("device.v2", { userId: null, file: /** The real lenses as last read from the camera (persisted, so Setup can list them with the camera closed). */ export const lenses = persisted("lenses.v1", { lenses: [], torch: false }); +/** + * Lenses switched off on this device (#426): a driver may report a lens that is not there (a 0.8× beside the 0.5×). + * Gone for every app here, and marked `off` in the device file so the Studio leaves it out too. The main lens stays. + */ +export const lensesOff = persisted("lensesOff.v1", [], (v) => Array.isArray(v) && v.every((x) => typeof x === "string")); +export function setLensOff(id: string, off: boolean) { + lensesOff.set((all) => (off ? [...new Set([...all, id])] : all.filter((x) => x !== id))); + void syncDevice(); +} +/** The lenses the apps offer: the real ones without those switched off. */ +export function useLensSet(): LensSet { + const set = lenses.use(), off = lensesOff.use(); + return { ...set, lenses: set.lenses.filter((l) => l.main || !off.includes(l.id)) }; +} let lensesRead = false; function readLenses() { const set = lensSet(getAllCameraDevices() as unknown as CamLike[]); @@ -75,7 +89,7 @@ function report(): DeviceReport { kind: short >= 600 ? "tablet" : "phone", make: make.charAt(0).toUpperCase() + make.slice(1), model: (k.Model ?? k.model ?? "").slice(0, 120), - lenses: lenses.get().lenses.map(deviceLens), + lenses: lenses.get().lenses.map((l) => ({ ...deviceLens(l), ...(!l.main && lensesOff.get().includes(l.id) ? { off: true } : {}) })), screen: short > 0 ? { portrait: { w: short, h: long }, landscape: { w: long, h: short } } : null, // Both orientations once both were measured; until then the other one is the first turned round. ...(() => { const a = cameraArea.get(), p = a.portrait ?? (a.landscape && { w: a.landscape.h, h: a.landscape.w }), l = a.landscape ?? (a.portrait && { w: a.portrait.h, h: a.portrait.w }); return p && l ? { camera: { portrait: p, landscape: l } } : {}; })(), diff --git a/apps/mobile/src/settings.ts b/apps/mobile/src/settings.ts index b39bd21..008b620 100644 --- a/apps/mobile/src/settings.ts +++ b/apps/mobile/src/settings.ts @@ -14,6 +14,8 @@ export interface LocalSettings { logging: boolean; /** How large the camera's buttons are on this device (#426): small on a phone, large on a tablet. */ cameraButtons?: CameraButtonSize; + /** How the app turns while the Camera tab is open (#426): as the device is held, or always landscape or portrait. */ + cameraOrientation?: "auto" | "landscape" | "portrait"; } export type CameraButtonSize = "s" | "m" | "l"; /** The camera's button sizes (dp): the button, its icon, the shutter. */ diff --git a/apps/studio/src/apps/DevicesApp.tsx b/apps/studio/src/apps/DevicesApp.tsx index 976825e..5a4b7e7 100644 --- a/apps/studio/src/apps/DevicesApp.tsx +++ b/apps/studio/src/apps/DevicesApp.tsx @@ -105,7 +105,7 @@ function PhoneCard({ d, devices, layouts, connected }: { d: FileRec; devices: Fi

What it reported

Screen {b.screen ? `${b.screen.portrait.w} × ${b.screen.portrait.h}` : "unknown"}{b.camera ? ` · camera area ${b.camera.portrait.w} × ${b.camera.portrait.h}` : ""}

-

{b.lenses.length ? b.lenses.map((l) => `${l.name}${l.focal35 ? ` (${l.focal35} mm)` : " (no focal length)"}`).join(", ") : "No lenses reported yet"}

+

{b.lenses.length ? b.lenses.map((l) => `${l.name}${l.focal35 ? ` (${l.focal35} mm)` : " (no focal length)"}${(l as { off?: boolean }).off ? ", switched off" : ""}`).join(", ") : "No lenses reported yet"}

Tabs

diff --git a/apps/studio/src/apps/LayoutsApp.tsx b/apps/studio/src/apps/LayoutsApp.tsx index b15da0e..3218983 100644 --- a/apps/studio/src/apps/LayoutsApp.tsx +++ b/apps/studio/src/apps/LayoutsApp.tsx @@ -139,7 +139,7 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File const k = Math.min(1, 620 / h, 860 / w); const placed = bars.flatMap((b) => b.items.map((i) => i.control)); const lensNames = (body.options.lensNames === "account" ? "phone" : body.options.lensNames); - const devLenses = db.lenses?.length ? db.lenses : [{ id: "w", name: "0.5×", focal35: 13 }, { id: "m", name: "1×", focal35: 24, main: true }, { id: "t", name: "5×", focal35: 120 }]; + const devLenses = db.lenses?.length ? db.lenses.filter((l) => !(l as { off?: boolean }).off) : [{ id: "w", name: "0.5×", focal35: 13 }, { id: "m", name: "1×", focal35: 24, main: true }, { id: "t", name: "5×", focal35: 120 }]; const lenses = (body.options.lenses.mode === "main" ? devLenses.filter((l) => l.main ?? l.name === "1×").slice(0, 1) : body.options.lenses.mode === "pick" ? devLenses.filter((l) => body.options.lenses.pick.includes(l.id)) : devLenses) .map((l) => (lensNames === "focal" && l.focal35 ? String(Math.round(l.focal35)) : l.name)); const framed = placed.some((c) => ["frame", "focal", "fit", "blackout", "reference", "upright"].includes(c)); diff --git a/docs/features/capture.md b/docs/features/capture.md index fd32970..7a4e3b2 100644 --- a/docs/features/capture.md +++ b/docs/features/capture.md @@ -7,10 +7,10 @@ The phone takes photos. A capture is one photo: queued at once, visible in Media ## Camera (`apps/mobile/src/apps/Camera.tsx`) - `react-native-vision-camera` 5.2.3: photo output `HIGHEST_4_3` (the sensor's largest 4:3 picture), JPEG quality 1, quality prioritised over speed (#426), preview drawn whole (`contain`) on black, the camera released while another tab is in front or the app is in the background. -- **Real lenses only** ([phone app](phone-app.md#this-device-srcdevicets-srclensests)): a lens is opened as the logical camera at the lens's zoom, or as a camera of its own. No digital zoom, so every photo is the full picture of one real lens and its EXIF describes it. A phone with one lens shows no lens rail. +- **Real lenses only** ([phone app](phone-app.md#this-device-srcdevicets-srclensests); a lens a driver reports but the device does not have is switched off in Setup › This device, #426: no app offers it and the device file marks it `off`): a lens is opened as the logical camera at the lens's zoom, or as a camera of its own. No digital zoom, so every photo is the full picture of one real lens and its EXIF describes it. A phone with one lens shows no lens rail. - **Lens names**: as the phone calls them (0.5×, 1×, 5×), or by the reported full-frame focal length (Setup, Camera; the account's preference). - **Built-in layout**: held upright, the lens rail above the control row; in landscape the control row stands at the right (beside the tab bar), the lens rail at the far left. Control row: uploads (count, red when something is stuck; opens Setup, Uploads), the last photo (opens it in Media), the shutter, the torch (filled when on). A strip over the picture names the project and the lens in use. -- Camera buttons are black with a white outline and a white icon when off, so they read over any picture, and filled in the accent colour when on (#426). Their size (with the shutter and the last-photo thumbnail) is chosen per device in Setup › Camera: small (40 dp), medium (48), large (60), kept in this device's settings (`cameraButtons`). +- Camera buttons are black with a white outline and a white icon when off, so they read over any picture, and filled in the accent colour when on (#426). Their size (with the shutter and the last-photo thumbnail) is chosen per device in Setup › Camera: small (40 dp), medium (48), large (60), kept in this device's settings (`cameraButtons`). The **orientation** of the Camera tab is chosen there too (#426): as held, landscape or portrait; while the tab is open the app keeps it (`expo-screen-orientation`), the other tabs turn as usual. A zoom preset's **focal length** control follows its bar: horizontal in a top or bottom bar, vertical in a side bar with + at the top; − and + step a millimetre, the track is dragged. ## What a capture produces (`src/media/pipeline.ts`) diff --git a/packages/model/src/types.ts b/packages/model/src/types.ts index bc76e6e..971a1d0 100644 --- a/packages/model/src/types.ts +++ b/packages/model/src/types.ts @@ -184,6 +184,8 @@ export interface DeviceLens { focal35: number | null; /** The zoom factor of the logical camera at which this lens takes over, where the camera reports one. */ zoom: number | null; + /** Switched off on the device (#426): a lens a driver reports that is not there; no app offers it. */ + off?: boolean; } /** @@ -208,6 +210,7 @@ export const DEVICE: FileType = { if (!isRecord(l) || !short(l.id, 60) || !short(l.name, 20)) return "a lens has an id and a name"; if (!(l.focal35 === null || (typeof l.focal35 === "number" && l.focal35 > 0 && l.focal35 < 2000))) return "a lens's focal35 is a positive number or null"; if (!(l.zoom === null || (typeof l.zoom === "number" && l.zoom > 0 && l.zoom < 1000))) return "a lens's zoom is a positive number or null"; + if (l.off !== undefined && typeof l.off !== "boolean") return "a lens's off is true or false"; } if (!(body.screen === null || (isRecord(body.screen) && size(body.screen.portrait) && size(body.screen.landscape)))) return "screen holds portrait and landscape sizes"; if (!Array.isArray(body.tabs) || body.tabs.length > 20 || !body.tabs.every((t) => typeof t === "string" && APP_ID.test(t))) return "tabs must be a list of app ids";