Skip to content

Commit

Permalink
Merge branch 'main' into 1901-fix-snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodeTraveler authored Jan 29, 2025
2 parents e4902ec + d694f5f commit 188f0f7
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
run: dotnet build ${{ env.PathToLibrarySolution }} -c Release -p:PackageVersion=${{ env.NugetPackageVersion }} -p:Version=${{ env.NugetPackageVersion }}

- name: Run All Unit Tests
run: dotnet test -c Release ${{ env.PathToLibrarySolution }} --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory ${{ runner.temp }}
run: dotnet test -c Release ${{ env.PathToLibrarySolution }} --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory ${{ runner.temp }} --logger GitHubActions

- name: Publish Test Results
if: runner.os == 'Windows'
Expand Down
4 changes: 2 additions & 2 deletions samples/CommunityToolkit.Maui.Sample/Models/PopupSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public PopupSizeConstants(IDeviceDisplay deviceDisplay)
{
Tiny = new(100, 100);
Small = new(300, 300);
Medium = new(0.7 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.6 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Large = new(0.9 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.8 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Medium = new(0.4 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.6 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Large = new(0.5 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.8 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
}

// examples for fixed sizes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Core;
using System.Runtime.Versioning;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Core.Handlers;
using CommunityToolkit.Maui.Views;

Expand All @@ -7,6 +8,11 @@ namespace CommunityToolkit.Maui;
/// <summary>
/// This class contains CameraView's <see cref="MauiAppBuilder"/> extensions.
/// </summary>
[SupportedOSPlatform("windows10.0.10240.0")]
[SupportedOSPlatform("android21.0")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("maccatalyst")]
[SupportedOSPlatform("tizen")]
public static class AppBuilderExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using System.ComponentModel;
using System.Runtime.Versioning;
using System.Windows.Input;
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
namespace CommunityToolkit.Maui.Core;

/// <summary>Default Values for <see cref="ICameraView"/>"/></summary>
[SupportedOSPlatform("windows10.0.10240.0")]
[SupportedOSPlatform("android21.0")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("maccatalyst")]
[SupportedOSPlatform("tizen")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static class CameraViewDefaults
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace CommunityToolkit.Maui.Views;
[SupportedOSPlatform("android21.0")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("maccatalyst")]
[SupportedOSPlatform("tizen")]
public partial class CameraView : View, ICameraView
{
static readonly BindablePropertyKey isAvailablePropertyKey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public static void MapOnOpened(PopupHandler handler, IPopup view, object? result
ArgumentNullException.ThrowIfNull(handler.MauiContext);

var parent = view.Parent.ToPlatform(handler.MauiContext);

parent.IsHitTestVisible = false;
handler.PlatformView.XamlRoot = parent.XamlRoot;
handler.PlatformView.XamlRoot = view.GetWindow().Content?.Handler?.MauiContext?.GetPlatformWindow().Content.XamlRoot ?? throw new InvalidOperationException("Window Content cannot be null");
handler.PlatformView.IsHitTestVisible = true;
handler.PlatformView.IsOpen = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" PrivateAssets="All" />
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
68 changes: 20 additions & 48 deletions src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace CommunityToolkit.Maui.UnitTests.Views;
public class PopupTests : BaseHandlerTest
{
const string resultWhenUserTapsOutsideOfPopup = "User Tapped Outside of Popup";
readonly IPopup popup = new MockPopup();
readonly MockPopup popup = new();
readonly MockPopupHandler popupHandler;

public PopupTests()
{
popupHandler = CreateElementHandler<MockPopupHandler>(popup);
Assert.IsType<IPopup>(new MockPopup(), exactMatch: false);
}

Expand Down Expand Up @@ -49,15 +51,13 @@ public async Task ShowPopupAsync_CancellationTokenExpired()

app.Windows[0].Page = page;

var popupHandler = CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

// Ensure CancellationToken Has Expired
await Task.Delay(100, CancellationToken.None);

await Assert.ThrowsAsync<TaskCanceledException>(() => page.ShowPopupAsync((MockPopup)popup, cts.Token));
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => page.ShowPopupAsync(popup, cts.Token));
}

[Fact(Timeout = (int)TestDuration.Short)]
Expand All @@ -80,15 +80,13 @@ public async Task ShowPopupAsync_CancellationTokenCancelled()

app.Windows[0].Page = page;

var popupHandler = CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

// Ensure CancellationToken Has Expired
await cts.CancelAsync();

await Assert.ThrowsAsync<TaskCanceledException>(() => page.ShowPopupAsync((MockPopup)popup, cts.Token));
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => page.ShowPopupAsync(popup, cts.Token));
}

[Fact(Timeout = (int)TestDuration.Short)]
Expand All @@ -111,15 +109,13 @@ public async Task CloseAsync_CancellationTokenExpired()

app.Windows[0].Page = page;

var popupHandler = CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

// Ensure CancellationToken Has Expired
await Task.Delay(100, CancellationToken.None);

await Assert.ThrowsAsync<TaskCanceledException>(() => ((MockPopup)popup).CloseAsync(token: cts.Token));
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => popup.CloseAsync(token: cts.Token));
}

[Fact(Timeout = (int)TestDuration.Short)]
Expand All @@ -142,15 +138,13 @@ public async Task CloseAsync_CancellationTokenCancelled()

app.Windows[0].Page = page;

var popupHandler = CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

// Ensure CancellationToken Has Expired
await cts.CancelAsync();

await Assert.ThrowsAsync<TaskCanceledException>(() => ((MockPopup)popup).CloseAsync(token: cts.Token));
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => popup.CloseAsync(token: cts.Token));
}

