From 83ecc3142eb3993a1069ba2f4375d3cce73a0003 Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Mon, 26 Aug 2024 16:30:08 +0300 Subject: [PATCH] Fix broken QR code scanner and fix landscape mode Changelog-Fixed: Fix broken QR code scanner and fix landscape mode --- .../CodeScanner/ScannerViewController.swift | 34 ++++++++----------- damus/Views/QRCodeView.swift | 19 ++++++----- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/damus/Views/CodeScanner/ScannerViewController.swift b/damus/Views/CodeScanner/ScannerViewController.swift index 53fd7940..c37b8e57 100644 --- a/damus/Views/CodeScanner/ScannerViewController.swift +++ b/damus/Views/CodeScanner/ScannerViewController.swift @@ -182,25 +182,6 @@ extension CodeScannerView { delegate?.didFail(reason: .badOutput) return } - } - - override public func viewWillLayoutSubviews() { - previewLayer?.frame = view.layer.bounds - } - - @objc func updateOrientation() { - guard let orientation = view.window?.windowScene?.interfaceOrientation else { return } - guard let connection = captureSession.connections.last, connection.isVideoOrientationSupported else { return } - connection.videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue) ?? .portrait - } - - override public func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - updateOrientation() - } - - override public func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) if previewLayer == nil { previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) @@ -220,6 +201,21 @@ extension CodeScannerView { } } + override public func viewWillLayoutSubviews() { + previewLayer?.frame = view.layer.bounds + } + + @objc func updateOrientation() { + guard let orientation = view.window?.windowScene?.interfaceOrientation else { return } + guard let connection = captureSession.connections.last, connection.isVideoOrientationSupported else { return } + connection.videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue) ?? .portrait + } + + override public func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + updateOrientation() + } + private func addviewfinder() { guard showViewfinder, let imageView = viewFinder else { return } diff --git a/damus/Views/QRCodeView.swift b/damus/Views/QRCodeView.swift index 7010d78e..e0c91700 100644 --- a/damus/Views/QRCodeView.swift +++ b/damus/Views/QRCodeView.swift @@ -126,11 +126,11 @@ struct QRCodeView: View { if our_profile?.picture != nil { ProfilePicView(pubkey: pubkey, size: 90.0, highlight: .custom(DamusColors.white, 3.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) - .padding(.top, 50) + .padding(.top, 20) } else { Image(systemName: "person.fill") .font(.system(size: 60)) - .padding(.top, 50) + .padding(.top, 20) } if let display_name = profile?.display_name { @@ -150,17 +150,18 @@ struct QRCodeView: View { .interpolation(.none) .resizable() .scaledToFit() - .frame(width: 300, height: 300) + .frame(minWidth: 100, maxWidth: 300, minHeight: 100, maxHeight: 300) .cornerRadius(10) .overlay(RoundedRectangle(cornerRadius: 10) - .stroke(DamusColors.white, lineWidth: 5.0)) + .stroke(DamusColors.white, lineWidth: 5.0) + .scaledToFit()) .shadow(radius: 10) Spacer() Text("Follow me on Nostr", comment: "Text on QR code view to prompt viewer looking at screen to follow the user.") .font(.system(size: 24, weight: .heavy)) - .padding(.top) + .padding(.top, 10) .foregroundColor(.white) Text("Scan the code", comment: "Text on QR code view to prompt viewer to scan the QR code on screen with their device camera.") @@ -179,7 +180,7 @@ struct QRCodeView: View { .frame(minWidth: 300, maxWidth: .infinity, maxHeight: 12, alignment: .center) } .buttonStyle(GradientButtonStyle()) - .padding(50) + .padding(20) } } @@ -201,11 +202,11 @@ struct QRCodeView: View { } } .scaledToFit() - .frame(width: 300, height: 300) + .frame(maxWidth: 300, maxHeight: 300) .cornerRadius(10) - .overlay(RoundedRectangle(cornerRadius: 10).stroke(DamusColors.white, lineWidth: 5.0)) + .overlay(RoundedRectangle(cornerRadius: 10).stroke(DamusColors.white, lineWidth: 5.0).scaledToFit()) .overlay(RoundedRectangle(cornerRadius: 10).trim(from: 0.0, to: outerTrimEnd).stroke(DamusColors.black, lineWidth: 5.5) - .rotationEffect(.degrees(-90))) + .rotationEffect(.degrees(-90)).scaledToFit()) .shadow(radius: 10) Spacer()