Skip to content

feat: expose upright Preview resolution for responsive camera UIs - #4224

Open
ismaelsousa wants to merge 22 commits into
margelo:mainfrom
ismaelsousa:feat/output-rotation-degrees
Open

ismaelsousa wants to merge 22 commits into
margelo:mainfrom
ismaelsousa:feat/output-rotation-degrees

Conversation

@ismaelsousa

@ismaelsousa ismaelsousa commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

No more guessing the Preview’s upright resolution

The existing currentResolution describes the Preview stream in its native, unrotated orientation. To align UI with the image users actually see, apps have had to infer its upright size and keep resolution and rotation in sync themselves.

This PR adds onPreviewResolution to <Camera />. It reports upright stream dimensions directly as the Preview configuration changes:

<Camera
  resizeMode="contain"
  onPreviewResolution={({ width, height }) => {
    setPreviewAspectRatio(width / height)
  }}
/>
Android iOS
vertical Upright reso iOs
upright-res-android-1.mov
upright-reso.mp4
PiP-android-1.mov
PiP.mp4
adaptative-controls.mp4
adapative-controls-android-2.mov

Same Preview, same resize mode. Using its reported upright ratio moves the frame and controls into alignment with the visible image.

Why it matters

  • Controls and overlays can follow the image, rather than a guessed frame or the black bars created by contain.
  • Responsive layouts and picture-in-picture can preserve the Preview’s upright aspect ratio through orientation changes.
  • Apps can define the correct touch area and avoid sending tap-to-focus requests from letterboxed regions. Such requests can fail on affected devices. This PR enables that boundary; it does not automatically filter taps.
Guessed Using onPreviewResolution
adaptative controls guessed adaptive controls upright

What changed

  • <Camera onPreviewResolution> provides upright dimensions for the common layout use case.
  • <Camera onPreviewConfigurationChanged> exposes the complete configuration when needed.
  • Lower-level users can read CameraPreviewOutput.currentConfiguration or subscribe through onConfigurationChanged. Its resolution remains in native, unrotated pixels alongside rotationDegrees.
  • Android tracks Preview configuration as interface orientation changes; iOS observes connection and stream-format changes.
  • Preview Lab demonstrates upright dimensions, adaptive controls, and picture-in-picture. Nitro-generated bindings are included in the diff.

Compatibility

Android is supported. On iOS, upright resolution requires iOS 17.0+; onPreviewResolution is not called on earlier versions.

Fixes #4236

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

@ismaelsousa is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

@ismaelsousa ismaelsousa changed the title Feat/output rotation degrees feat: expose upright Preview resolution for responsive camera UIs Oct 27, 2026
@ismaelsousa
ismaelsousa marked this pull request as ready for review October 27, 2026 22:28
@ismaelsousa

Copy link
Copy Markdown
Contributor Author

Adding tests to cover the new feature

image

Store and forward outputOrientation to Preview.targetRotation so CameraX updates ResolutionInfo for the new target orientation. This keeps resolutionInfo.rotationDegrees synchronized instead of leaving it based on the default rotation.
Use AVCaptureDevice.RotationCoordinator on iOS 17 and later, creating the interface orientation manager only on older versions. Apply preview rotation updates synchronously and clean up observation on reconfiguration and deinit.

Related PR: margelo#4237

Validation: VisionCamera iOS target build, Swift formatting, and git diff --check passed.
…nfiguration because does nothing anymore on android
@ismaelsousa
ismaelsousa force-pushed the feat/output-rotation-degrees branch from fbbc46b to 30087eb Compare October 29, 2026 18:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [iPhone Duo] Cameras are rotated 90° clockwise when using the camera on the inner display

1 participant