Skip to content

Commit

Permalink
Fix brave/brave-ios#8227: When launching the QR code scanning UI whil…
Browse files Browse the repository at this point in the history
…e in the Landscape mode, the camera view is rotated 90 degrees (brave/brave-ios#8472)
  • Loading branch information
soner-yuksel authored Nov 24, 2023
1 parent cd33b22 commit 1df4c0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class RecentSearchQRCodeScannerController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

scannerView.cameraView.stopRunning()
}

override func viewDidAppear(_ animated: Bool) {
if let orientation = view.window?.windowScene?.interfaceOrientation {
scannerView.cameraView.videoPreviewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation(ui: orientation)
}
scannerView.cameraView.startRunning()
}

Expand Down
14 changes: 11 additions & 3 deletions Sources/Brave/Frontend/Sync/SyncCameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate {
videoPreviewLayer?.frame = layer.bounds
layer.addSublayer(videoPreviewLayer!)

captureSession.startRunning()
startRunning()
bringSubviewToFront(cameraOverlayView)

AVCaptureDevice.requestAccess(
Expand All @@ -143,11 +143,19 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate {
}

func startRunning() {
captureSession?.startRunning()
DispatchQueue.global(qos: .default).async { [weak self] in
guard let self else { return }

if self.captureSession?.isRunning == false {
self.captureSession?.startRunning()
}
}
}

func stopRunning() {
captureSession?.stopRunning()
if captureSession?.isRunning == true {
captureSession?.stopRunning()
}
}

func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
Expand Down

0 comments on commit 1df4c0e

Please sign in to comment.