From 4d011b911634f7d045674ea7fa775a2483efcd92 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:58:14 +0000 Subject: [PATCH] Fix a bug where the Screen lock placeholder could be slow. (#2155) * Only use the Task for the delayed window changes. The timing was off with the Task when locking the device with the app open. * Check the application state before unlocking the app. On top of a), the app will reveal itself if you background during the success animation, b) the flow is run farrrr too many times, so the app is revealing itself way before the Face ID scan UI is complete - definitely need a state machine here. --- .../Application/Windowing/WindowManager.swift | 23 +++++++++++-------- .../AppLockFlowCoordinator.swift | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index 84b72d342..1bfdf3b46 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -63,10 +63,10 @@ class WindowManager { /// Shows the main and overlay window combo, hiding the alternate window. func switchToMain() { + mainWindow.isHidden = false + overlayWindow.isHidden = false + switchTask = Task { - mainWindow.isHidden = false - overlayWindow.isHidden = false - // Delay hiding to make sure the main windows are visible. try await Task.sleep(for: windowHideDelay) @@ -76,14 +76,17 @@ class WindowManager { /// Shows the alternate window, hiding the main and overlay combo. func switchToAlternate() { + alternateWindow.isHidden = false + + // We don't know what route the app will use when returning back + // to the main window, so end any editing operation now to avoid + // e.g. the keyboard being displayed on top of a call sheet. + mainWindow.endEditing(true) + + // alternateWindow.isHidden = false cannot got inside the Task otherwise the timing + // is poor when you lock the phone - you briefly see the main window for a few + // frames after you've unlocked the phone and then the placeholder animates in. switchTask = Task { - alternateWindow.isHidden = false - - // We don't know what route the app will use when returning back - // to the main window, so end any editing operation now to avoid - // e.g. the keyboard being displayed on top of a call sheet. - mainWindow.endEditing(true) - // Delay hiding to make sure the alternate window is visible. try await Task.sleep(for: windowHideDelay) diff --git a/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift index 1a6c60e34..d75dd7c05 100644 --- a/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift @@ -108,7 +108,7 @@ class AppLockFlowCoordinator: CoordinatorProtocol { if appLockService.biometricUnlockEnabled, appLockService.biometricUnlockTrusted { showPlaceholder() // For the unlock background. - if await appLockService.unlockWithBiometrics() { + if await appLockService.unlockWithBiometrics(), UIApplication.shared.applicationState == .active { actionsSubject.send(.unlockApp) return } @@ -132,6 +132,7 @@ class AppLockFlowCoordinator: CoordinatorProtocol { guard let self else { return } switch action { case .appUnlocked: + guard UIApplication.shared.applicationState == .active else { return } actionsSubject.send(.unlockApp) case .forceLogout: actionsSubject.send(.forceLogout)