From 6cd45c96518d2273607544889c3a6ac4dcaece21 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Tue, 4 Jun 2024 05:09:37 -0500 Subject: [PATCH] Reset opacity when view is being reused --- .../Tests/Issues/Issue19955.cs | 25 +++++ .../tests/TestCases/Issues/Issue19955.cs | 91 +++++++++++++++++++ .../Navigation/NavigationViewFragment.cs | 4 + 3 files changed, 120 insertions(+) create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19955.cs create mode 100644 src/Controls/tests/TestCases/Issues/Issue19955.cs diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19955.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19955.cs new file mode 100644 index 000000000000..5b4e0aa3e2b4 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19955.cs @@ -0,0 +1,25 @@ +using System.Drawing; +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; +using OpenQA.Selenium.Interactions; +using NUnit.Framework.Legacy; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue19955: _IssuesUITest +{ + public Issue19955(TestDevice device) : base(device) { } + + public override string Issue => "Navigating Back to FlyoutPage Renders Blank Page"; + + [Test] + [Category(UITestCategories.FlyoutPage)] + public void NavigatingBackToFlyoutPageRendersBlankPage() + { + App.WaitForElement("NavigateToSecondPageButton"); + App.Tap("NavigateToSecondPageButton"); + App.WaitForElement("NavigateBackToFirstPageButton"); + App.Tap("NavigateBackToFirstPageButton"); + App.WaitForElement("NavigateToSecondPageButton"); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases/Issues/Issue19955.cs b/src/Controls/tests/TestCases/Issues/Issue19955.cs new file mode 100644 index 000000000000..53cfc0dcff9e --- /dev/null +++ b/src/Controls/tests/TestCases/Issues/Issue19955.cs @@ -0,0 +1,91 @@ +using System; +using System.Diagnostics; +using Microsoft.Maui.Controls; + +namespace Maui.Controls.Sample.Issues +{ + [Issue(IssueTracker.Github, 19955, "Navigating Back to FlyoutPage Renders Blank Page")] + public class Issue19955 : NavigationPage + { + public Issue19955() : base(new MainFlyout()) + { + + } + + public partial class MainFlyout : FlyoutPage + { + public MainFlyout() + { + Flyout = new MainFlyoutMenu(); + Detail = new MarkerNavigationPage(); + } + + class MarkerNavigationPage : NavigationPage + { + public MarkerNavigationPage() : base(new FirstPage()) + { + } + } + + class MarkerNavigationPage2 : NavigationPage + { + public MarkerNavigationPage2() : base(new FirstPage()) + { + } + } + } + + public partial class MainFlyoutMenu : ContentPage + { + public MainFlyoutMenu() + { + Title = "MainFlyoutMenu"; + Content = new VerticalStackLayout(){ + new Label() + { + Text = "I'm the Flyout Page" + } + }; + } + } + + public partial class FirstPage : ContentPage + { + public FirstPage() + { + Content = new VerticalStackLayout(){ + new Button(){ + Text = "Navigate to Second page", + Command = new Command(Button_Clicked), + AutomationId = "NavigateToSecondPageButton" + }, + }; + } + + async void Button_Clicked() + { + await Application.Current.MainPage.Navigation.PushAsync(new SecondPage()); + } + } + + public partial class SecondPage : ContentPage + { + public SecondPage() + { + Content = new VerticalStackLayout() + { + new Button(){ + Text = "Navigate back to first page", + Command = new Command(Button_Clicked), + AutomationId = "NavigateBackToFirstPageButton" + } + }; + } + + async void Button_Clicked() + { + await Application.Current.MainPage.Navigation.PopAsync(); + } + } + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Android/Navigation/NavigationViewFragment.cs b/src/Core/src/Platform/Android/Navigation/NavigationViewFragment.cs index 97a25c1e7954..0a47dbc7e1a5 100644 --- a/src/Core/src/Platform/Android/Navigation/NavigationViewFragment.cs +++ b/src/Core/src/Platform/Android/Navigation/NavigationViewFragment.cs @@ -58,6 +58,10 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup? container .CurrentPage .ToPlatform(NavigationManager.MauiContext, RequireContext(), inflater, ChildFragmentManager); + // This shouldn't typically happen, but if a previous animation hasn't finished from a navigation that was interrupted + // the opacity of the view will be set to 0. This will reset it to 1. + NavigationManager.CurrentPage?.Handler?.UpdateValue(nameof(IView.Opacity)); + _currentView.RemoveFromParent(); return _currentView;