This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix bug. Children pages in NavigationPage were got appearing events
even if they were not latest in navigation stack
#758
Closed
rotorgames
wants to merge
6
commits into
xamarin:master
from
rotorgames:android-navigation-appearing
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45de43a
[Android] Fix bug. OnAppearing in child page was invoked even if thes…
rotorgames 48cbfa4
[UITest] Add test
rotorgames 2a80af8
Forgot to add NavigationChildAppearing to project
rotorgames db17c75
[UITest] Rename test class to bugzilla ticket
rotorgames e90924d
Merge branch 'master' into android-navigation-appearing
rmarinho 0fa4274
Fix build
rmarinho File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52458.cs
This file contains 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,185 @@ | ||
using System; | ||
using System.Linq; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
#if UITEST | ||
using NUnit.Framework; | ||
#endif | ||
|
||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Bugzilla, 52458, "Children pages in NavigationPage were got `appearing events` even if they were not latest in navigation stack", NavigationBehavior.PushModalAsync)] | ||
public class Bugzilla52458 : TestPage | ||
{ | ||
NavigationPage _navPage; | ||
ContentPage _page2, _page3; | ||
Label _checkIsAppearingLabel; | ||
|
||
IPageController PageController => this; | ||
|
||
protected override void Init() | ||
{ | ||
NavigationPage navPage; | ||
ContentPage appearingPage, page2, page3; | ||
|
||
var appearingLabel = new Label | ||
{ | ||
AutomationId = "checkIsAppearingLabel", | ||
Text = false.ToString() | ||
}; | ||
|
||
appearingPage = new ContentPage | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
new Button | ||
{ | ||
BackgroundColor = Color.Red, | ||
Text = "NavigateToPage2", | ||
Command = new Command(NavigateToPage2) | ||
} | ||
} | ||
} | ||
}; | ||
page2 = new ContentPage | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
new StackLayout() | ||
{ | ||
Orientation = StackOrientation.Horizontal, | ||
Children = | ||
{ | ||
new Label | ||
{ | ||
Text = "First page is appeared: " | ||
}, | ||
appearingLabel | ||
} | ||
}, | ||
new Button | ||
{ | ||
Text = "SetPage3", | ||
Command = new Command(SetPage3) | ||
} | ||
} | ||
} | ||
}; | ||
page3 = new ContentPage | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
new Button | ||
{ | ||
Text = "RevertToNavigationPage", | ||
Command = new Command(SetNavigationPage) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
appearingPage.Appearing += OnAppearingFirstPage; | ||
appearingPage.Disappearing += OnDisappearingFirstPage; | ||
|
||
navPage = new NavigationPage(appearingPage); | ||
|
||
_navPage = navPage; | ||
_checkIsAppearingLabel = appearingLabel; | ||
_page2 = page2; | ||
_page3 = page3; | ||
|
||
SetPage(navPage); | ||
} | ||
|
||
void OnAppearingFirstPage(object sender, EventArgs e) | ||
{ | ||
Device.StartTimer(TimeSpan.FromMilliseconds(50), () => | ||
{ | ||
var currentPage = _navPage.CurrentPage; | ||
|
||
_checkIsAppearingLabel.Text = true.ToString(); | ||
|
||
if (currentPage != sender) | ||
{ | ||
//throw new Exception("Page cannot get appearing event if it is not last in NavigationStack"); | ||
} | ||
|
||
return false; | ||
}); | ||
} | ||
|
||
void OnDisappearingFirstPage(object sender, EventArgs e) | ||
{ | ||
_checkIsAppearingLabel.Text = false.ToString(); | ||
} | ||
|
||
void SetNavigationPage() | ||
{ | ||
SetPage(_navPage); | ||
} | ||
|
||
void NavigateToPage2() | ||
{ | ||
if (_navPage.CurrentPage != _page2) | ||
_navPage.PushAsync(_page2); | ||
} | ||
|
||
void SetPage3() | ||
{ | ||
SetPage(_page3); | ||
} | ||
|
||
void SetPage(Page page) | ||
{ | ||
if (PageController.InternalChildren.Count > 0) | ||
PageController.InternalChildren.Remove(PageController.InternalChildren.First()); | ||
PageController.InternalChildren.Add(page); | ||
} | ||
|
||
protected override bool OnBackButtonPressed() | ||
{ | ||
var currentPage = (Page)PageController.InternalChildren.FirstOrDefault(); | ||
var currentPageResult = currentPage?.SendBackButtonPressed(); | ||
|
||
if (currentPageResult != null && currentPageResult.Value) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.OnBackButtonPressed(); | ||
} | ||
|
||
#if UITEST | ||
|
||
[Test] | ||
public void NavigationAppearingTest() | ||
{ | ||
var app = RunningApp; | ||
app.WaitForElement(x => x.Text("NavigateToPage2")); | ||
app.Tap(x => x.Text("NavigateToPage2")); | ||
app.WaitForElement(x => x.Text("SetPage3")); | ||
app.Tap(x => x.Text("SetPage3")); | ||
app.WaitForElement(x => x.Text("RevertToNavigationPage")); | ||
app.Tap(x => x.Text("RevertToNavigationPage")); | ||
app.WaitForElement(x => x.Marked("checkIsAppearingLabel")); | ||
|
||
var checkIsAppearingLabel = app.Query(x => x.Marked("checkIsAppearingLabel")).First(); | ||
|
||
Assert.IsFalse(string.Equals(checkIsAppearingLabel.Text, true.ToString()), "Page cannot get appearing event if it is not last in NavigationStack"); | ||
|
||
app.Back(); | ||
} | ||
|
||
#endif | ||
|
||
|
||
} | ||
} |
This file contains 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 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
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.
Not a fan to add another way to insert pages to the fragment stack. Can't we fix the problem just on SwitchContentAsync ?
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.
Ok. I will try to do it soon