Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8227: When launching the QR code scanning UI while in the Landscape mode, the camera view is rotated 90 degrees #8472

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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