Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
553d284
Add `Popup.CanBeDismissedByTappingOutsideOfPopup`
TheCodeTraveler Jun 20, 2025
913ab04
Add GetCanBeDismissedByTappingOutsideOfPopup()
TheCodeTraveler Jun 20, 2025
546a15c
Add PopupDefaults Test
TheCodeTraveler Jun 20, 2025
cd25d0f
Add `DefaultPopupSettings()`
TheCodeTraveler Jun 20, 2025
186aa68
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jun 20, 2025
7bee4c8
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jun 20, 2025
4b37b71
Add `DefaultPopupSettings` and `DefaultPopupOptionsSettings`
TheCodeTraveler Jun 20, 2025
bcc716d
Add Unit Tests
TheCodeTraveler Jun 20, 2025
126bab4
Update Unit Tests
TheCodeTraveler Jun 20, 2025
926cd45
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jun 20, 2025
e0470af
Update DefaultPopupSettingsTests.cs
TheCodeTraveler Jun 20, 2025
fda9b55
Update PopupExtensionsTests.cs
TheCodeTraveler Jun 21, 2025
49b7ffd
Move `PopupDefaults` and `PopupOptionsDefaults` to private nested class
TheCodeTraveler Jun 22, 2025
cac47b4
Update PopupExtensionsTests.cs
TheCodeTraveler Jun 22, 2025
cce29a1
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jun 22, 2025
d872384
Resolve Merge Conflicts
TheCodeTraveler Jun 22, 2025
3900df1
Update XML docs
TheCodeTraveler Jun 22, 2025
71429ab
Fix XML
TheCodeTraveler Jun 22, 2025
6e86f84
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jul 1, 2025
52fba1a
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jul 3, 2025
a6ff45d
Merge branch 'main' into Add-Popup-Defaults-to-AppBuilderExtensions
TheCodeTraveler Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public static MauiApp CreateMauiApp()
.UseMauiCommunityToolkit(static options =>
{
options.SetShouldEnableSnackbarOnWindows(true);
options.SetPopupDefaults(new DefaultPopupSettings());
options.SetPopupOptionsDefaults(new DefaultPopupOptionsSettings());
})
#else
.UseMauiCommunityToolkit(static options =>
Expand Down
2 changes: 2 additions & 0 deletions src/CommunityToolkit.Maui.UnitTests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ protected virtual void Dispose(bool isDisposing)
options.SetShouldSuppressExceptionsInAnimations(false);
options.SetShouldSuppressExceptionsInBehaviors(false);
options.SetShouldSuppressExceptionsInConverters(false);
options.SetPopupDefaults(new DefaultPopupSettings());
options.SetPopupOptionsDefaults(new DefaultPopupOptionsSettings());

// Restore default MediaElementOptions
var mediaElementOptions = new MediaElementOptions();
Expand Down
1 change: 0 additions & 1 deletion src/CommunityToolkit.Maui.UnitTests/BaseViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service
#endregion

#region Register Services for PopupServiceTests

appBuilder.Services.AddTransientPopup<LongLivedSelfClosingPopup, LongLivedMockPageViewModel>();
appBuilder.Services.AddTransientPopup<ShortLivedSelfClosingPopup, ShortLivedMockPageViewModel>();
appBuilder.Services.AddTransientPopup<GarbageCollectionHeavySelfClosingPopup, MockPageViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public void ConfirmOptionsDefaultValue()
Assert.False(Options.ShouldSuppressExceptionsInBehaviors);
Assert.False(Options.ShouldSuppressExceptionsInConverters);
Assert.False(isAndroidDialogFragmentServiceInitialized);
Assert.Equal(Options.DefaultPopupSettings, new DefaultPopupSettings());
Assert.Equal(Options.DefaultPopupOptionsSettings, new DefaultPopupOptionsSettings());

Core.AppBuilderExtensions.ShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted -= HandleShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted;

Expand Down Expand Up @@ -50,6 +52,8 @@ public void ConfirmDefaultValueRemainWhenOptionsNull()
Assert.False(Options.ShouldSuppressExceptionsInBehaviors);
Assert.False(Options.ShouldSuppressExceptionsInConverters);
Assert.True(isAndroidDialogFragmentServiceInitialized);
Assert.Equal(Options.DefaultPopupSettings, new DefaultPopupSettings());
Assert.Equal(Options.DefaultPopupOptionsSettings, new DefaultPopupOptionsSettings());

void HandleShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted(object? sender, EventArgs e)
{
Expand Down Expand Up @@ -88,6 +92,25 @@ public void UseMauiCommunityToolkit_ShouldAssignValues()
// Arrange
var builder = MauiApp.CreateBuilder();
bool isAndroidDialogFragmentServiceInitialized = false;
var defaultPopupSettings = new DefaultPopupSettings
{
CanBeDismissedByTappingOutsideOfPopup = true,
BackgroundColor = Colors.Orange,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Start,
Margin = 72,
Padding = 4
};

var defaultPopupOptionsSettings = new DefaultPopupOptionsSettings
{
CanBeDismissedByTappingOutsideOfPopup = true,
OnTappingOutsideOfPopup = () => Console.WriteLine("Hello World"),
PageOverlayColor = Colors.Green,
Shadow = null,
Shape = null
};

Core.AppBuilderExtensions.ShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted += HandleShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted;

// Act
Expand All @@ -98,6 +121,8 @@ public void UseMauiCommunityToolkit_ShouldAssignValues()
options.SetShouldSuppressExceptionsInBehaviors(!Options.ShouldSuppressExceptionsInBehaviors);
options.SetShouldSuppressExceptionsInConverters(!Options.ShouldSuppressExceptionsInConverters);
options.SetShouldUseStatusBarBehaviorOnAndroidModalPage(!Core.Options.ShouldUseStatusBarBehaviorOnAndroidModalPage);
options.SetPopupDefaults(defaultPopupSettings);
options.SetPopupOptionsDefaults(defaultPopupOptionsSettings);
});

