Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async void DisplayPopup(object sender, EventArgs e)

await this.ShowPopupAsync(popupMediaElement);

popupMediaElement.Stop();
popupMediaElement.Source = null;
popupMediaElement.Stop();
popupMediaElement.Source = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class ComplexPopupViewModel(IPopupService popupService) : Observa
{
readonly IPopupService popupService = popupService;
readonly INavigation navigation = Application.Current?.Windows[0].Page?.Navigation ?? throw new InvalidOperationException("Unable to locate INavigation");

[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ReturnButtonTappedCommand))]
public partial string ReturnText { get; set; } = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void UseMauiCommunityToolkit_ShouldAssignValues()
Shadow = null,
Shape = null
};

Core.AppBuilderExtensions.ShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted += HandleShouldUseStatusBarBehaviorOnAndroidModalPageOptionCompleted;

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CommunityToolkit.Maui.UnitTests.Services;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Controls.Shapes;
using Nito.AsyncEx;
using Xunit;

namespace CommunityToolkit.Maui.UnitTests.Extensions;
Expand Down Expand Up @@ -1162,8 +1163,14 @@ public async Task ShowPopupAsync_ReferenceTypeShouldReturnNull_WhenPopupTapGestu
var popupPage = (PopupPage)navigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand Down Expand Up @@ -1197,8 +1204,14 @@ public async Task ShowPopupAsync_Shell_ReferenceTypeShouldReturnNull_WhenPopupTa
var popupPage = (PopupPage)shellNavigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand All @@ -1225,8 +1238,14 @@ public async Task ShowPopupAsync_NullableValueTypeShouldReturnResult_WhenPopupIs
var popupPage = (PopupPage)navigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand Down Expand Up @@ -1260,8 +1279,14 @@ public async Task ShowPopupAsync_Shell_NullableValueTypeShouldReturnResult_WhenP
var popupPage = (PopupPage)shellNavigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand All @@ -1288,8 +1313,14 @@ public async Task ShowPopupAsync_ValueTypeShouldReturnResult_WhenPopupIsClosedBy
var popupPage = (PopupPage)navigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand Down Expand Up @@ -1324,8 +1355,14 @@ public async Task ShowPopupAsync_Shell_ValueTypeShouldReturnResult_WhenPopupIsCl
var popupPage = (PopupPage)shellNavigation.ModalStack[0];
popupPage.PopupClosed += HandlePopupClosed;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);
tapGestureRecognizer.Command?.Execute(null);
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

var popupClosedResult = await popupClosedTCS.Task;
var showPopupResult = await showPopupTask;
Expand Down Expand Up @@ -1472,9 +1509,6 @@ public async Task ShowPopupAsync_TaskShouldCompleteWhenCloseAsyncIsCalled()
Assert.Equal(expectedResult, popupResult.Result);
Assert.False(popupResult.WasDismissedByTappingOutsideOfPopup);
}

static TapGestureRecognizer GetTapOutsideGestureRecognizer(PopupPage popupPage) =>
(TapGestureRecognizer)popupPage.Content.Children.OfType<BoxView>().Single().GestureRecognizers[0];
}

sealed class ViewWithIQueryAttributable : Button, IQueryAttributable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@ public void Popup_SetPopupOptionsDefaultsNotCalled_UsesPopupOptionsDefaults()
var popupPage = new PopupPage(new Popup(), null);
var popupBorder = popupPage.Content.PopupBorder;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

Assert.Equal(2, popupBorder.StrokeThickness);
Assert.Equal(Colors.LightGray, popupBorder.Stroke);
Assert.Equal(Colors.Black.WithAlpha(0.3f), popupPage.BackgroundColor);

Assert.Equal(Colors.Black, popupBorder.Shadow.Brush);
Assert.Equal(new(20, 20), popupBorder.Shadow.Offset);
Assert.Equal(40, popupBorder.Shadow.Radius);
Assert.Equal(0.8f, popupBorder.Shadow.Opacity);

