-
Notifications
You must be signed in to change notification settings - Fork 494
Added OnNavigatingFrom extension for popup related navigation #3099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dartasen
wants to merge
13
commits into
CommunityToolkit:main
Choose a base branch
from
dartasen:feat/addnavigatingextension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ec77c8
Add support for NavigatingFromEventArgs
dartasen 0a4dd08
Adjust documentation of NavigatedFromEventArgsExtensions
dartasen 484f716
Consolidate NavigationEventArgsExtensions
TheCodeTraveler 90cdcef
Ensure Unit Tests unsubscribe from event handler
TheCodeTraveler c6886ac
Implement `OnNavigatingFrom` in `PopupsPage`
TheCodeTraveler 1c930b9
Merge branch 'main' into feat/addnavigatingextension
TheCodeTraveler 943cfce
Add Timeout
TheCodeTraveler 1ce05c8
Update Directory.Build.props
TheCodeTraveler 7db69f9
Update MauiPackageVersion to 10.0.51
TheCodeTraveler c0a805f
Merge branch 'main' into feat/addnavigatingextension
TheCodeTraveler e6b5f65
Update src/CommunityToolkit.Maui.UnitTests/Extensions/NavigatingFromE…
TheCodeTraveler e1e08f6
Update src/CommunityToolkit.Maui/Extensions/NavigationEventArgsExtens…
TheCodeTraveler a06260d
Update src/CommunityToolkit.Maui/Extensions/NavigationEventArgsExtens…
TheCodeTraveler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/CommunityToolkit.Maui.UnitTests/Extensions/NavigatingFromEventArgsExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| using CommunityToolkit.Maui.Extensions; | ||
| using CommunityToolkit.Maui.UnitTests.Mocks; | ||
| using Xunit; | ||
|
|
||
| namespace CommunityToolkit.Maui.UnitTests.Extensions; | ||
|
|
||
| public class NavigatingFromEventArgsExtensionsTests : BaseViewTest | ||
| { | ||
| [Fact] | ||
| public async Task NavigatingFromEventArgsExtensions_IsDestinationPageACommunityToolkitPopupPage_ShouldReturnTrue() | ||
| { | ||
| // Arrange | ||
| MockApplication application = (MockApplication)ServiceProvider.GetRequiredService<IApplication>(); | ||
| IPopupService popupService = ServiceProvider.GetRequiredService<IPopupService>(); | ||
|
|
||
| Shell shell = (Shell)(application.Windows[0].Page ?? throw new InvalidOperationException("Unable to retrieve Shell")); | ||
| Page mainPage = shell.CurrentPage; | ||
| ShellContentPage shellContentPage = new(); | ||
|
|
||
| Dictionary<string, object> shellParameters = new() | ||
| { | ||
| { nameof(ContentPage.BackgroundColor), Colors.Orange } | ||
| }; | ||
|
|
||
| TaskCompletionSource<bool?> isDestinationPageACommunityToolkitPopupPageTCS = new(); | ||
| shellContentPage.NavigatingFromEventArgsReceived += (sender, args) => | ||
| { | ||
| isDestinationPageACommunityToolkitPopupPageTCS.SetResult(args.IsDestinationPageACommunityToolkitPopupPage()); | ||
| }; | ||
|
|
||
| // Act | ||
| await mainPage.Navigation.PushAsync(shellContentPage); | ||
| await popupService.ShowPopupAsync<ShortLivedMockPageViewModel>(shell, null, shellParameters, TestContext.Current.CancellationToken); | ||
| bool? isDestinationPageACommunityToolkitPopupPage = await isDestinationPageACommunityToolkitPopupPageTCS.Task; | ||
|
|
||
| // Assert | ||
| Assert.True(isDestinationPageACommunityToolkitPopupPage); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task NavigatingFromEventArgsExtensions_IsDestinationPageACommunityToolkitPopupPage_ShouldReturnFalse() | ||
| { | ||
| // Arrange | ||
| MockApplication application = (MockApplication)ServiceProvider.GetRequiredService<IApplication>(); | ||
| IPopupService popupService = ServiceProvider.GetRequiredService<IPopupService>(); | ||
TheCodeTraveler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Shell shell = (Shell)(application.Windows[0].Page ?? throw new InvalidOperationException("Unable to retrieve Shell")); | ||
| Page mainPage = shell.CurrentPage; | ||
|
|
||
| ShellContentPage shellContentPage = new(); | ||
| ShellContentPage anotherShellContentPage = new(); | ||
|
|
||
| TaskCompletionSource<bool?> isDestinationPageACommunityToolkitPopupPageTCS = new(); | ||
dartasen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shellContentPage.NavigatingFromEventArgsReceived += (sender, args) => | ||
| { | ||
| isDestinationPageACommunityToolkitPopupPageTCS.SetResult(args.IsDestinationPageACommunityToolkitPopupPage()); | ||
| }; | ||
|
|
||
| // Act | ||
| await mainPage.Navigation.PushAsync(shellContentPage); | ||
| await mainPage.Navigation.PushAsync(anotherShellContentPage); | ||
| bool? isDestinationPageACommunityToolkitPopupPage = await isDestinationPageACommunityToolkitPopupPageTCS.Task; | ||
|
|
||
| // Assert | ||
| Assert.False(isDestinationPageACommunityToolkitPopupPage); | ||
| } | ||
|
|
||
| sealed class ShellContentPage : ContentPage | ||
| { | ||
| public event EventHandler<NavigatingFromEventArgs>? NavigatingFromEventArgsReceived; | ||
|
|
||
| protected override void OnNavigatingFrom(NavigatingFromEventArgs args) | ||
| { | ||
| base.OnNavigatingFrom(args); | ||
| NavigatingFromEventArgsReceived?.Invoke(this, args); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/CommunityToolkit.Maui/Extensions/NavigatingFromEventArgsExtensions.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using CommunityToolkit.Maui.Views; | ||
|
|
||
| namespace CommunityToolkit.Maui.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for <see cref="NavigatingFromEventArgs"/>. | ||
| /// </summary> | ||
| public static class NavigatingFromEventArgsExtensions | ||
| { | ||
| /// <summary> | ||
| /// Determines if the destination page will be a Community Toolkit <see cref="Popup"/>. | ||
| /// </summary> | ||
| /// <param name="args">The current <see cref="NavigatingFromEventArgs"/>.</param> | ||
| /// <returns>A boolean indicating if the destination page will be a Community Toolkit <see cref="Popup"/>.</returns> | ||
| public static bool IsDestinationPageACommunityToolkitPopupPage(this NavigatingFromEventArgs args) => args.DestinationPage is PopupPage; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.