2022-11-25 14:31:37 +00:00
|
|
|
//
|
|
|
|
// AppSheet.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by Evgeny on 24/11/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-08-09 14:43:42 +04:00
|
|
|
class AppSheetState: ObservableObject {
|
|
|
|
static let shared = AppSheetState()
|
|
|
|
@Published var scenePhaseActive: Bool = false
|
2024-10-16 21:55:59 +03:00
|
|
|
|
|
|
|
func redactionReasons(_ protectScreen: Bool) -> RedactionReasons {
|
|
|
|
!protectScreen || scenePhaseActive
|
|
|
|
? RedactionReasons()
|
|
|
|
: RedactionReasons.placeholder
|
|
|
|
}
|
2024-08-09 14:43:42 +04:00
|
|
|
}
|
|
|
|
|
2022-11-25 14:31:37 +00:00
|
|
|
private struct PrivacySensitive: ViewModifier {
|
2023-01-11 17:09:17 +00:00
|
|
|
@AppStorage(DEFAULT_PRIVACY_PROTECT_SCREEN) private var protectScreen = false
|
2024-08-09 14:43:42 +04:00
|
|
|
// 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
|
2022-11-25 14:31:37 +00:00
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
2024-10-16 21:55:59 +03:00
|
|
|
content.redacted(reason: appSheetState.redactionReasons(protectScreen))
|
2022-11-25 14:31:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension View {
|
|
|
|
func appSheet<Content>(
|
|
|
|
isPresented: Binding<Bool>,
|
|
|
|
onDismiss: (() -> Void)? = nil,
|
|
|
|
content: @escaping () -> Content
|
|
|
|
) -> some View where Content: View {
|
2024-08-09 02:12:55 +09:00
|
|
|
sheet(isPresented: isPresented, onDismiss: onDismiss) {
|
|
|
|
content().modifier(PrivacySensitive())
|
|
|
|
}
|
2022-11-25 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func appSheet<T, Content>(
|
|
|
|
item: Binding<T?>,
|
|
|
|
onDismiss: (() -> Void)? = nil,
|
|
|
|
content: @escaping (T) -> Content
|
|
|
|
) -> some View where T: Identifiable, Content: View {
|
2024-08-09 02:12:55 +09:00
|
|
|
sheet(item: item, onDismiss: onDismiss) { it in
|
|
|
|
content(it).modifier(PrivacySensitive())
|
|
|
|
}
|
2022-11-25 14:31:37 +00:00
|
|
|
}
|
|
|
|
}
|