From 6fe6d36d9226759ad54485e72eaf7426bdb67bb7 Mon Sep 17 00:00:00 2001
From: Alireza <mr.toghyiani@icloud.com>
Date: Wed, 11 Oct 2023 17:17:44 -0400
Subject: [PATCH] Avoid showing the initial loading view after welcome form

Change-Id: I0ffdc263f200fc7e6d676d5c2ec58a776314c8bf
---
 Ring/Ring/Coordinators/AppCoordinator.swift      | 16 ++++++++--------
 .../Walkthrough/WalkthroughCoordinator.swift     |  8 ++++++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/Ring/Ring/Coordinators/AppCoordinator.swift b/Ring/Ring/Coordinators/AppCoordinator.swift
index 98184ae3c..fa122d1ab 100644
--- a/Ring/Ring/Coordinators/AppCoordinator.swift
+++ b/Ring/Ring/Coordinators/AppCoordinator.swift
@@ -102,6 +102,12 @@ final class AppCoordinator: Coordinator, StateableResponsive {
         self.dispatchApplication()
     }
 
+    /// Starts the coordinator
+    func startWithoutLoading() {
+        // ~ Dispatch to the proper screen
+        self.dispatchApplication()
+    }
+
     func migrateAccount(accountId: String) {
         let migratonController = MigrateAccountViewController.instantiate(with: self.injectionBag)
         migratonController.viewModel.accountToMigrate = accountId
@@ -139,22 +145,16 @@ final class AppCoordinator: Coordinator, StateableResponsive {
         let walkthroughCoordinator = WalkthroughCoordinator(with: self.injectionBag)
         walkthroughCoordinator.isAccountFirst = isAccountFirst
         walkthroughCoordinator.withAnimations = animated
+        walkthroughCoordinator.parentCoordinator = self
         walkthroughCoordinator.start()
 
+        self.navigationController.setViewControllers([], animated: false)
         self.addChildCoordinator(childCoordinator: walkthroughCoordinator)
         let walkthroughViewController = walkthroughCoordinator.rootViewController
         self.present(viewController: walkthroughViewController,
                      withStyle: .appear,
                      withAnimation: true,
                      disposeBag: self.disposeBag)
-
-        walkthroughViewController.rx.controllerWasDismissed
-            .subscribe(onNext: { [weak self, weak walkthroughCoordinator] (_) in
-                walkthroughCoordinator?.stateSubject.dispose()
-                self?.removeChildCoordinator(childCoordinator: walkthroughCoordinator)
-                self?.dispatchApplication()
-            })
-            .disposed(by: self.disposeBag)
     }
 
     /// Presents the main interface
diff --git a/Ring/Ring/Features/Walkthrough/WalkthroughCoordinator.swift b/Ring/Ring/Features/Walkthrough/WalkthroughCoordinator.swift
index c03f3107b..8d751a658 100644
--- a/Ring/Ring/Features/Walkthrough/WalkthroughCoordinator.swift
+++ b/Ring/Ring/Features/Walkthrough/WalkthroughCoordinator.swift
@@ -75,8 +75,12 @@ class WalkthroughCoordinator: Coordinator, StateableResponsive {
                     self.showAddAccount(with: walkthroughType)
                 case .accountCreated, .deviceLinked:
                     if self.rootViewController.presentedViewController != nil {
-                        self.rootViewController.dismiss(animated: true) { [weak self] in // dismiss the pop up form modal view
-                            self?.rootViewController.dismiss(animated: true) // dismiss the welcome view and check for user account state
+                        if let appCoordinator = self.parentCoordinator as? AppCoordinator {
+                            appCoordinator.startWithoutLoading()
+                            appCoordinator.removeChildCoordinator(childCoordinator: self)
+                            rootViewController.presentedViewController?.dismiss(animated: true) {
+                                self.rootViewController.dismiss(animated: false)
+                            }
                         }
                     }
                 case .walkthroughCanceled:
-- 
GitLab