-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Enhancement] Changes in navigation events parameters #28384
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
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b1155de
Added repro sample
jsuarezruiz 3aa95d5
Added UITests
jsuarezruiz c54d712
Changes in navigation events parameters
jsuarezruiz 1143890
Fix failing UITest
jsuarezruiz d4a48e1
Fixed test
jsuarezruiz 3f97a13
Fixed test on iOS/Catalyst
jsuarezruiz 55e4987
Renamed NavigationType.PageSwap to NavigationType.Replace
jsuarezruiz a612fdb
Removed NavigationType.Initialized
jsuarezruiz 8624cb1
Added two more samples, using tabs and flyout
jsuarezruiz a22156c
Updated sample
jsuarezruiz be30c11
Create Issue21814TabbedPage.cs
jsuarezruiz bcdcff7
Updated flyout sample
jsuarezruiz f543582
Adding more tests
jsuarezruiz 3d3dd2a
Added more TabbedPage tests
jsuarezruiz 4ae778a
More FlyoutPage tests
jsuarezruiz 8dfba1d
Updated test
jsuarezruiz c45bf21
Fixed tests
jsuarezruiz 20b8f52
Use Replace with Tabs and FlyoutItems
jsuarezruiz c9c1a4e
Fixed unit tests
jsuarezruiz 2b3cc79
Updated test
jsuarezruiz 1223371
Fix iOS Flyout tests
jsuarezruiz 631300c
Changes in tests
jsuarezruiz 207e075
Fix test on Android
jsuarezruiz 435fe31
Fixed Windows test
jsuarezruiz a5f5774
Fixed parameters in NavigatingFromEventArgs
jsuarezruiz 882f728
Updated TabbedPage unit test
jsuarezruiz 97e282c
Added more navigation unit tests
jsuarezruiz 6442596
- fix publicapi.txt files
PureWeen 5cde60c
Update FlyoutPage.cs
PureWeen a143401
Update FlyoutPage.cs
PureWeen f6f4e70
Update MultiPage.cs
PureWeen 78cd921
- fix publicapi
PureWeen a21aa12
More tests
jsuarezruiz ed9319a
Fixed device test
jsuarezruiz 97efcee
Changes based on PR feedback, simplify FlyoutPage Detail
jsuarezruiz 98bb1cf
More changes to fix a test
jsuarezruiz 4ad8eae
[ci] Update the publicapi
rmarinho c809393
- remove navigatingfrom
PureWeen ddc4874
Updated tests
jsuarezruiz 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
There are no files selected for viewing
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
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
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
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
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 |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ public partial class NavigationPage : Page, IPageContainer<Page>, IBarElement, I | |
|
|
||
| INavigationPageController NavigationPageController => this; | ||
|
|
||
|
|
||
| partial void Init(); | ||
|
|
||
| #if WINDOWS || ANDROID || TIZEN | ||
|
|
@@ -63,6 +64,7 @@ public partial class NavigationPage : Page, IPageContainer<Page>, IBarElement, I | |
| #endif | ||
|
|
||
| bool _setForMaui; | ||
|
|
||
| /// <include file="../../docs/Microsoft.Maui.Controls/NavigationPage.xml" path="//Member[@MemberName='.ctor'][1]/Docs/*" /> | ||
| public NavigationPage() : this(UseMauiHandler) | ||
| { | ||
|
|
@@ -112,6 +114,8 @@ public Color BarTextColor | |
|
|
||
| internal Task CurrentNavigationTask { get; set; } | ||
|
|
||
| internal NavigationType NavigationType { get; set; } | ||
|
|
||
| /// <include file="../../docs/Microsoft.Maui.Controls/NavigationPage.xml" path="//Member[@MemberName='Peek']/Docs/*" /> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public Page Peek(int depth) | ||
|
|
@@ -377,12 +381,12 @@ protected override bool OnBackButtonPressed() | |
| void SendNavigated(Page previousPage, NavigationType navigationType) | ||
| { | ||
| previousPage?.SendNavigatedFrom(new NavigatedFromEventArgs(CurrentPage, navigationType)); | ||
| CurrentPage.SendNavigatedTo(new NavigatedToEventArgs(previousPage)); | ||
| CurrentPage.SendNavigatedTo(new NavigatedToEventArgs(previousPage, navigationType)); | ||
| } | ||
|
|
||
| void SendNavigating(Page navigatingFrom = null) | ||
| void SendNavigating(NavigationType navigationType, Page navigatingFrom = null) | ||
| { | ||
| (navigatingFrom ?? CurrentPage)?.SendNavigatingFrom(new NavigatingFromEventArgs()); | ||
| (navigatingFrom ?? CurrentPage)?.SendNavigatingFrom(new NavigatingFromEventArgs(CurrentPage, navigationType)); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -691,16 +695,17 @@ private protected override void OnHandlerChangedCore() | |
| var visiblePage = Navigation.NavigationStack[NavigationStack.Count - 1]; | ||
| RootPage = navStack[0]; | ||
| CurrentPage = visiblePage; | ||
|
|
||
|
|
||
| var navigationType = DetermineNavigationType(); | ||
|
|
||
| SendHandlerUpdateAsync(false, null, | ||
| () => | ||
| { | ||
| FireAppearing(CurrentPage); | ||
| }, | ||
| () => | ||
| { | ||
| // TODO this is the wrong navigation type | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was passing the wrong navigation type parameter. If we not decide to update the navigation EventArgs with the properties included in this PR, the changes to fix this should be included in another one. |
||
| SendNavigated(null, NavigationType.Initialize); | ||
| SendNavigated(null, navigationType); | ||
| }) | ||
| .FireAndForget(Handler); | ||
| } | ||
|
|
@@ -712,7 +717,21 @@ private protected override void OnHandlerChangedCore() | |
| ((IStackNavigation)this).NavigationFinished(this.NavigationStack); | ||
| } | ||
| } | ||
|
|
||
| NavigationType DetermineNavigationType() | ||
| { | ||
| var parentPages = this.GetParentPages(); | ||
|
|
||
| bool hasTabOrFlyout = parentPages.Any(page => page is FlyoutPage or TabbedPage); | ||
|
|
||
| if (hasTabOrFlyout) | ||
| { | ||
| return NavigationType.Replace; | ||
| } | ||
|
|
||
| return NavigationType.Push; | ||
| } | ||
|
|
||
| // Once we get all platforms over to the new APIs | ||
| // we can just delete all the code inside NavigationPage.cs that fires "requested" events | ||
| class MauiNavigationImpl : NavigationProxy | ||
|
|
@@ -750,6 +769,7 @@ protected override void OnInsertPageBefore(Page page, Page before) | |
| Owner.SendHandlerUpdateAsync(false, | ||
| () => | ||
| { | ||
| Owner.NavigationType = NavigationType.Insert; | ||
| int index = Owner.InternalChildren.IndexOf(before); | ||
| Owner.InternalChildren.Insert(index, page); | ||
|
|
||
|
|
@@ -783,6 +803,7 @@ protected async override Task<Page> OnPopAsync(bool animated) | |
| await Owner.SendHandlerUpdateAsync(animated, | ||
| () => | ||
| { | ||
| Owner.NavigationType = NavigationType.Pop; | ||
| Owner.CurrentPage = newCurrentPage; | ||
| Owner.RemoveFromInnerChildren(currentPage); | ||
| if (currentPage.TitleView != null) | ||
|
|
@@ -792,7 +813,7 @@ await Owner.SendHandlerUpdateAsync(animated, | |
| }, | ||
| () => | ||
| { | ||
| Owner.SendNavigating(currentPage); | ||
| Owner.SendNavigating(NavigationType.Pop, currentPage); | ||
| Owner.FireDisappearing(currentPage); | ||
| Owner.FireAppearing(newCurrentPage); | ||
| }, | ||
|
|
@@ -817,6 +838,7 @@ protected override Task OnPopToRootAsync(bool animated) | |
| return Owner.SendHandlerUpdateAsync(animated, | ||
| () => | ||
| { | ||
| Owner.NavigationType = NavigationType.PopToRoot; | ||
| var lastIndex = NavigationStack.Count - 1; | ||
| while (lastIndex > 0) | ||
| { | ||
|
|
@@ -829,7 +851,7 @@ protected override Task OnPopToRootAsync(bool animated) | |
| }, | ||
| () => | ||
| { | ||
| Owner.SendNavigating(previousPage); | ||
| Owner.SendNavigating(NavigationType.PopToRoot, previousPage); | ||
| Owner.FireDisappearing(previousPage); | ||
| Owner.FireAppearing(newPage); | ||
| }, | ||
|
|
@@ -845,22 +867,24 @@ protected override Task OnPushAsync(Page root, bool animated) | |
| if (Owner.InternalChildren.Contains(root)) | ||
| return Task.CompletedTask; | ||
|
|
||
| var navigationType = Owner.DetermineNavigationType(); | ||
| var previousPage = Owner.CurrentPage; | ||
|
|
||
| return Owner.SendHandlerUpdateAsync(animated, | ||
| () => | ||
| { | ||
| Owner.NavigationType = navigationType; | ||
| Owner.PushPage(root); | ||
| }, | ||
| () => | ||
| { | ||
| Owner.SendNavigating(previousPage); | ||
| Owner.SendNavigating(navigationType, previousPage); | ||
| Owner.FireDisappearing(previousPage); | ||
| Owner.FireAppearing(root); | ||
| }, | ||
| () => | ||
| { | ||
| Owner.SendNavigated(previousPage, NavigationType.Push); | ||
| Owner.SendNavigated(previousPage, navigationType); | ||
| Owner?.Pushed?.Invoke(Owner, new NavigationEventArgs(root)); | ||
| }); | ||
| } | ||
|
|
@@ -886,6 +910,7 @@ protected override void OnRemovePage(Page page) | |
| Owner.SendHandlerUpdateAsync(false, | ||
| () => | ||
| { | ||
| Owner.NavigationType = NavigationType.Remove; | ||
| Owner.RemoveFromInnerChildren(page); | ||
|
|
||
| if (Owner.RootPage == page) | ||
|
|
||
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 |
|---|---|---|
| @@ -1,30 +1,18 @@ | ||
| #nullable disable | ||
| using System; | ||
| using Microsoft.Maui.Controls.Internals; | ||
|
|
||
| namespace Microsoft.Maui.Controls | ||
| { | ||
| internal enum NavigationType | ||
| { | ||
| Push, | ||
| Pop, | ||
| PopToRoot, | ||
| Insert, | ||
| Remove, | ||
| PageSwap, | ||
| Initialize | ||
| } | ||
|
|
||
| public sealed class NavigatedFromEventArgs : EventArgs | ||
| { | ||
| internal NavigationType NavigationType { get; } | ||
| public NavigationType NavigationType { get; } | ||
|
|
||
| internal Page DestinationPage { get; } | ||
| public Page DestinationPage { get; } | ||
|
|
||
| internal NavigatedFromEventArgs(Page destinationPage, NavigationType navigationType) | ||
| { | ||
| DestinationPage = destinationPage; | ||
| NavigationType = navigationType; | ||
| } | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#30985