1using Plugin.Maui.ScreenSecurity.Handlers;
6 internal class BlurProtectionManager
8 private static UIVisualEffectView? _blurBackground =
null;
10 internal static void HandleBlurProtection(
bool enabled, ThemeStyle? style =
null, UIWindow? window =
null)
12 UIApplication.Notifications.ObserveWillResignActive((sender, args) =>
17 EnableBlurScreenProtection(window, style);
19 DisableBlurScreenProtection();
23 ErrorsHandler.HandleException(nameof(HandleBlurProtection), ex);
27 UIApplication.Notifications.ObserveDidBecomeActive((sender, args) =>
31 DisableBlurScreenProtection();
35 ErrorsHandler.HandleException(nameof(HandleBlurProtection), ex);
40 internal static void EnableBlur(UIWindow? window, ThemeStyle style)
44 EnableBlurScreenProtection(window, style);
48 ErrorsHandler.HandleException(nameof(EnableBlur), ex);
52 internal static void DisableBlur()
56 DisableBlurScreenProtection();
60 ErrorsHandler.HandleException(nameof(DisableBlur), ex);
64 private static void EnableBlurScreenProtection(UIWindow? window =
null, ThemeStyle? style =
null)
68 var blurEffectStyle = style
switch
70 ThemeStyle.Light => UIBlurEffectStyle.Light,
71 _ => UIBlurEffectStyle.Dark
74 using var blurEffect = UIBlurEffect.FromStyle(blurEffectStyle);
76 _blurBackground =
new UIVisualEffectView(blurEffect)
81 window.AddSubview(_blurBackground);
85 private static void DisableBlurScreenProtection()
87 _blurBackground?.RemoveFromSuperview();
89 _blurBackground =
null;