mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			75 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			75 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
| 
											6 years ago
										 | 
 | ||
| 
											6 years ago
										 | final class ScanQRCodeWrapperVC : BaseVC { | ||
| 
											6 years ago
										 |     var delegate: (UIViewController & OWSQRScannerDelegate)? = nil | ||
| 
											6 years ago
										 |     var isPresentedModally = false | ||
| 
											6 years ago
										 |     private let message: String | ||
| 
											6 years ago
										 |     private let scanQRCodeVC = OWSQRCodeScanningViewController() | ||
|  |      | ||
|  |     // MARK: Settings | ||
|  |     override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait } | ||
|  |      | ||
|  |     // MARK: Lifecycle | ||
| 
											6 years ago
										 |     init(message: String) { | ||
|  |         self.message = message | ||
|  |         super.init(nibName: nil, bundle: nil) | ||
|  |     } | ||
|  |      | ||
|  |     required init?(coder: NSCoder) { | ||
| 
											6 years ago
										 |         preconditionFailure("Use init(message:) instead.") | ||
| 
											6 years ago
										 |     } | ||
|  |      | ||
|  |     override init(nibName: String?, bundle: Bundle?) { | ||
| 
											6 years ago
										 |         preconditionFailure("Use init(message:) instead.") | ||
| 
											6 years ago
										 |     } | ||
|  |      | ||
| 
											6 years ago
										 |     override func viewDidLoad() { | ||
| 
											6 years ago
										 |         super.viewDidLoad() | ||
| 
											6 years ago
										 |         // Set up navigation bar if needed | ||
| 
											6 years ago
										 |         if isPresentedModally { | ||
| 
											6 years ago
										 |             navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close)) | ||
| 
											6 years ago
										 |         } | ||
| 
											6 years ago
										 |         setUpGradientBackground() | ||
| 
											6 years ago
										 |         // Set up scan QR code VC | ||
| 
											6 years ago
										 |         scanQRCodeVC.scanDelegate = delegate | ||
|  |         let scanQRCodeVCView = scanQRCodeVC.view! | ||
|  |         view.addSubview(scanQRCodeVCView) | ||
|  |         scanQRCodeVCView.pin(.leading, to: .leading, of: view) | ||
|  |         scanQRCodeVCView.pin(.trailing, to: .trailing, of: view) | ||
| 
											5 years ago
										 |         scanQRCodeVCView.autoPinEdge(.top, to: .top, of: view) | ||
| 
											6 years ago
										 |         scanQRCodeVCView.autoPinToSquareAspectRatio() | ||
| 
											6 years ago
										 |         // Set up bottom view | ||
| 
											6 years ago
										 |         let bottomView = UIView() | ||
|  |         view.addSubview(bottomView) | ||
|  |         bottomView.pin(.top, to: .bottom, of: scanQRCodeVCView) | ||
|  |         bottomView.pin(.leading, to: .leading, of: view) | ||
|  |         bottomView.pin(.trailing, to: .trailing, of: view) | ||
|  |         bottomView.pin(.bottom, to: .bottom, of: view) | ||
| 
											6 years ago
										 |         // Set up explanation label | ||
| 
											6 years ago
										 |         let explanationLabel = UILabel() | ||
| 
											6 years ago
										 |         explanationLabel.text = message | ||
| 
											6 years ago
										 |         explanationLabel.textColor = Colors.text | ||
|  |         explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) | ||
| 
											6 years ago
										 |         explanationLabel.numberOfLines = 0 | ||
|  |         explanationLabel.lineBreakMode = .byWordWrapping | ||
|  |         explanationLabel.textAlignment = .center | ||
|  |         bottomView.addSubview(explanationLabel) | ||
|  |         explanationLabel.autoPinWidthToSuperview(withMargin: 32) | ||
|  |         explanationLabel.autoPinHeightToSuperview(withMargin: 32) | ||
|  |         // Title | ||
|  |         title = NSLocalizedString("Scan QR Code", comment: "") | ||
|  |     } | ||
|  |      | ||
|  |     override func viewDidAppear(_ animated: Bool) { | ||
|  |         super.viewDidAppear(animated) | ||
|  |         UIDevice.current.ows_setOrientation(.portrait) | ||
|  |         DispatchQueue.main.async { [weak self] in | ||
|  |             self?.scanQRCodeVC.startCapture() | ||
|  |         } | ||
|  |     } | ||
| 
											6 years ago
										 |      | ||
|  |     // MARK: Interaction | ||
| 
											6 years ago
										 |     @objc private func close() { | ||
| 
											6 years ago
										 |         presentingViewController?.dismiss(animated: true, completion: nil) | ||
|  |     } | ||
| 
											6 years ago
										 | } |