nayooti 5 éve
szülő
commit
7ef26b1580

+ 38 - 38
deltachat-ios/Controller/WelcomeViewController.swift

@@ -40,7 +40,6 @@ class WelcomeViewController: UIViewController {
         return nav
     }()
 
-    // will be shown while transitioning to tabBarController
     private var activityIndicator: UIActivityIndicatorView = {
         let view: UIActivityIndicatorView
         if #available(iOS 13, *) {
@@ -104,28 +103,30 @@ class WelcomeViewController: UIViewController {
         contentGuide.trailingAnchor.constraint(equalTo: welcomeView.trailingAnchor).isActive = true
         contentGuide.bottomAnchor.constraint(equalTo: welcomeView.bottomAnchor).isActive = true
 
+        // this enables vertical scrolling
         frameGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor).isActive = true
     }
 
-    func setTransitionState(_ transitioning: Bool) {
-        if transitioning {
+    /// if active the welcomeViewController will show nothing but a centered activity indicator
+    func activateSpinner(_ active: Bool) {
+        if active {
             activityIndicator.startAnimating()
         } else {
             activityIndicator.stopAnimating()
         }
-        activityIndicator.isHidden = !transitioning
-        scrollView.isHidden = transitioning
+        activityIndicator.isHidden = !active
+        scrollView.isHidden = active
     }
 
     // MARK: - actions
 
-    func showQRReader(completion onComplete: VoidFunction? = nil) {
+    private func showQRReader(completion onComplete: VoidFunction? = nil) {
         present(qrCodeReaderNav, animated: true) {
             onComplete?()
         }
     }
 
-    func createAccountFromQRCode() {
+    private func createAccountFromQRCode() {
         guard let code = scannedQrCode else {
             return
         }
@@ -137,6 +138,35 @@ class WelcomeViewController: UIViewController {
             accountCreationErrorAlert()
         }
     }
+
+    private func accountCreationErrorAlert() {
+        func handleRepeat() {
+            showQRReader(completion: { [unowned self] in
+                self.activateSpinner(false)
+            })
+        }
+
+        let title = String.localized("error") // TODO: replace with more precise error message when available
+        let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
+        let okAction = UIAlertAction(
+            title: String.localized("ok"),
+            style: .default,
+            handler: { [unowned self] _ in
+                self.activateSpinner(false)
+            }
+        )
+
+        let repeatAction = UIAlertAction(
+            title: String.localized("global_menu_edit_redo_desktop"),
+            style: .default,
+            handler: { _ in
+                handleRepeat()
+            }
+        )
+        alert.addAction(okAction)
+        alert.addAction(repeatAction)
+        present(alert, animated: true)
+    }
 }
 
 extension WelcomeViewController: QrCodeReaderDelegate {
@@ -158,7 +188,7 @@ extension WelcomeViewController: QrCodeReaderDelegate {
             title: String.localized("ok"),
             style: .default,
             handler: { [unowned self] _ in
-                self.setTransitionState(true)
+                self.activateSpinner(true)
                 self.qrCodeReaderNav.dismiss(animated: true) {
                     self.createAccountFromQRCode()
                 }
@@ -199,40 +229,10 @@ extension WelcomeViewController: QrCodeReaderDelegate {
                  }
              }
          )
-
         alert.addAction(okAction)
         alert.addAction(qrCancelAction)
         qrCodeReaderNav.present(alert, animated: true, completion: nil)
     }
-
-    private func accountCreationErrorAlert() {
-        func handleRepeat() {
-            showQRReader(completion: { [unowned self] in
-                self.setTransitionState(false)
-            })
-        }
-
-        let title = String.localized("error") // TODO: replace with more precise error message when available
-        let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
-        let okAction = UIAlertAction(
-            title: String.localized("ok"),
-            style: .default,
-            handler: { [unowned self] _ in
-                self.setTransitionState(false)
-            }
-        )
-
-        let repeatAction = UIAlertAction(
-            title: String.localized("global_menu_edit_redo_desktop"),
-            style: .default,
-            handler: { _ in
-                handleRepeat()
-            }
-        )
-        alert.addAction(okAction)
-        alert.addAction(repeatAction)
-        present(alert, animated: true)
-    }
 }
 
 class WelcomeContentView: UIView {

+ 4 - 4
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -132,10 +132,10 @@ class AppCoordinator: NSObject, Coordinator {
 
     func presentWelcomeController(animated: Bool) {
         if animated {
-            welcomeController.setTransitionState(true)
+            welcomeController.activateSpinner(true)
             showWelcomeController()
             DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-                self.welcomeController.setTransitionState(false)
+                self.welcomeController.activateSpinner(false)
             }
         } else {
             showWelcomeController()
@@ -176,11 +176,11 @@ extension AppCoordinator: WelcomeCoordinator {
     
 
     func handleLoginSuccess() {
-        welcomeController.setTransitionState(true) // this will hide welcomeController's content
+        welcomeController.activateSpinner(true) // this will hide welcomeController's content
         DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
             self.loginController.dismiss(animated: true) { // this is ignored if loginController is not shown
                 self.presentTabBarController()
-                self.welcomeController.setTransitionState(false)
+                self.welcomeController.activateSpinner(false)
             }
         }
     }