Skip to content

Commit

Permalink
Fix #5888 - QR code frame is not aligned (#5922)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusadogru authored and garvankeeley committed Dec 18, 2019
1 parent e978760 commit 70ed7e4
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions Client/Frontend/Browser/QRCodeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ class QRCodeViewController: UIViewController {
private var isLightOn: Bool = false
private var shapeLayer = CAShapeLayer()

private var scanRange: CGRect {
let size = UIDevice.current.userInterfaceIdiom == .pad ?
CGSize(width: view.frame.width / 2, height: view.frame.width / 2) :
CGSize(width: view.frame.width / 3 * 2, height: view.frame.width / 3 * 2)
var rect = CGRect(size: size)
rect.center = UIScreen.main.bounds.center
return rect
}

private var scanBorderHeight: CGFloat {
return UIDevice.current.userInterfaceIdiom == .pad ?
view.frame.width / 2 : view.frame.width / 3 * 2
}

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -104,20 +90,29 @@ class QRCodeViewController: UIViewController {
self.view.addSubview(instructionsLabel)

setupConstraints()
let rectPath = UIBezierPath(rect: UIScreen.main.bounds)
rectPath.append(UIBezierPath(rect: scanRange).reversing())
shapeLayer.path = rectPath.cgPath
maskView.layer.mask = shapeLayer

isAnimationing = true
startScanLineAnimation()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
applyShapeLayer()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.captureSession.stopRunning()
stopScanLineAnimation()
}

private func applyShapeLayer() {
view.layoutIfNeeded()
shapeLayer.removeFromSuperlayer()
let rectPath = UIBezierPath(rect: view.bounds)
rectPath.append(UIBezierPath(rect: scanBorder.frame).reversing())
shapeLayer.path = rectPath.cgPath
maskView.layer.mask = shapeLayer
}

private func setupConstraints() {
maskView.snp.makeConstraints { (make) in
Expand Down Expand Up @@ -155,7 +150,7 @@ class QRCodeViewController: UIViewController {
self.view.setNeedsLayout()
UIView.animate(withDuration: 2.4, animations: {
self.scanLine.snp.updateConstraints({ (make) in
make.top.equalTo(self.scanBorder.snp.top).offset(self.scanBorderHeight - 6)
make.top.equalTo(self.scanBorder.snp.top).offset(self.scanBorder.frame.size.height - 6)
})
self.view.layoutIfNeeded()
}) { (value: Bool) in
Expand Down Expand Up @@ -231,11 +226,7 @@ class QRCodeViewController: UIViewController {
}

override func willAnimateRotation(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
shapeLayer.removeFromSuperlayer()
let rectPath = UIBezierPath(rect: UIScreen.main.bounds)
rectPath.append(UIBezierPath(rect: scanRange).reversing())
shapeLayer.path = rectPath.cgPath
maskView.layer.mask = shapeLayer
applyShapeLayer()

guard let videoPreviewLayer = self.videoPreviewLayer else {
return
Expand Down

0 comments on commit 70ed7e4

Please sign in to comment.