ios: fix appSheet screen protection for ios 16 (#4635)

* ios: fix app sheet screen protection for ios 16

* comment
This commit is contained in:
spaced4ndy
2024-08-09 14:43:42 +04:00
committed by GitHub
parent cf8fd2ea11
commit 42d7c20a47
2 changed files with 9 additions and 2 deletions
+1
View File
@@ -58,6 +58,7 @@ struct SimpleXApp: App {
}
.onChange(of: scenePhase) { phase in
logger.debug("scenePhase was \(String(describing: scenePhase)), now \(String(describing: phase))")
AppSheetState.shared.scenePhaseActive = phase == .active
switch (phase) {
case .background:
// --- authentication
+8 -2
View File
@@ -8,15 +8,21 @@
import SwiftUI
class AppSheetState: ObservableObject {
static let shared = AppSheetState()
@Published var scenePhaseActive: Bool = false
}
private struct PrivacySensitive: ViewModifier {
@AppStorage(DEFAULT_PRIVACY_PROTECT_SCREEN) private var protectScreen = false
@Environment(\.scenePhase) var scenePhase
// Screen protection doesn't work for appSheet on iOS 16 if @Environment(\.scenePhase) is used instead of global state
@ObservedObject var appSheetState: AppSheetState = AppSheetState.shared
func body(content: Content) -> some View {
if !protectScreen {
content
} else {
content.privacySensitive(scenePhase != .active).redacted(reason: .privacy)
content.privacySensitive(!appSheetState.scenePhaseActive).redacted(reason: .privacy)
}
}
}