diff --git a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift index 4580c6b73..fa0afe386 100644 --- a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift +++ b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift @@ -5,8 +5,7 @@ import UIKit class LockEnterPasscodeCoordinator: Coordinator { var coordinators: [Coordinator] = [] - var protectionWasShown = false - private let window: UIWindow = UIWindow() + let window: UIWindow = UIWindow() private let model: LockEnterPasscodeViewModel private let lock: LockInterface private lazy var lockEnterPasscodeViewController: LockEnterPasscodeViewController = { @@ -20,21 +19,20 @@ class LockEnterPasscodeCoordinator: Coordinator { if state { self?.stop() } - self?.protectionWasShown = bioUnlock } } func start() { - guard lock.isPasscodeSet() else { - return - } - protectionWasShown = true + guard lock.isPasscodeSet() else { return } window.rootViewController = lockEnterPasscodeViewController window.makeKeyAndVisible() - //Because of the usage of the window and rootViewController we are not able to receive properly view life circle events. So we should call this methods manually. - lockEnterPasscodeViewController.showKeyboard() - lockEnterPasscodeViewController.showBioMerickAuth() } func stop() { window.isHidden = true } + + func showAuthentication() { + guard lock.isPasscodeSet() else { return } + lockEnterPasscodeViewController.showKeyboard() + lockEnterPasscodeViewController.showBioMerickAuth() + } } diff --git a/Trust/Protection/Coordinators/ProtectionCoordinator.swift b/Trust/Protection/Coordinators/ProtectionCoordinator.swift index 6219d3026..56ecf84ef 100644 --- a/Trust/Protection/Coordinators/ProtectionCoordinator.swift +++ b/Trust/Protection/Coordinators/ProtectionCoordinator.swift @@ -19,29 +19,25 @@ class ProtectionCoordinator: Coordinator { func didFinishLaunchingWithOptions() { splashCoordinator.start() lockEnterPasscodeCoordinator.start() - } - - func applicationWillResignActive() { - splashCoordinator.start() + lockEnterPasscodeCoordinator.showAuthentication() } func applicationDidBecomeActive() { - //We track protectionWasShown because of the Touch ID that will trigger applicationDidBecomeActive method after valdiation. - if !lockEnterPasscodeCoordinator.protectionWasShown { - lockEnterPasscodeCoordinator.start() - } else { - lockEnterPasscodeCoordinator.protectionWasShown = false - } - - //We should dismiss spalsh screen when app become active. splashCoordinator.stop() } + func applicationWillResignActive() { + splashCoordinator.start() + } + func applicationDidEnterBackground() { splashCoordinator.start() + lockEnterPasscodeCoordinator.start() } func applicationWillEnterForeground() { splashCoordinator.stop() + lockEnterPasscodeCoordinator.start() + lockEnterPasscodeCoordinator.showAuthentication() } } diff --git a/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift b/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift index 38fe5db85..6aab28c78 100644 --- a/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift +++ b/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift @@ -8,26 +8,26 @@ class LockEnterPasscodeCoordinatorTest: XCTestCase { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) coordinator.start() - XCTAssertTrue(coordinator.protectionWasShown) + XCTAssertFalse(coordinator.window.isHidden) } func testStop() { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) coordinator.start() - XCTAssertTrue(coordinator.protectionWasShown) + XCTAssertFalse(coordinator.window.isHidden) coordinator.stop() + XCTAssertTrue(coordinator.window.isHidden) } func testDisableLock() { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() fakeLock.passcodeSet = false let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) coordinator.start() - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) } }