Fix PrivacyOverlayView via NotificationCenter instead of using the .onChange handler (#13)

This commit is contained in:
Nick Klockenga 2026-04-02 22:39:32 -04:00 committed by GitHub
parent fe6cab4bb0
commit 280f086012
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@ struct ContentView: View {
@Environment(\.scenePhase) private var scenePhase
@Environment(\.modelContext) private var modelContext
@State private var lockVM = AppLockViewModel()
@State private var showPrivacyScreen = false
private var hasActiveWallet: Bool {
wallets.contains { $0.isActive }
@ -41,9 +42,8 @@ struct ContentView: View {
}
// Privacy screen hides content in app switcher when app lock is enabled
if appLockEnabled, scenePhase == .inactive, !shouldShowLock {
if showPrivacyScreen, !shouldShowLock {
PrivacyOverlayView()
.transition(.opacity)
}
}
.onAppear {
@ -74,6 +74,7 @@ struct ContentView: View {
}
case .active:
logger.info("Scene phase: active")
showPrivacyScreen = false
if appLockEnabled {
lockVM.handleForeground(timeout: lockTimeout)
}
@ -83,6 +84,11 @@ struct ContentView: View {
break
}
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
if appLockEnabled {
showPrivacyScreen = true
}
}
}
}