From 93406c3f3312840d158931ca8acb246b592df028 Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Fri, 24 Nov 2023 16:41:57 -0500 Subject: [PATCH] Fix #8227: When launching the QR code scanning UI while in the Landscape mode, the camera view is rotated 90 degrees (#8472) --- .../RecentSearchQRCodeScannerController.swift | 7 +++++++ Sources/Brave/Frontend/Sync/SyncCameraView.swift | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift b/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift index 9be33947cce..979c479be49 100644 --- a/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift +++ b/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift @@ -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() } diff --git a/Sources/Brave/Frontend/Sync/SyncCameraView.swift b/Sources/Brave/Frontend/Sync/SyncCameraView.swift index bc152f9019c..4b5bb98f540 100644 --- a/Sources/Brave/Frontend/Sync/SyncCameraView.swift +++ b/Sources/Brave/Frontend/Sync/SyncCameraView.swift @@ -124,7 +124,7 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate { videoPreviewLayer?.frame = layer.bounds layer.addSublayer(videoPreviewLayer!) - captureSession.startRunning() + startRunning() bringSubviewToFront(cameraOverlayView) AVCaptureDevice.requestAccess( @@ -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) {