From 85f2a06ecd11e4ba5a9e567d86f9d2fb49a2c5ca Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 9 Dec 2024 09:48:09 -0800 Subject: [PATCH] Revert "[release/9.0.1xx-sr1] [Windows] Fix crash when navigating pages" (#26478) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "[release/9.0.1xx-sr1] [release/9.0.1xx] [Windows] Fix crash when navi…" This reverts commit 51e2faf67a4de286c589767e8a82afcca2acfe59. * Update Versions.props --- eng/Versions.props | 4 +-- .../Elements/Shell/ShellTests.Windows.cs | 25 ------------------ .../Windows/StackNavigationManager.cs | 26 ++++--------------- 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 48a52441ca55..53a6264ce9fd 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,10 +1,10 @@ - 9.0.13 + 9.0.14 9 0 - 13 + 14 9.0.100 servicing diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs index 4bbcc4c27276..3a5b98c09518 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs @@ -541,31 +541,6 @@ await CreateHandlerAndAddToWindow(shell, async (handler) => }); } - [Fact(DisplayName = "Navigate back and forth doesn't crash")] - public async Task NavigateBackAndForthDoesntCrash() - { - SetupBuilder(); - - var shell = await CreateShellAsync(shell => - { - shell.CurrentItem = new ContentPage(); - }); - - await CreateHandlerAndAddToWindow(shell, async (handler) => - { - var secondPage = new ContentPage(); - - for (int i = 0; i < 5; i++) - { - await shell.Navigation.PushAsync(secondPage, false); - await Task.Delay(100); - await shell.Navigation.PopToRootAsync(false); - await Task.Delay(100); - } - Assert.NotNull(shell.Handler); - }); - } - [Fact(DisplayName = "Shell Toolbar With Only MenuBarItems Is Visible")] public async Task ShellToolbarWithOnlyMenuBarItemsIsVisible() { diff --git a/src/Core/src/Platform/Windows/StackNavigationManager.cs b/src/Core/src/Platform/Windows/StackNavigationManager.cs index 3ff11c3fbf77..79ab61095b73 100644 --- a/src/Core/src/Platform/Windows/StackNavigationManager.cs +++ b/src/Core/src/Platform/Windows/StackNavigationManager.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Threading; +using System.Threading.Tasks; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; @@ -14,7 +17,6 @@ public class StackNavigationManager IMauiContext _mauiContext; Frame? _navigationFrame; Action? _pendingNavigationFinished; - ContentPresenter? _previousContent; bool _connected; protected NavigationRootManager WindowManager => _mauiContext.GetNavigationRootManager(); @@ -56,12 +58,6 @@ public virtual void Disconnect(IStackNavigation navigationView, Frame navigation FirePendingNavigationFinished(); _navigationFrame = null; NavigationView = null; - - if (_previousContent is not null) - { - _previousContent.Content = null; - _previousContent = null; - } } public virtual void NavigateTo(NavigationRequest args) @@ -170,14 +166,6 @@ void OnNavigated(object sender, UI.Xaml.Navigation.NavigationEventArgs e) VerticalAlignment = UI.Xaml.VerticalAlignment.Stretch }; - // There's some bug in our code, or the lifecycle of ContentControl, that is causing the content to - // never be removed from the parent... - if (_previousContent is not null) - { - _previousContent.Content = null; - _previousContent = null; - } - page.Content = presenter; } else @@ -186,15 +174,13 @@ void OnNavigated(object sender, UI.Xaml.Navigation.NavigationEventArgs e) } // At this point if the Content isn't a ContentPresenter the user has replaced - // the content so we just let them take control + // the conent so we just let them take control if (presenter == null || _currentPage == null) return; - var platformPage = _currentPage.ToPlatform(MauiContext); - try { - presenter.Content = platformPage; + presenter.Content = _currentPage.ToPlatform(MauiContext); } catch (Exception) { @@ -204,8 +190,6 @@ void OnNavigated(object sender, UI.Xaml.Navigation.NavigationEventArgs e) _pendingNavigationFinished = () => { - _previousContent = presenter; - if (presenter?.Content is not FrameworkElement pc) { FireNavigationFinished();