Bug 52252 - Navigationstack is not getting smaller when removing the last page (currentpage) when a modal page is in view
Summary: Navigationstack is not getting smaller when removing the last page (currentpa...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.4
Hardware: Macintosh Mac OS
: Normal critical
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-02-02 14:29 UTC by mvergouwe
Modified: 2017-10-05 18:17 UTC (History)
4 users (show)

See Also:
Tags: bug, android, ios, navigationstack, ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (295.25 KB, application/x-zip-compressed)
2017-03-13 18:35 UTC, Jimmy [MSFT]
Details
iOS not working (778.58 KB, video/quicktime)
2017-03-13 19:07 UTC, mvergouwe
Details

Description mvergouwe 2017-02-02 14:29:50 UTC
# Steps to reproduce
1. Create a navigation page with a root page
2. Push three pages on the navigationstack
3. Push a modal page on the modalstack
4. Try to remove the last page from the navigationstack 
5. Pop the modal page from the stack

# Expected behavior
Navigationstack size should be three
Page shown should be the second last page from the navigation stack 

# Actual behavior
Navigationstack size is still four

# Supplemental info (logs, images, videos)
It's due to the PopAsync that doesn't finish in this code from NavigationPage.cs because page == CurrentPage
PopAsync can not be awaited with this code!!!

		void RemovePage(Page page)
		{
			if (page == CurrentPage && ((INavigationPageController)this).StackDepth <= 1)
				throw new InvalidOperationException("Cannot remove root page when it is also the currently displayed page.");
			if (page == CurrentPage)
			{
				Log.Warning("NavigationPage", "RemovePage called for CurrentPage object. This can result in undesired behavior, consider called PopAsync instead.");
				PopAsync();
				return;
			}

			if (!PageController.InternalChildren.Contains(page))
				throw new ArgumentException("Page to remove must be contained on this Navigation Page");

			EventHandler<NavigationRequestedEventArgs> handler = RemovePageRequestedInternal;
			if (handler != null)
				handler(this, new NavigationRequestedEventArgs(page, true));

			PageController.InternalChildren.Remove(page);
		}

# Test environment (full version information)
Xamarin.Forms 2.3.1
Comment 1 adrianknight89 2017-02-24 00:40:02 UTC
I think it'd be better if you attached a minimal repro for the team to test and verify the issue.
Comment 2 mvergouwe 2017-02-24 09:28:27 UTC
I'm not entirely sure what you don't understand about the steps to reproduce which I've put in the bug description.
Please send me a more detailed question so I can help you solve this.

# Steps to reproduce
1. Create a navigation page with a root page
2. Push three pages on the navigationstack
3. Push a modal page on the modalstack
4. Try to remove the last page from the navigationstack 
5. Pop the modal page from the stack

# Expected behavior
Navigationstack size should be three
Page shown should be the second last page from the navigation stack 

# Actual behavior
Navigationstack size is still four
Comment 3 Jimmy [MSFT] 2017-02-27 18:10:35 UTC
Thank you for filing this report! I will look into creating a sample project based on the information you have provided in order to confirm this issue and I will update the report as necessary.
Comment 4 Jimmy [MSFT] 2017-03-13 18:35:38 UTC
Created attachment 20292 [details]
repro project

I was able to reproduce this issue on Android with the project I'm attaching. The issue does _not_ occur on iOS or UWP. I am confirming this report so the team can investigate further.

### Version tests
Forms 2.3.4-pre4    BAD
Forms 2.3.3.193     BAD
Comment 5 mvergouwe 2017-03-13 19:07:04 UTC
Created attachment 20295 [details]
iOS not working

This movie shows it does not work on iPhoneSimulator with iOS 10.2 and Xamarin.Forms 2.3.4.212-pre4
Comment 6 Jimmy [MSFT] 2017-08-11 16:50:45 UTC
I can still reproduce this issue on Android and iOS with the latest Xamarin.Forms versions.


### Platforms Affected
Android
iOS


### Steps to Reproduce
1. Run the attached repro project on one of the affected Platforms
2. Press "Go to next page". Repeat two more times.
3. Press "Open Modal Page"
4. Press "Remove Last Page"
5. Press "Go Back"


### Expected Results
The app will return to Page 2 and the Label on the page will indicate the navigation stack size is 3.


### Actual Results
The app returns to Page 2 but the Label on the page indicates the navigation stack size is 4.


### Version Tests
2.3.6.127-nightly   BAD
2.3.5-pre6          BAD

Note You need to log in before you can comment on or make changes to this bug.