Assert.Equal(new CornerRadius(20, 20, 20, 20), ((RoundRectangle?)popupBorder.StrokeShape)?.CornerRadius);
Assert.Equal(2, ((RoundRectangle?)popupBorder.StrokeShape)?.StrokeThickness);
Assert.Equal(Colors.LightGray, ((RoundRectangle?)popupBorder.StrokeShape)?.Stroke);
Expand All @@ -52,19 +58,25 @@ public void Popup_SetPopupOptionsNotCalled_PopupOptionsEmptyUsed_UsesPopupOption
var popupPage = new PopupPage(new Popup(), PopupOptions.Empty);
var popupBorder = popupPage.Content.PopupBorder;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

Assert.Equal(2, popupBorder.StrokeThickness);
Assert.Equal(Colors.LightGray, popupBorder.Stroke);
Assert.Equal(Colors.Black.WithAlpha(0.3f), popupPage.BackgroundColor);

Assert.Equal(Colors.Black, popupBorder.Shadow.Brush);
Assert.Equal(new(20, 20), popupBorder.Shadow.Offset);
Assert.Equal(40, popupBorder.Shadow.Radius);
Assert.Equal(0.8f, popupBorder.Shadow.Opacity);

Assert.Equal(new CornerRadius(20, 20, 20, 20), ((RoundRectangle?)popupBorder.StrokeShape)?.CornerRadius);
Assert.Equal(2, ((RoundRectangle?)popupBorder.StrokeShape)?.StrokeThickness);
Assert.Equal(Colors.LightGray, ((RoundRectangle?)popupBorder.StrokeShape)?.Stroke);
Expand All @@ -90,20 +102,18 @@ public void Popup_SetPopupDefaultsCalled_UsesDefaultPopupOptionsSettings()

var popupPage = new PopupPage(new Popup(), null);
var popupBorder = popupPage.Content.PopupBorder;
var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Act
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => { tapGestureRecognizer.Command?.Execute(null); });
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

// // Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
// Assert
Assert.True(hasOnTappingOutsideOfPopupExecuted);
Assert.Equal(defaultPopupSettings.PageOverlayColor, popupPage.BackgroundColor);
Assert.Equal(defaultPopupSettings.Shadow, popupBorder.Shadow);
Expand All @@ -130,20 +140,18 @@ public void Popup_SetPopupDefaultsCalled_PopupOptionsOverridden_UsesProvidedPopu

var popupPage = new PopupPage(new Popup(), defaultPopupSettings);
var popupBorder = popupPage.Content.PopupBorder;
var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Act
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => { tapGestureRecognizer.Command?.Execute(null); });
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

// // Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
Assert.True(hasOnTappingOutsideOfPopupExecuted);
Assert.Equal(defaultPopupSettings.PageOverlayColor, popupPage.BackgroundColor);
Assert.Equal(defaultPopupSettings.Shadow, popupBorder.Shadow);
Expand All @@ -157,19 +165,25 @@ public void View_SetPopupOptionsDefaultsNotCalled_UsesPopupOptionsDefaults()
var popupPage = new PopupPage(new View(), null);
var popupBorder = popupPage.Content.PopupBorder;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

Assert.Equal(2, popupBorder.StrokeThickness);
Assert.Equal(Colors.LightGray, popupBorder.Stroke);
Assert.Equal(Colors.Black.WithAlpha(0.3f), popupPage.BackgroundColor);

Assert.Equal(Colors.Black, popupBorder.Shadow.Brush);
Assert.Equal(new(20, 20), popupBorder.Shadow.Offset);
Assert.Equal(40, popupBorder.Shadow.Radius);
Assert.Equal(0.8f, popupBorder.Shadow.Opacity);