// Assert
Expand All @@ -107,6 +132,8 @@ public void UseMauiCommunityToolkit_ShouldAssignValues()
Assert.True(Options.ShouldSuppressExceptionsInBehaviors);
Assert.True(Options.ShouldSuppressExceptionsInConverters);
Assert.False(isAndroidDialogFragmentServiceInitialized);
Assert.Equal(defaultPopupSettings, Options.DefaultPopupSettings);
Assert.Equal(defaultPopupOptionsSettings, Options.DefaultPopupOptionsSettings);

Core.AppBuilderExtensions.ShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted -= HandleShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void ShowPopupAsync_WithViewType_ShowsPopup()
public void ShowPopupAsync_WithViewType_SetsCorrectDefaults()
{
// Arrange
Border popupBorder;
PopupPage popupPage;
Popup autogeneratedPopup;
var label = new Label();
Expand All @@ -192,13 +193,16 @@ public void ShowPopupAsync_WithViewType_SetsCorrectDefaults()
navigation.ShowPopup(label);

popupPage = (PopupPage)navigation.ModalStack[0];
popupBorder = popupPage.Content.PopupBorder;
autogeneratedPopup = (Popup)(popupPage.Content.PopupBorder.Content ?? throw new InvalidOperationException("Border Content cannot be null"));

// Assert
Assert.Equal(PopupDefaults.BackgroundColor, autogeneratedPopup.BackgroundColor);
Assert.Equal(PopupDefaults.HorizontalOptions, autogeneratedPopup.HorizontalOptions);
Assert.Equal(PopupDefaults.VerticalOptions, autogeneratedPopup.VerticalOptions);
Assert.Equal(PopupDefaults.Padding, autogeneratedPopup.Padding);
Assert.Equal(new Thickness(30), popupBorder.Margin);
Assert.Equal(LayoutOptions.Center, popupBorder.VerticalOptions);
Assert.Equal(LayoutOptions.Center, popupBorder.HorizontalOptions);
Assert.Equal(new Thickness(15), autogeneratedPopup.Padding);
Assert.Equal(Colors.White, autogeneratedPopup.BackgroundColor);
Assert.True(autogeneratedPopup.CanBeDismissedByTappingOutsideOfPopup);
}

