Show the lock screen placeholder on willResignActive. (#2086)

This commit is contained in:
Doug
2023-11-15 15:31:35 +00:00
committed by GitHub
parent 342feb4113
commit 0b9da83470
10 changed files with 164 additions and 65 deletions
@@ -49,15 +49,21 @@ class AppLockFlowCoordinator: CoordinatorProtocol {
// Set the initial background state.
showPlaceholder()
notificationCenter.publisher(for: UIApplication.willResignActiveNotification)
.sink { [weak self] _ in
self?.applicationWillResignActive()
}
.store(in: &cancellables)
notificationCenter.publisher(for: UIApplication.didEnterBackgroundNotification)
.sink { [weak self] _ in
self?.applicationDidEnterBackground()
}
.store(in: &cancellables)
notificationCenter.publisher(for: UIApplication.willEnterForegroundNotification)
notificationCenter.publisher(for: UIApplication.didBecomeActiveNotification)
.sink { [weak self] _ in
self?.applicationWillEnterForeground()
self?.applicationDidBecomeActive()
}
.store(in: &cancellables)
}
@@ -68,19 +74,23 @@ class AppLockFlowCoordinator: CoordinatorProtocol {
// MARK: - App unlock
private func applicationDidEnterBackground() {
private func applicationWillResignActive() {
unlockTask = nil
guard appLockService.isEnabled else { return }
appLockService.applicationDidEnterBackground()
showPlaceholder()
}
private func applicationWillEnterForeground() {
private func applicationDidEnterBackground() {
guard appLockService.isEnabled else { return }
appLockService.applicationDidEnterBackground()
showPlaceholder() // Double call but just to be safe
}
private func applicationDidBecomeActive() {
guard appLockService.isEnabled else { return }
guard appLockService.computeNeedsUnlock(willEnterForegroundAt: .now) else {
guard appLockService.computeNeedsUnlock(didBecomeActiveAt: .now) else {
// Reveal the app again if within the grace period.
actionsSubject.send(.unlockApp)
return