From 21cd4bdb6fe40b2b5eaec8cce15ccbc992ce2f1e Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Fri, 1 Apr 2022 10:28:22 -0500 Subject: [PATCH 1/6] Switch to Modal for window tests --- .../tests/DeviceTests/Elements/Shell/ShellTests.cs | 6 ++---- .../DeviceTests/Stubs/WindowHandlerStub.iOS.cs | 13 +++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs index 5ebdcd298b98..93fa0b36c975 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs @@ -1,5 +1,4 @@ -#if !IOS -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -182,5 +181,4 @@ public async Task BasicShellNavigationStructurePermutations(ShellItem[] shellIte return value; }); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs index 825db3d0a323..802fc1502957 100644 --- a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs +++ b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs @@ -16,16 +16,17 @@ public class WindowHandlerStub : ElementHandler, IWindowHandl private static void MapContent(WindowHandlerStub handler, IWindow window) { var view = window.Content.ToPlatform(handler.MauiContext); - handler.PlatformView.RootViewController.View.AddSubview(view); + + var vc = + (window.Content.Handler as IPlatformViewHandler) + .ViewController; + + handler.PlatformView.RootViewController.PresentViewController(vc, false, null); } protected override void DisconnectHandler(UIWindow platformView) { - VirtualView - .Content - .ToPlatform() - .RemoveFromSuperview(); - + platformView.RootViewController.DismissViewController(false, null); base.DisconnectHandler(platformView); } From 776f3488a6eb8129f3e00b2b700ffaa247730633 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Fri, 15 Apr 2022 16:31:17 -0500 Subject: [PATCH 2/6] - add iOS tests to collection --- .../tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs | 2 ++ .../Elements/FlyoutPage/FlyoutPageTests.iOS.cs | 9 +++++++++ .../tests/DeviceTests/Elements/Modal/ModalTests.cs | 2 +- .../Elements/NavigationPage/NavigationPageTests.iOS.cs | 9 +++++++++ .../tests/DeviceTests/Elements/PlatformBehaviorTests.cs | 2 +- .../tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs | 9 +++++++++ .../tests/DeviceTests/Elements/VisualElementTests.cs | 2 +- 7 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs create mode 100644 src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs create mode 100644 src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs index 88233b8e021b..b5f8da788983 100644 --- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs @@ -1,9 +1,11 @@ using System.Threading.Tasks; using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; +using Xunit; namespace Microsoft.Maui.DeviceTests { + [Collection(HandlerTestBase.RunInNewWindowCollection)] public partial class EditorTests { MauiTextView GetPlatformControl(EditorHandler handler) => diff --git a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs new file mode 100644 index 000000000000..0be66c849e6d --- /dev/null +++ b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs @@ -0,0 +1,9 @@ +using Xunit; + +namespace Microsoft.Maui.DeviceTests +{ + [Collection(HandlerTestBase.RunInNewWindowCollection)] + public partial class FlyoutPageTests + { + } +} \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs index 6f6fd446866d..80ea2b5ed651 100644 --- a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs @@ -17,7 +17,7 @@ namespace Microsoft.Maui.DeviceTests { [Category(TestCategory.Modal)] -#if ANDROID +#if ANDROID || IOS [Collection(HandlerTestBase.RunInNewWindowCollection)] #endif public partial class ModalTests : HandlerTestBase diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs new file mode 100644 index 000000000000..fbdcc2152bc2 --- /dev/null +++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs @@ -0,0 +1,9 @@ +using Xunit; + +namespace Microsoft.Maui.DeviceTests +{ + [Collection(HandlerTestBase.RunInNewWindowCollection)] + public partial class NavigationPageTests : HandlerTestBase + { + } +} diff --git a/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs b/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs index c03e1bf82a44..92e6cc4d5802 100644 --- a/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.Maui.DeviceTests { [Category(TestCategory.Behavior)] -#if ANDROID +#if ANDROID || IOS [Collection(HandlerTestBase.RunInNewWindowCollection)] #endif public partial class PlatformBehaviorTests : HandlerTestBase diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs new file mode 100644 index 000000000000..477ff70ba130 --- /dev/null +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs @@ -0,0 +1,9 @@ +using Xunit; + +namespace Microsoft.Maui.DeviceTests +{ + [Collection(HandlerTestBase.RunInNewWindowCollection)] + public partial class ShellTests + { + } +} diff --git a/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs b/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs index e2f04d497ecf..f627967ed2fe 100644 --- a/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.Maui.DeviceTests { [Category(TestCategory.VisualElement)] -#if ANDROID +#if ANDROID || IOS [Collection(HandlerTestBase.RunInNewWindowCollection)] #endif public partial class VisualElementTests : HandlerTestBase From b7532ac733c766193baf4a075c459bd287e28016 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 12 May 2022 12:53:51 -0500 Subject: [PATCH 3/6] - fix exception --- .../Handlers/Shell/iOS/ShellPageRendererTracker.cs | 2 +- src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs index 893531e55110..39f893260be6 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -168,7 +168,7 @@ protected virtual void OnPageSet(Page oldPage, Page newPage) { oldPage.Appearing -= PageAppearing; oldPage.PropertyChanged -= OnPagePropertyChanged; - newPage.Loaded -= OnPageLoaded; + oldPage.Loaded -= OnPageLoaded; ((INotifyCollectionChanged)oldPage.ToolbarItems).CollectionChanged -= OnToolbarItemsChanged; } diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs index 41729d9baae8..6dcdc74cd5b7 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs @@ -70,6 +70,7 @@ public async Task FlyoutContentRenderersWhenFlyoutBehaviorStartsAsLocked() }); } +#if !IOS [Fact(DisplayName = "Flyout Starts as Open correctly")] public async Task FlyoutIsPresented() { @@ -87,6 +88,7 @@ public async Task FlyoutIsPresented() await CheckFlyoutState(handler, false); }); } +#endif [Fact(DisplayName = "Back Button Visibility Changes with push/pop")] From 88e87043675059e68c10e9bae45ec072fb44e69d Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 12 May 2022 14:46:29 -0500 Subject: [PATCH 4/6] - fix VS dismiss --- .../Shell/iOS/ShellPageRendererTracker.cs | 17 ++++++- .../Elements/ListView/ListViewTests.cs | 1 + .../DeviceTests/Elements/Shell/ShellTests.cs | 8 +--- .../Elements/Shell/ShellTests.iOS.cs | 2 +- .../tests/DeviceTests/HandlerTestBase.iOS.cs | 45 ++++++++++++++----- .../Stubs/WindowHandlerStub.iOS.cs | 44 +++++++++++++++--- 6 files changed, 92 insertions(+), 25 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs index 39f893260be6..d0105eba2b84 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -141,7 +141,14 @@ protected virtual void UpdateTabBarVisible() void OnToolbarPropertyChanged(object sender, PropertyChangedEventArgs e) { - UpdateTitle(); + if (e.PropertyName == Shell.TitleViewProperty.PropertyName) + { + UpdateTitleView(); + } + else if (e.PropertyName == Page.TitleProperty.PropertyName) + { + UpdateTitle(); + } } protected virtual void UpdateTitle() @@ -207,7 +214,13 @@ protected virtual void OnRendererSet() protected virtual void UpdateTitleView() { - var titleView = _context.Shell.GetEffectiveValue(Shell.TitleViewProperty, () => Shell.GetTitleView(_context.Shell), null, Page); + var titleView = _context.Shell.Toolbar.TitleView as View; + + if (NavigationItem.TitleView is TitleViewContainer tvc && + tvc.View == titleView) + { + return; + } if (titleView == null) { diff --git a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs index 457b3cd13771..e687df8530d3 100644 --- a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs @@ -8,6 +8,7 @@ namespace Microsoft.Maui.DeviceTests { + [Collection(HandlerTestBase.RunInNewWindowCollection)] [Category(TestCategory.ListView)] public partial class ListViewTests : HandlerTestBase { diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs index 6dcdc74cd5b7..d33260a48614 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs @@ -90,7 +90,6 @@ public async Task FlyoutIsPresented() } #endif - [Fact(DisplayName = "Back Button Visibility Changes with push/pop")] public async Task BackButtonVisibilityChangesWithPushPop() { @@ -115,12 +114,9 @@ public async Task SetHasBackButton() { SetupBuilder(); - var shell = await InvokeOnMainThreadAsync(() => + var shell = await CreateShellAsync(shell => { - return new Shell() - { - Items = { new ContentPage() } - }; + shell.CurrentItem = new ContentPage(); }); await CreateHandlerAndAddToWindow(shell, async (handler) => diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs index e53ad18bb07b..383941cc3a12 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs @@ -1,4 +1,4 @@ -#if !IOS +#if IOS using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs b/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs index 41a6ccde525a..40ff106806f2 100644 --- a/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs +++ b/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs @@ -59,7 +59,14 @@ Task RunWindowTest(IWindow window, Func action) await controlsWindow.Navigation.PopModalAsync(); } - window.Handler.DisconnectHandler(); + if (window.Handler is WindowHandlerStub whs) + { + window.Handler.DisconnectHandler(); + await whs.FinishedDisconnecting; + } + else + window.Handler.DisconnectHandler(); + } } }); @@ -72,6 +79,28 @@ internal ModalWrapper GetModalWrapper(Page modalPage) } protected bool IsBackButtonVisible(IElementHandler handler) + { + var vcs = GetActiveChildViewControllers(handler); + + if (vcs.Length <= 1) + return false; + + return !vcs[vcs.Length - 1].NavigationItem.HidesBackButton; + } + + protected object GetTitleView(IElementHandler handler) + { + var activeVC = GetVisibleViewController(handler); + if ( activeVC.NavigationItem.TitleView is + ShellPageRendererTracker.TitleViewContainer tvc) + { + return tvc.View.Handler.PlatformView; + } + + return null; + } + + UIViewController[] GetActiveChildViewControllers(IElementHandler handler) { if (handler is ShellRenderer renderer) { @@ -79,14 +108,7 @@ protected bool IsBackButtonVisible(IElementHandler handler) { if (sir.ChildViewControllers[0] is ShellSectionRenderer ssr) { - // Nothing has been pushed to the stack - if (ssr.ChildViewControllers.Length == 1) - return false; - - var activeVC = - ssr.ChildViewControllers[ssr.ChildViewControllers.Length - 1]; - - return !activeVC.NavigationItem.HidesBackButton; + return ssr.ChildViewControllers; } } } @@ -94,9 +116,10 @@ protected bool IsBackButtonVisible(IElementHandler handler) throw new NotImplementedException(); } - protected object GetTitleView(IElementHandler handler) + UIViewController GetVisibleViewController(IElementHandler handler) { - throw new NotImplementedException(); + var vcs = GetActiveChildViewControllers(handler); + return vcs[vcs.Length - 1]; } } } diff --git a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs index 802fc1502957..f0d363214b87 100644 --- a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs +++ b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.iOS.cs @@ -1,5 +1,7 @@ using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; using UIKit; @@ -8,6 +10,9 @@ namespace Microsoft.Maui.DeviceTests { public class WindowHandlerStub : ElementHandler, IWindowHandler { + TaskCompletionSource _finishedDisconnecting = new TaskCompletionSource(); + public Task FinishedDisconnecting => _finishedDisconnecting.Task; + public static IPropertyMapper WindowMapper = new PropertyMapper(WindowHandler.Mapper) { [nameof(IWindow.Content)] = MapContent @@ -17,16 +22,45 @@ private static void MapContent(WindowHandlerStub handler, IWindow window) { var view = window.Content.ToPlatform(handler.MauiContext); - var vc = - (window.Content.Handler as IPlatformViewHandler) - .ViewController; + if (window.Content is Shell) + { + var vc = + (window.Content.Handler as IPlatformViewHandler) + .ViewController; - handler.PlatformView.RootViewController.PresentViewController(vc, false, null); + handler.PlatformView.RootViewController.PresentViewController(vc, false, null); + } + else + { + handler.PlatformView.RootViewController.View.AddSubview(view); + } } protected override void DisconnectHandler(UIWindow platformView) { - platformView.RootViewController.DismissViewController(false, null); + var vc = (VirtualView.Content.Handler as IPlatformViewHandler) + .ViewController; + + if (VirtualView.Content is Shell) + { + platformView.RootViewController + .PresentedViewController. + DismissViewController(false, + () => + { + _finishedDisconnecting.SetResult(true); + }); + } + else + { + VirtualView + .Content + .ToPlatform() + .RemoveFromSuperview(); + + _finishedDisconnecting.SetResult(true); + } + base.DisconnectHandler(platformView); } From 14791f3a60a28a92c9d67e6ed2bc6c0e9fa0eadc Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 12 May 2022 14:47:02 -0500 Subject: [PATCH 5/6] - enable iOS Tests --- .../tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs index 383941cc3a12..88d41a6281e9 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs @@ -1,5 +1,4 @@ -#if IOS -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -207,4 +206,3 @@ public ModalShellPage() } } } -#endif From 587971c72cea89cd2cb285b53f47f459ba526d9d Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 12 May 2022 15:12:19 -0500 Subject: [PATCH 6/6] - comment out iOS tests for shell --- src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs | 6 ++++-- .../tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs index d33260a48614..5b78c71b941c 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs @@ -1,4 +1,5 @@ -using System; +#if !IOS +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -334,4 +335,5 @@ public async Task BasicShellNavigationStructurePermutations(ShellItem[] shellIte return value; }); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs index 88d41a6281e9..e53ad18bb07b 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.iOS.cs @@ -1,4 +1,5 @@ -using System; +#if !IOS +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -206,3 +207,4 @@ public ModalShellPage() } } } +#endif