[Fact(Timeout = (int)TestDuration.Short)]
Expand All @@ -171,17 +165,15 @@ public async Task OnOpenedMapperIsCalled()

app.Windows[0].Page = page;

var popupHandler = CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

page.ShowPopup((MockPopup)popup);
page.ShowPopup(popup);
Assert.Equal(1, popupHandler.OnOpenedCount);
popup.OnDismissedByTappingOutsideOfPopup();
await popup.OnDismissedByTappingOutsideOfPopup(CancellationToken.None);

var popupTask = page.ShowPopupAsync((MockPopup)popup, CancellationToken.None);
popup.OnDismissedByTappingOutsideOfPopup();
var popupTask = page.ShowPopupAsync(popup, CancellationToken.None);
await popup.OnDismissedByTappingOutsideOfPopup(CancellationToken.None);

await popupTask;

Expand All @@ -202,7 +194,7 @@ public async Task PopupDismissedByTappingOutsideOfPopup()
}
};

((MockPopup)popup).Closed += (s, e) =>
popup.Closed += (s, e) =>
{
Assert.Equal(popup, s);
popupClosedTCS.SetResult(((string?)e.Result, e.WasDismissedByTappingOutsideOfPopup));
Expand All @@ -213,12 +205,10 @@ public async Task PopupDismissedByTappingOutsideOfPopup()

app.Windows[0].Page = page;

CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

popup.OnDismissedByTappingOutsideOfPopup();
await popup.OnDismissedByTappingOutsideOfPopup(CancellationToken.None);

var (result, wasDismissedByTappingOutsideOfPopup) = await popupClosedTCS.Task;

Expand Down Expand Up @@ -247,20 +237,17 @@ public async Task OnDismissedWithResult()

app.Windows[0].Page = page;

// Make sure that our popup will have a Handler
CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

((MockPopup)popup).Closed += (_, e) =>
popup.Closed += (_, e) =>
{
result = e.Result;
isPopupDismissed = true;
closedTCS.TrySetResult();
closedTCS.SetResult();
};

((MockPopup)popup).Close(new object());
popup.Close(new object());
await closedTCS.Task;

Assert.True(isPopupDismissed);
Expand Down Expand Up @@ -288,19 +275,16 @@ public async Task OnDismissedWithoutResult()

app.Windows[0].Page = page;

// Make sure that our popup will have a Handler
CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

((MockPopup)popup).Closed += (_, e) =>
popup.Closed += (_, e) =>
{
result = e.Result;
isPopupDismissed = true;
};

await ((MockPopup)popup).CloseAsync(token: CancellationToken.None);
await popup.CloseAsync(token: CancellationToken.None);

Assert.True(isPopupDismissed);
Assert.Null(result);
Expand Down Expand Up @@ -341,17 +325,14 @@ public async Task ShowPopup_IsLogicalChild()

app.Windows[0].Page = page;

// Make sure that our popup will have a Handler
CreateElementHandler<MockPopupHandler>(popup);

Assert.NotNull(popup.Handler);
Assert.NotNull(page.Handler);

Assert.Single(page.LogicalChildrenInternal);
page.ShowPopup((MockPopup)popup);
page.ShowPopup(popup);
Assert.Equal(2, page.LogicalChildrenInternal.Count);

await ((MockPopup)popup).CloseAsync(token: CancellationToken.None);
await popup.CloseAsync(token: CancellationToken.None);
Assert.Single(page.LogicalChildrenInternal);
}

Expand All @@ -361,15 +342,6 @@ public MockPopup()
{
ResultWhenUserTapsOutsideOfPopup = resultWhenUserTapsOutsideOfPopup;
}

protected override async Task OnClosed(object? result, bool wasDismissedByTappingOutsideOfPopup, CancellationToken token = default)
{
await Task.Delay(100, token);

((IPopup)this).HandlerCompleteTCS.TrySetResult();

await base.OnClosed(result, wasDismissedByTappingOutsideOfPopup, token);
}
}

sealed class PopupViewModel : INotifyPropertyChanged
Expand Down
2 changes: 2 additions & 0 deletions src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ internal virtual void OnOpened() =>
/// <param name="token"><see cref="CancellationToken"/></param>
protected virtual async Task OnClosed(object? result, bool wasDismissedByTappingOutsideOfPopup, CancellationToken token = default)
{
token.ThrowIfCancellationRequested();

((IPopup)this).OnClosed(result);
((IResourceDictionary)resources).ValuesChanged -= OnResourcesChanged;

Expand Down

0 comments on commit 188f0f7

Please sign in to comment.