Assert.Equal(new CornerRadius(20, 20, 20, 20), ((RoundRectangle?)popupBorder.StrokeShape)?.CornerRadius);
Assert.Equal(2, ((RoundRectangle?)popupBorder.StrokeShape)?.StrokeThickness);
Assert.Equal(Colors.LightGray, ((RoundRectangle?)popupBorder.StrokeShape)?.Stroke);
Expand All @@ -182,19 +196,24 @@ public void View_SetPopupOptionsNotCalled_PopupOptionsEmptyUsed_UsesPopupOptions
var popupPage = new PopupPage(new View(), PopupOptions.Empty);
var popupBorder = popupPage.Content.PopupBorder;

var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
// Assert
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}
Assert.Equal(2, popupBorder.StrokeThickness);
Assert.Equal(Colors.LightGray, popupBorder.Stroke);
Assert.Equal(Colors.Black.WithAlpha(0.3f), popupPage.BackgroundColor);

Assert.Equal(Colors.Black, popupBorder.Shadow.Brush);
Assert.Equal(new(20, 20), popupBorder.Shadow.Offset);
Assert.Equal(40, popupBorder.Shadow.Radius);
Assert.Equal(0.8f, popupBorder.Shadow.Opacity);

Assert.Equal(new CornerRadius(20, 20, 20, 20), ((RoundRectangle?)popupBorder.StrokeShape)?.CornerRadius);
Assert.Equal(2, ((RoundRectangle?)popupBorder.StrokeShape)?.StrokeThickness);
Assert.Equal(Colors.LightGray, ((RoundRectangle?)popupBorder.StrokeShape)?.Stroke);
Expand All @@ -220,20 +239,18 @@ public void View_SetPopupDefaultsCalled_UsesDefaultPopupOptionsSettings()

var popupPage = new PopupPage(new View(), null);
var popupBorder = popupPage.Content.PopupBorder;
var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Act
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => { tapGestureRecognizer.Command?.Execute(null); });
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

// // Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
// Assert
Assert.True(hasOnTappingOutsideOfPopupExecuted);
Assert.Equal(defaultPopupSettings.PageOverlayColor, popupPage.BackgroundColor);
Assert.Equal(defaultPopupSettings.Shadow, popupBorder.Shadow);
Expand All @@ -260,28 +277,21 @@ public void View_SetPopupDefaultsCalled_PopupOptionsOverridden_UsesProvidedPopup

var popupPage = new PopupPage(new View(), defaultPopupSettings);
var popupBorder = popupPage.Content.PopupBorder;
var tapGestureRecognizer = GetTapOutsideGestureRecognizer(popupPage);

// Act
// // Assert
try
{
// Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
AsyncContext.Run(() => { tapGestureRecognizer.Command?.Execute(null); });
AsyncContext.Run(() => Assert.True(popupPage.TryExecuteTapOutsideOfPopupCommand()));
}
catch (PopupNotFoundException) // PopupNotFoundException is expected here because `ShowPopup` was never called
{
}

// // Assert
Assert.True(tapGestureRecognizer.Command?.CanExecute(null));
Assert.True(hasOnTappingOutsideOfPopupExecuted);
Assert.Equal(defaultPopupSettings.PageOverlayColor, popupPage.BackgroundColor);
Assert.Equal(defaultPopupSettings.Shadow, popupBorder.Shadow);
Assert.Equal(defaultPopupSettings.Shape, popupBorder.StrokeShape);
}


static TapGestureRecognizer GetTapOutsideGestureRecognizer(PopupPage popupPage) =>
(TapGestureRecognizer)popupPage.Content.Children.OfType<BoxView>().Single().GestureRecognizers[0];
}
#pragma warning restore CA1416
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void CanBeDismissedByTappingOutsideOfPopup_SetValue_ShouldBeUpdated()
public void Shadow_DefaultValue_ShouldBeTrue()
{
var popupOptions = new PopupOptions();

Assert.Equal(Colors.Black, popupOptions.Shadow?.Brush);
Assert.Equal(new(20, 20), popupOptions.Shadow?.Offset);
Assert.Equal(40, popupOptions.Shadow?.Radius);
Expand Down
Loading
Loading