Skip to content

Fix Apple camera preview orientation#310

Merged
jfversluis merged 1 commit into
mainfrom
jfversluis/ios-preview-orientation-fix
Jun 17, 2026
Merged

Fix Apple camera preview orientation#310
jfversluis merged 1 commit into
mainfrom
jfversluis/ios-preview-orientation-fix

Conversation

@jfversluis

@jfversluis jfversluis commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Resolve iOS/MacCatalyst camera preview orientation from the active UIWindowScene instead of relying on UIDevice.CurrentDevice.Orientation during preview layout.
  • Use EffectiveGeometry.InterfaceOrientation on iOS/MacCatalyst 26+ and UIWindowScene.InterfaceOrientation below that, with fallback to device orientation/last known/portrait when scene orientation is unavailable.
  • Register orientation notifications idempotently on connect and remove them on disconnect/dispose; notification handling now requests layout instead of calling LayoutSubviews() directly.

Fixes #40.

Validation

  • dotnet restore ZXing.Net.MAUI/ZXing.Net.MAUI.csproj
  • dotnet build ZXing.Net.MAUI/ZXing.Net.MAUI.csproj -f net10.0-ios -c Release --no-restore
  • dotnet build ZXing.Net.MAUI/ZXing.Net.MAUI.csproj -f net10.0-maccatalyst -c Release --no-restore
  • Verified the same iOS/MacCatalyst builds with SDK 10.0.102 selected from a session-local global.json.
  • dotnet test ZXing.Net.MAUI.Tests/ZXing.Net.MAUI.Tests.csproj -f net10.0 -c Release

Remaining risk

  • Not device-tested in this environment; validation is compile/test coverage only.

Linked issues

Fixes #296.

@jfversluis

Copy link
Copy Markdown
Collaborator Author

@bstadick since you authored the earlier orientation PR (#186), and @bhuvan94 since you opened the linked issue (#40): could you please test the artifacts from this PR if they help your situation?

This is a fresh, focused iOS/MacCatalyst preview-orientation fix based on current main, without the unrelated workflow changes from the older PR. Any real-device feedback, especially around rotation and iPad/windowed scenarios, would be very helpful.

Use the active window scene interface orientation for the iOS and MacCatalyst preview layer, falling back safely when scene orientation is unavailable. Trigger layout updates from an idempotent orientation observer and remove it during disconnect/dispose.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jfversluis jfversluis force-pushed the jfversluis/ios-preview-orientation-fix branch from dd34363 to cfe843d Compare June 17, 2026 08:35
@jfversluis jfversluis merged commit 7159b3a into main Jun 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant