-
Notifications
You must be signed in to change notification settings - Fork 2k
[iOS, Mac] Fix Shell.CurrentState.Location stale in OnNavigated after GoToAsync #34880
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
149 changes: 149 additions & 0 deletions
149
src/Controls/tests/TestCases.HostApp/Issues/Issue34662.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,149 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 34662, "Shell OnNavigated not called for route navigation", PlatformAffected.iOS | PlatformAffected.macOS)] | ||
| public class Issue34662 : Shell | ||
| { | ||
| public Issue34662() | ||
| { | ||
| // Page1 and Page2 are sub-routes under DashboardPage -- not ShellItems. | ||
| // This allows absolute navigation to "//DashboardPage/Page1/Page2". | ||
| Routing.RegisterRoute("Page1", typeof(Issue34662_Page1)); | ||
| Routing.RegisterRoute("Page2", typeof(Issue34662_Page2)); | ||
|
|
||
| Items.Add(new ShellContent | ||
| { | ||
| Title = "Login", | ||
| ContentTemplate = new DataTemplate(() => new Issue34662_LoginPage()), | ||
| Route = "LoginPage" | ||
| }); | ||
|
|
||
| Items.Add(new ShellContent | ||
| { | ||
| Title = "Dashboard", | ||
| ContentTemplate = new DataTemplate(() => new Issue34662_DashboardPage()), | ||
| Route = "DashboardPage" | ||
| }); | ||
| } | ||
|
|
||
| protected override void OnNavigated(ShellNavigatedEventArgs args) | ||
| { | ||
| base.OnNavigated(args); | ||
|
|
||
| // Capture CurrentState.Location inside OnNavigated. | ||
| // On 10.0.50 (bug): CurrentState = "//DashboardPage" (stale) after GoToAsync("//DashboardPage/Page1/Page2"). | ||
| // On 10.0.41 (working): CurrentState = "//DashboardPage/Page1/Page2". | ||
| var currentState = CurrentState?.Location?.OriginalString; | ||
|
|
||
| // OnNavigated fires AFTER Page2.OnAppearing, so push the value directly to Page2's label. | ||
| var page2 = CurrentPage as Issue34662_Page2 | ||
| ?? (CurrentPage as NavigationPage)?.CurrentPage as Issue34662_Page2; | ||
| page2?.SetCurrentStateLocation(currentState); | ||
| } | ||
| } | ||
|
|
||
| public class Issue34662_LoginPage : ContentPage | ||
| { | ||
| public Issue34662_LoginPage() | ||
| { | ||
| Title = "Login"; | ||
|
|
||
| var loginButton = new Button | ||
| { | ||
| Text = "Login -> //DashboardPage/Page1/Page2", | ||
| AutomationId = "LoginButton", | ||
| HorizontalOptions = LayoutOptions.Fill | ||
| }; | ||
| loginButton.Clicked += OnLoginClicked; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = new Thickness(40), | ||
| Spacing = 20, | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Children = | ||
| { | ||
| new Label | ||
| { | ||
| Text = "Tap to navigate to //DashboardPage/Page1/Page2", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| HorizontalTextAlignment = TextAlignment.Center | ||
| }, | ||
| loginButton | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private async void OnLoginClicked(object sender, EventArgs e) | ||
| { | ||
| await Shell.Current.GoToAsync("//DashboardPage/Page1/Page2"); | ||
| } | ||
| } | ||
|
|
||
| public class Issue34662_DashboardPage : ContentPage | ||
| { | ||
| public Issue34662_DashboardPage() | ||
| { | ||
| Title = "Dashboard"; | ||
| Content = new Label | ||
| { | ||
| Text = "Dashboard Page", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| public class Issue34662_Page1 : ContentPage | ||
| { | ||
| public Issue34662_Page1() | ||
| { | ||
| Title = "Page 1"; | ||
| Content = new Label | ||
| { | ||
| Text = "Page 1", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| public class Issue34662_Page2 : ContentPage | ||
| { | ||
| readonly Label _currentStateLabel; | ||
|
|
||
| public Issue34662_Page2() | ||
| { | ||
| Title = "Page 2"; | ||
|
|
||
| // Set by OnNavigated via SetCurrentStateLocation. | ||
| // Shows Shell.CurrentState.Location captured inside OnNavigated. | ||
| // Bug on 10.0.50: shows "//DashboardPage" (stale) instead of "//DashboardPage/Page1/Page2". | ||
| _currentStateLabel = new Label | ||
| { | ||
| AutomationId = "OnNavigatedCurrentStateLabel", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| HorizontalTextAlignment = TextAlignment.Center, | ||
| Text = "(not set)" | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = new Thickness(30), | ||
| Spacing = 16, | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Children = | ||
| { | ||
| new Label { Text = "Page 2", HorizontalOptions = LayoutOptions.Center }, | ||
| new Label { Text = "CurrentState.Location inside OnNavigated:", HorizontalOptions = LayoutOptions.Center }, | ||
| _currentStateLabel | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| // Called directly from Issue34662.OnNavigated -- OnNavigated fires AFTER OnAppearing, | ||
| // so we cannot read CurrentState in OnAppearing and must receive it this way. | ||
| internal void SetCurrentStateLocation(string currentState) | ||
| { | ||
| _currentStateLabel.Text = currentState ?? "(null)"; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34662.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,23 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue34662 : _IssuesUITest | ||
| { | ||
| public Issue34662(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "Shell OnNavigated not called for route navigation"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Shell)] | ||
| public void ShellCurrentStateLocationCorrectAfterAbsoluteNavigation() | ||
| { | ||
| App.WaitForElement("LoginButton"); | ||
| App.Tap("LoginButton"); | ||
| var currentStateText = App.WaitForElement("OnNavigatedCurrentStateLabel").GetText(); | ||
| Assert.That(currentStateText, Is.EqualTo("//DashboardPage/Page1/Page2"), | ||
| "Shell.CurrentState.Location inside OnNavigated should be '//DashboardPage/Page1/Page2', not stale '//DashboardPage'"); | ||
| } | ||
| } | ||
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.