[Fact]
Expand Down Expand Up @@ -465,7 +469,6 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions()
// Verify Border Bindings to Border
Assert.Equal(popup.BindingContext, border.BindingContext);
Assert.Equal(popup.Margin, border.Margin);
Assert.Equal(((IPaddingElement)popup).Padding, border.Padding);
Assert.Equal(popup.Background, border.Background);
Assert.Equal(popup.BackgroundColor, border.BackgroundColor);
Assert.Equal(popup.HorizontalOptions, border.HorizontalOptions);
Expand Down Expand Up @@ -537,7 +540,6 @@ public void ShowPopupAsync_Shell_WithCustomOptions_AppliesOptions()
// Verify Border Bindings to Border
Assert.Equal(popup.BindingContext, border.BindingContext);
Assert.Equal(popup.Margin, border.Margin);
Assert.Equal(((IPaddingElement)popup).Padding, border.Padding);
Assert.Equal(popup.Background, border.Background);
Assert.Equal(popup.BackgroundColor, border.BackgroundColor);
Assert.Equal(popup.HorizontalOptions, border.HorizontalOptions);
Expand All @@ -563,6 +565,8 @@ public void ShowPopupAsyncWithView_WithCustomOptions_AppliesOptions()

var view = new Grid
{
Margin = 20,
BackgroundColor = Colors.Orange,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Start,
};
Expand Down Expand Up @@ -606,10 +610,9 @@ public void ShowPopupAsyncWithView_WithCustomOptions_AppliesOptions()
Assert.Equal(view.VerticalOptions, border.VerticalOptions);
Assert.Equal(view.HorizontalOptions, border.HorizontalOptions);

// Verify Border Bindings to Border
// Verify Popup Bindings to Border
Assert.Equal(popup.BindingContext, border.BindingContext);
Assert.Equal(popup.Margin, border.Margin);
Assert.Equal(((IPaddingElement)popup).Padding, border.Padding);
Assert.Equal(popup.Background, border.Background);
Assert.Equal(popup.BackgroundColor, border.BackgroundColor);
Assert.Equal(popup.HorizontalOptions, border.HorizontalOptions);
Expand Down Expand Up @@ -676,22 +679,17 @@ public void ShowPopupAsyncWithView_Shell_WithCustomOptions_AppliesOptions()
Assert.Equal(viewWithQueryable.Background, popup.Background);
Assert.Equal(viewWithQueryable.BackgroundColor, popup.BackgroundColor);
Assert.Equal(viewWithQueryable.Margin, popup.Margin);
Assert.Equal(viewWithQueryable.VerticalOptions, popup.VerticalOptions);
Assert.Equal(viewWithQueryable.HorizontalOptions, popup.HorizontalOptions);

// Verify View options Binding to Border
Assert.Equal(viewWithQueryable.BindingContext, border.BindingContext);
Assert.Equal(viewWithQueryable.Background, border.Background);
Assert.Equal(viewWithQueryable.BackgroundColor, border.BackgroundColor);
Assert.Equal(viewWithQueryable.Padding, border.Padding);
Assert.Equal(viewWithQueryable.Margin, border.Margin);
Assert.Equal(viewWithQueryable.VerticalOptions, border.VerticalOptions);
Assert.Equal(viewWithQueryable.HorizontalOptions, border.HorizontalOptions);

// Verify Border Bindings to Border
// Verify Border Bindings to Popup
Assert.Equal(popup.BindingContext, border.BindingContext);
Assert.Equal(popup.Margin, border.Margin);
Assert.Equal(((IPaddingElement)popup).Padding, border.Padding);
Assert.Equal(popup.Background, border.Background);
Assert.Equal(popup.BackgroundColor, border.BackgroundColor);
Assert.Equal(popup.HorizontalOptions, border.HorizontalOptions);
Expand Down
Loading
Loading