fix(ios): sync preview orientation with device orientation#86
Open
grfalk wants to merge 1 commit intoNativeScript:mainfrom
Open
fix(ios): sync preview orientation with device orientation#86grfalk wants to merge 1 commit intoNativeScript:mainfrom
grfalk wants to merge 1 commit intoNativeScript:mainfrom
Conversation
The AVCaptureVideoPreviewLayer connection orientation is never synced with the device orientation, causing the camera preview to appear rotated 90 degrees when the device is in landscape mode (e.g. iPad). Add _syncPreviewOrientation() which reads the current interface orientation from UIWindowScene and applies it to the preview layer connection using videoRotationAngle (iOS 17+) or the deprecated videoOrientation fallback. The sync is called on load, on orientation change, and after toggleCamera().
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Gary Faulkner.
|
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.
Problem
The AVCaptureVideoPreviewLayer connection orientation is never synced with the current device orientation. This causes the camera preview to appear rotated 90 degrees when the device is in landscape mode - most commonly observed on iPad, but affects any iOS device that supports multiple orientations.
Root Cause
In index.ios.ts, createNativeView() creates the AVCaptureVideoPreviewLayer from the capture session and adds it to the view, but never sets videoOrientation (or videoRotationAngle on iOS 17+) on the layer connection. The onLayout() method updates the layer frame but not its orientation.
Fix
Added a private _syncPreviewOrientation() method that:
The method is called:
Testing
Verified the fix corrects the 90-degree rotation on iPad in landscape mode when using MLKitView with DetectionType.Barcode via @nativescript/mlkit-barcode-scanning.
Made with Cursor