Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions ios/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CameraView: UIView {
guard let self = self else { return }
if let previewLayer = self.previewLayer {
previewLayer.session = session
previewLayer.connection?.videoOrientation = .portrait
self.updateVideoOrientation()
print("✅ Preview layer bound to session from onSessionReady callback")
} else {
print("⚠️ Preview layer missing when session became ready")
Expand All @@ -62,7 +62,7 @@ public class CameraView: UIView {
guard let self = self, let previewLayer = self.previewLayer else { return }
if let existingSession = existingSession {
previewLayer.session = existingSession
previewLayer.connection?.videoOrientation = .portrait
self.updateVideoOrientation()
print("✅ Preview layer bound to existing session")
}
}
Expand All @@ -73,6 +73,26 @@ public class CameraView: UIView {
public override func layoutSubviews() {
super.layoutSubviews()
previewLayer?.frame = bounds
updateVideoOrientation()
}

private func updateVideoOrientation() {
guard let connection = previewLayer?.connection, connection.isVideoOrientationSupported else { return }

let orientation = UIDevice.current.orientation

switch orientation {
case .portrait:
connection.videoOrientation = .portrait
case .landscapeRight:
connection.videoOrientation = .landscapeLeft
case .landscapeLeft:
connection.videoOrientation = .landscapeRight
case .portraitUpsideDown:
connection.videoOrientation = .portraitUpsideDown
default:
break
}
}

deinit {
Expand Down