Repository navigation
ios: continuous autofocus for the QR scanner and the capture camera - #349
Merged
Merged
Conversation
The owner reported the iPad not autofocusing, "ex. in the QR code".
Neither camera path owned a capture session, so neither ever configured
focus: `PairingScannerView` hands off to VisionKit's
`DataScannerViewController` and `CameraPicker` to `UIImagePickerController`,
and both keep their `AVCaptureSession` and `AVCaptureDeviceInput` private.
The remaining lever is the `AVCaptureDevice`, which is process-wide: focus
settings applied to it while a session runs do take effect on that session.
Add `CameraFocus`:
- `apply(nearRange:)` locks the back wide-angle device and sets
`focusMode = .continuousAutoFocus`, `.continuousAutoExposure`, and
`isSubjectAreaChangeMonitoringEnabled = true`.
- `nearRange` additionally sets `autoFocusRangeRestriction = .near`. This
is what a QR at reading distance needs; without it the lens hunts the
whole range and tends to settle on the far field.
- `Reapplier` re-asserts focus on `subjectAreaDidChangeNotification`, and
restores the device on deinit so other sessions are unaffected.
Both call sites apply it AFTER a short settle delay, because a system
controller reconfigures the device as its session starts and anything set
before that is overwritten. The scanner asks for `.near`; the photo camera
does not, since a capture may be a whiteboard across the room.
A camera that reports `isFocusModeSupported(.continuousAutoFocus) == false`
is genuinely fixed-focus (several iPad front cameras are). That returns
`.unsupported` and the scanner sheet says so, rather than implying a fix
that did not happen.
NOT verified on hardware: this machine has no simulator runtime (see the
PR body) and autofocus cannot be exercised in a simulator regardless. The
behaviour needs a check on the owner's iPad.
Implementation-Agent: Claude Code iPad companion agent (linux-primary)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Contributor
|
daniel-parent Mac pre-merge verification (for the integration lane, which has no Swift toolchain). Xcode 26.6, macOS 26.6, merged onto
About the 3 full-suite failures: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Owner feedback item 4:
Yes — with one honest caveat, below.
Cause
Neither camera path ever configured focus, because neither owns its capture session.
PairingScanner.swifthands off to VisionKit'sDataScannerViewController(the QR path).CaptureView.swift'sCameraPickerhands off toUIImagePickerControllerwith.camera.Both keep their
AVCaptureSessionandAVCaptureDeviceInputprivate, and neither exposes any focus API. There was noAVFoundationimport anywhere inapps/iosbefore this change — I checked every capture session in the app, not just the scanner; those two are all of them.The lever that remains is the
AVCaptureDeviceitself, which is a process-wide object: focus settings applied to it while a session is running do take effect on that session.Change —
CameraFocus.swiftapply(nearRange:)locks the back wide-angle device and setsfocusMode = .continuousAutoFocus,.continuousAutoExposure, andisSubjectAreaChangeMonitoringEnabled = true.nearRangeadditionally setsautoFocusRangeRestriction = .near. This is the one that matters for a QR held at reading distance — without it the lens hunts the full range and tends to settle on the far field.Reapplierre-asserts focus onsubjectAreaDidChangeNotification, and restores the device ondeinitso other sessions are unaffected.Both call sites apply it after a short settle delay, because a system controller reconfigures the device as its session starts and anything set before that is simply overwritten. The scanner asks for
.near; the photo camera does not, since a capture may be a whiteboard across the room as easily as a page on the desk.Where it genuinely cannot be fixed
A camera reporting
isFocusModeSupported(.continuousAutoFocus) == falseis a fixed-focus camera — several iPad front cameras are — and no software setting changes that. That returns.unsupported(deviceName:)and the scanner sheet now says so:rather than implying a fix that did not happen.
Verification
AVCaptureDevice.Worse, the owner's Mac cannot currently build for the iOS simulator at all:
/Library/Developer/PrivateFrameworks/CoreSimulator.frameworkis missing, soxcodebuildfails to loadIDESimulatorFoundationand refuses to run for any destination.xcodebuild -runFirstLaunchneeds admin rights not available over SSH.What I could verify:
xcrun swiftc -typecheck(bypassingxcodebuild) — 0 errors.apps/ios/scripts/generate-xcodeproj.pyre-run soCameraFocus.swiftandCameraFocusTests.swiftare registered with the app and test targets.CameraFocusTestspins the part that must stay honest — a fixed-focus camera is reported, not silently ignored. These tests have never been executed here; CI'siPad companion (simulator build + tests)job runsFlashTeXPadTestsand will be the first to run them.The actual autofocus behaviour needs a check on the owner's iPad. If it still will not focus after this, the next thing to know is which camera is in use and what
CameraFocus.Outcomeit reports.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu