From 42d7c20a4795c3c72bcaa5997d119bdb87fc84e7 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:43:42 +0400 Subject: [PATCH] ios: fix appSheet screen protection for ios 16 (#4635) * ios: fix app sheet screen protection for ios 16 * comment --- apps/ios/Shared/SimpleXApp.swift | 1 + apps/ios/Shared/Views/Helpers/AppSheet.swift | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 34c66d6705..ae539d7298 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -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 diff --git a/apps/ios/Shared/Views/Helpers/AppSheet.swift b/apps/ios/Shared/Views/Helpers/AppSheet.swift index 9e699598e7..0ade1c0d8e 100644 --- a/apps/ios/Shared/Views/Helpers/AppSheet.swift +++ b/apps/ios/Shared/Views/Helpers/AppSheet.swift @@ -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) } } }