mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-16 04:16:39 -05:00
33 lines
1013 B
Swift
33 lines
1013 B
Swift
import SwiftUI
|
|
|
|
public struct ScreenCaptureProtectionModifier: ViewModifier {
|
|
private let blurRadius: CGFloat
|
|
@State private var isScreenCaptured = false
|
|
|
|
public init(blurRadius: CGFloat = 8) {
|
|
self.blurRadius = blurRadius
|
|
}
|
|
|
|
public func body(content: Content) -> some View {
|
|
#if !os(watchOS) && !os(macOS)
|
|
content
|
|
.blur(radius: isScreenCaptured ? blurRadius : 0)
|
|
.animation(.easeInOut(duration: 0.2), value: isScreenCaptured)
|
|
.onAppear {
|
|
isScreenCaptured = UIScreen.main.isCaptured
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: UIScreen.capturedDidChangeNotification)) { _ in
|
|
isScreenCaptured = UIScreen.main.isCaptured
|
|
}
|
|
#else
|
|
content
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public extension View {
|
|
func screenCaptureProtected(blurRadius: CGFloat = 16) -> some View {
|
|
modifier(ScreenCaptureProtectionModifier(blurRadius: blurRadius))
|
|
}
|
|
}
|