@@ -13,6 +13,13 @@ class SignInWithQRViewController: UIViewController {
1313 // Scan QR Code
1414 @IBOutlet weak var scanButton : UIButton !
1515
16+ // Sign In Manually
17+ @IBOutlet weak var signInManuallyButton : UIButton !
18+
19+ // Other components
20+ @IBOutlet weak var lineView : UIView !
21+ @IBOutlet weak var orLabel : UILabel !
22+
1623 // Footnote
1724 @IBOutlet weak var versionLabel : UILabel ! {
1825 didSet {
@@ -32,6 +39,20 @@ class SignInWithQRViewController: UIViewController {
3239 }
3340 }
3441
42+ override func prepare( for segue: UIStoryboardSegue , sender: Any ? ) {
43+ switch segue. identifier {
44+ case " scanQR " :
45+ guard let qrCodeVC = segue. destination. children. first as? QRCodeViewController else { return }
46+ qrCodeVC. delegate = self
47+ if #available( iOS 13 . 0 , * ) { qrCodeVC. isModalInPresentation = true }
48+ case " manual " :
49+ guard let signInVC = segue. destination. children. first as? SignInManuallyViewController else { return }
50+ signInVC. delegate = self
51+ if #available( iOS 13 . 0 , * ) { signInVC. isModalInPresentation = true }
52+ default : return
53+ }
54+ }
55+
3556 func startLoading( ) {
3657 self . activityIndicator. center = self . view. center
3758 self . activityIndicator. hidesWhenStopped = true
@@ -48,13 +69,24 @@ class SignInWithQRViewController: UIViewController {
4869 }
4970
5071 func resetButtonUI( ) {
72+ let animator = UIViewPropertyAnimator ( duration: 0.3 , curve: . easeOut) {
73+ self . lineView. isHidden = false
74+ self . orLabel. isHidden = false
75+ self . signInManuallyButton. isHidden = false
76+ }
77+ animator. startAnimation ( )
78+
5179 self . scanButton. setTitleColor ( UIColor ( red: 1 , green: 1 , blue: 1 , alpha: 0.88 ) , for: . normal)
5280 self . scanButton. backgroundColor = UIColor ( red: 123 / 255 , green: 83 / 255 , blue: 239 / 255 , alpha: 1.0 )
53- self . scanButton. setTitle ( " Scan QR Code " , for: . normal)
81+ self . scanButton. setTitle ( " Sign in with QR code " , for: . normal)
5482 self . scanButton. isEnabled = true
5583 }
5684
5785 func updateButtonUI( ) {
86+ self . lineView. isHidden = true
87+ self . orLabel. isHidden = true
88+ self . signInManuallyButton. isHidden = true
89+
5890 self . scanButton. backgroundColor = UIColor ( red: 240 / 255 , green: 240 / 255 , blue: 240 / 255 , alpha: 1.0 )
5991 self . scanButton. setTitleColor ( UIColor ( red: 0 , green: 0 , blue: 0 , alpha: 0.12 ) , for: . normal)
6092 self . scanButton. setTitle ( " Signing In... " , for: . normal)
@@ -63,19 +95,17 @@ class SignInWithQRViewController: UIViewController {
6395}
6496
6597// MARK: - QR Code
66- extension SignInWithQRViewController : QRCodeScanDelegate {
67-
68- override func prepare( for segue: UIStoryboardSegue , sender: Any ? ) {
69- guard segue. identifier == " scanQR " , let QRCodeVC = segue. destination. children. first as? QRCodeViewController else { return }
70- QRCodeVC . delegate = self
71- }
72-
98+ extension SignInWithQRViewController : SignInDelegate {
7399 @IBAction func didTapScanQRCode( ) {
74100 performSegue ( withIdentifier: " scanQR " , sender: nil )
75101 }
76102
103+ @IBAction func didTapSignInManually( ) {
104+ performSegue ( withIdentifier: " manual " , sender: nil )
105+ }
106+
77107 // Delegate method
78- func didScanQRCode ( appId: String , userId: String , accessToken: String ? ) {
108+ func didSignIn ( appId: String , userId: String , accessToken: String ? ) {
79109 SendBirdCall . configure ( appId: appId)
80110
81111 UserDefaults . standard. appId = appId
@@ -107,6 +137,7 @@ extension SignInWithQRViewController {
107137 let errorDescription = String ( error? . localizedDescription ?? " " )
108138 self . presentErrorAlert ( message: " Failed to authenticate \n \( errorDescription) " )
109139 }
140+ UserDefaults . standard. clear ( )
110141 return
111142 }
112143 UserDefaults . standard. autoLogin = true
0 commit comments