mirror of https://github.com/oxen-io/session-ios
Merge pull request #66 from loki-project/multi-device-qr-code-scanning
Multi Device QR Code Scanningpull/67/head
commit
baf4150f6e
@ -1,12 +0,0 @@
|
||||
#import <SignalMessaging/OWSViewController.h>
|
||||
#import "OWSQRCodeScanningViewController.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ScanQRCodeVC : OWSViewController
|
||||
|
||||
@property (nonatomic, weak) UIViewController<OWSQRScannerDelegate> *delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,62 +0,0 @@
|
||||
#import "ScanQRCodeVC.h"
|
||||
#import "Session-Swift.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ScanQRCodeVC ()
|
||||
|
||||
@property (nonatomic) OWSQRCodeScanningViewController *qrCodeScanningVC;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ScanQRCodeVC
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
// Background color
|
||||
self.view.backgroundColor = Theme.backgroundColor;
|
||||
// QR code scanning VC
|
||||
self.qrCodeScanningVC = [OWSQRCodeScanningViewController new];
|
||||
self.qrCodeScanningVC.scanDelegate = self.delegate;
|
||||
[self.view addSubview:self.qrCodeScanningVC.view];
|
||||
[self.qrCodeScanningVC.view autoPinEdgeToSuperviewEdge:ALEdgeLeading];
|
||||
[self.qrCodeScanningVC.view autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
|
||||
[self.qrCodeScanningVC.view autoPinToTopLayoutGuideOfViewController:self withInset:0.0];
|
||||
[self.qrCodeScanningVC.view autoPinToSquareAspectRatio];
|
||||
// Explanation label
|
||||
UILabel *explanationLabel = [UILabel new];
|
||||
explanationLabel.text = NSLocalizedString(@"Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", @"");
|
||||
explanationLabel.textColor = Theme.primaryColor;
|
||||
explanationLabel.font = UIFont.ows_dynamicTypeSubheadlineClampedFont;
|
||||
explanationLabel.numberOfLines = 0;
|
||||
explanationLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
explanationLabel.textAlignment = NSTextAlignmentCenter;
|
||||
// Bottom view
|
||||
UIView *bottomView = [UIView new];
|
||||
[self.view addSubview:bottomView];
|
||||
[bottomView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.qrCodeScanningVC.view];
|
||||
[bottomView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
|
||||
[bottomView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
|
||||
[bottomView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
|
||||
[bottomView addSubview:explanationLabel];
|
||||
[explanationLabel autoPinWidthToSuperviewWithMargin:32];
|
||||
[explanationLabel autoPinHeightToSuperviewWithMargin:32];
|
||||
// Title
|
||||
self.title = NSLocalizedString(@"Scan QR Code", "");
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
[super viewDidAppear:animated];
|
||||
[UIDevice.currentDevice ows_setOrientation:UIInterfaceOrientationPortrait];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.qrCodeScanningVC startCapture];
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,74 @@
|
||||
|
||||
final class ScanQRCodeWrapperVC : UIViewController {
|
||||
var delegate: (UIViewController & OWSQRScannerDelegate)? = nil
|
||||
var isPresentedModally = false
|
||||
private let message: String
|
||||
private let scanQRCodeVC = OWSQRCodeScanningViewController()
|
||||
|
||||
// MARK: Settings
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait }
|
||||
|
||||
// MARK: Lifecycle
|
||||
init(message: String) {
|
||||
self.message = message
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
preconditionFailure("Use init(title:) instead.")
|
||||
}
|
||||
|
||||
override init(nibName: String?, bundle: Bundle?) {
|
||||
preconditionFailure("Use init(title:) instead.")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
// Navigation bar
|
||||
if isPresentedModally {
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(objc_dismiss))
|
||||
}
|
||||
// Background color
|
||||
view.backgroundColor = Theme.backgroundColor
|
||||
// Scan QR code VC
|
||||
scanQRCodeVC.scanDelegate = delegate
|
||||
let scanQRCodeVCView = scanQRCodeVC.view!
|
||||
view.addSubview(scanQRCodeVCView)
|
||||
scanQRCodeVCView.pin(.leading, to: .leading, of: view)
|
||||
scanQRCodeVCView.pin(.trailing, to: .trailing, of: view)
|
||||
scanQRCodeVCView.autoPin(toTopLayoutGuideOf: self, withInset: 0)
|
||||
scanQRCodeVCView.autoPinToSquareAspectRatio()
|
||||
// Bottom view
|
||||
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)
|
||||
// Explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.text = message
|
||||
explanationLabel.textColor = Theme.primaryColor
|
||||
explanationLabel.font = .ows_dynamicTypeSubheadlineClamped
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func objc_dismiss() {
|
||||
presentingViewController?.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue