Skip to content

fix: initialize iOS preview orientation#3899

Open
Phecda wants to merge 1 commit into
mrousavy:mainfrom
Phecda:fix/ios-preview-initial-orientation
Open

fix: initialize iOS preview orientation#3899
Phecda wants to merge 1 commit into
mrousavy:mainfrom
Phecda:fix/ios-preview-initial-orientation

Conversation

@Phecda
Copy link
Copy Markdown

@Phecda Phecda commented May 20, 2026

Summary

Fixes an iOS preview orientation race when the camera is first configured after launching the app directly into landscape.

HybridInterfaceOrientationManager previously initialized currentOrientation asynchronously on the main queue. In fast startup paths, HybridCameraPreviewOutput.configure(...) could run before that async orientation read completed, leaving the preview connection without the current interface orientation until a later orientation notification arrived.

This PR makes the initial orientation available earlier and applies it more reliably:

  • read the initial interface orientation synchronously when already on the main thread;
  • refresh the current interface orientation immediately after starting orientation updates;
  • retry applying the preview connection orientation on the next main-queue turn if configure(...) runs before currentOrientation is available.

Reproduction branch:

https://github.com/Phecda/react-native-vision-camera/tree/repro/ios-landscape-preview-orientation

Repro Steps:

  1. Build in Release mode
  2. Grant camera permission, then fully terminate the app.
  3. Rotate the device to landscape and launch the app again.

Expected: the preview is landscape.

Actual: the first preview is rotated by 90 degrees; re-entering the camera screen fixes it.

Changelog

[IOS] [FIXED] - Initialize and apply preview interface orientation during first camera configuration.

Test Plan

swift format --configuration ./config/.swift-format --in-place \
  "packages/react-native-vision-camera/ios/Hybrid Objects/Orientation/HybridInterfaceOrientationManager.swift" \
  "packages/react-native-vision-camera/ios/Hybrid Objects/Outputs/HybridCameraPreviewOutput.swift"

git diff --check

bun camera build

Result:

TypeScript build completed successfully.

I also reproduced the issue with the example app by launching directly in landscape and verified this fix in a downstream app where release builds previously showed the first preview rotated by 90 degrees until leaving and re-entering the camera screen.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

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

A member of the Team first needs to authorize it.

@Phecda Phecda marked this pull request as ready for review May 20, 2026 02:53
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.

1 participant