Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

#13527 - OnAppearing() is now called on every back navigation again b… #13528

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Xamarin.Forms.Platform.UAP/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ internal void UpdatePageSizes()
readonly Windows.UI.Xaml.Controls.Page _page;
Windows.UI.Xaml.Controls.ProgressBar _busyIndicator;
Page _currentPage;
Page _modalBackgroundPage;
readonly Stack<Page> _modalBackgroundPages = new Stack<Page>();
readonly NavigationModel _navModel = new NavigationModel();
readonly ToolbarTracker _toolbarTracker = new ToolbarTracker();
readonly ImageConverter _imageConverter = new ImageConverter();
Expand Down Expand Up @@ -345,19 +345,23 @@ async void SetCurrent(Page newPage, bool popping = false, bool modal = false, Ac
Page previousPage = _currentPage;

if (modal && !popping && !newPage.BackgroundColor.IsDefault)
_modalBackgroundPage = previousPage;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this line, when you navigate to the second modal level, _modalBackgroundPage already has a value and will be overwritten.
As of that, when you navigate back the second time, _modalBackgroundPage will already be null (this is done in the first pop of the navigation stack at line 360 below!). So you lost the outer modal page and cannot call its OnAppeare() callback anymore!

{
_modalBackgroundPages.Push(previousPage);
}
else
{
RemovePage(previousPage);

if(!modal && _modalBackgroundPage != null)
if(!modal && _modalBackgroundPages.Count != 0)
{
RemovePage(_modalBackgroundPage);
_modalBackgroundPage.Cleanup();
_modalBackgroundPage.Parent = null;
var modalBackgroundPage = _modalBackgroundPages.Peek();
RemovePage(modalBackgroundPage);
modalBackgroundPage.Cleanup();
modalBackgroundPage.Parent = null;
}

_modalBackgroundPage = null;

if(_modalBackgroundPages.Count > 0)
_modalBackgroundPages.Pop();
}

if (popping)
Expand Down Expand Up @@ -398,8 +402,8 @@ void RemovePage(Page page)
if (_container == null || page == null)
return;

if (_modalBackgroundPage != null)
_modalBackgroundPage.GetCurrentPage()?.SendAppearing();
if (_modalBackgroundPages.Count != 0)
_modalBackgroundPages.Peek().GetCurrentPage()?.SendAppearing();

IVisualElementRenderer pageRenderer = GetRenderer(page);

Expand All @@ -411,9 +415,9 @@ void AddPage(Page page)
{
if (_container == null || page == null)
return;

if (_modalBackgroundPage != null)
_modalBackgroundPage.GetCurrentPage()?.SendDisappearing();
if (_modalBackgroundPages.Count != 0)
_modalBackgroundPages.Peek().GetCurrentPage()?.SendDisappearing();

IVisualElementRenderer pageRenderer = page.GetOrCreateRenderer();

Expand Down