From 5cd60eaf29acc686623c0d64cd085781c8c2289c Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:29:55 +0100 Subject: [PATCH] PoC for allowing developers to control the defaults --- .../MauiProgram.cs | 2 ++ src/CommunityToolkit.Maui/Options.cs | 28 +++++++++++++++++++ .../Defaults/PopupDefaults.shared.cs | 3 ++ 3 files changed, 33 insertions(+) diff --git a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs index b4f7893a6a..968d7ae9a6 100644 --- a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs +++ b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs @@ -55,6 +55,8 @@ public static MauiApp CreateMauiApp() .UseMauiCommunityToolkit(static options => { options.SetShouldEnableSnackbarOnWindows(true); + + options.Defaults.Popup.SetCanBeDismissedByTappingOutsideOfPopup(false); }) #else .UseMauiCommunityToolkit(static options => diff --git a/src/CommunityToolkit.Maui/Options.cs b/src/CommunityToolkit.Maui/Options.cs index 9c70dfa891..7f48c12c7f 100644 --- a/src/CommunityToolkit.Maui/Options.cs +++ b/src/CommunityToolkit.Maui/Options.cs @@ -23,6 +23,34 @@ internal Options(in MauiAppBuilder builder) : this() internal static bool ShouldSuppressExceptionsInBehaviors { get; private set; } internal static bool ShouldEnableSnackbarOnWindows { get; private set; } + /// + /// + /// + public Default Defaults { get; } = new Default(); + + /// + /// + /// + public class Default + { + /// + /// + /// + public PopupDefault Popup { get; } = new(); + + /// + /// + /// + public class PopupDefault + { + /// + /// + /// + /// + public void SetCanBeDismissedByTappingOutsideOfPopup(bool canBeDismissedByTappingOutsideOfPopup) => PopupDefaults.CanBeDismissedByTappingOutsideOfPopup = canBeDismissedByTappingOutsideOfPopup; + } + } + /// /// Will return the default value instead of throwing an exception when using . /// diff --git a/src/CommunityToolkit.Maui/Primitives/Defaults/PopupDefaults.shared.cs b/src/CommunityToolkit.Maui/Primitives/Defaults/PopupDefaults.shared.cs index d4710f8c9b..ca51df9f96 100644 --- a/src/CommunityToolkit.Maui/Primitives/Defaults/PopupDefaults.shared.cs +++ b/src/CommunityToolkit.Maui/Primitives/Defaults/PopupDefaults.shared.cs @@ -31,4 +31,7 @@ static class PopupDefaults /// Default value for BackgroundColor /// public static Color BackgroundColor { get; } = Colors.White; + + public static bool CanBeDismissedByTappingOutsideOfPopup { get; internal set; } = + PopupDefaults.CanBeDismissedByTappingOutsideOfPopup; } \ No newline at end of file