public TabbedPageManager(IMauiContext context) { _context = context; NavigationRootManager = _context.GetNavigationRootManager(); _listeners = new Listeners(this); _viewPager = new ViewPager2(context.Context) { OverScrollMode = OverScrollMode.Never, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; }
Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action) where THandler : class, IElementHandler { return(InvokeOnMainThreadAsync(async() => { var testingRootPanel = (WPanel)MauiProgram.CurrentWindow.Content; IElementHandler newWindowHandler = null; NavigationRootManager navigationRootManager = null; try { var scopedContext = new MauiContext(MauiContext.Services); scopedContext.AddWeakSpecific(MauiProgram.CurrentWindow); var mauiContext = scopedContext.MakeScoped(true); navigationRootManager = mauiContext.GetNavigationRootManager(); navigationRootManager.UseCustomAppTitleBar = false; newWindowHandler = window.ToHandler(mauiContext); var content = window.Content.Handler.ToPlatform(); await content.OnLoadedAsync(); await Task.Delay(10); if (typeof(THandler).IsAssignableFrom(newWindowHandler.GetType())) { await action((THandler)newWindowHandler); } else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType())) { await action((THandler)window.Content.Handler); } } finally { if (navigationRootManager != null) { navigationRootManager.Disconnect(); } if (newWindowHandler != null) { newWindowHandler.DisconnectHandler(); } // Set the root window panel back to the testing panel if (testingRootPanel != null && MauiProgram.CurrentWindow.Content != testingRootPanel) { MauiProgram.CurrentWindow.Content = testingRootPanel; await testingRootPanel.OnLoadedAsync(); await Task.Delay(10); } } })); }
Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action) where THandler : class, IElementHandler { return(InvokeOnMainThreadAsync(async() => { var testingRootPanel = (WPanel)MauiProgram.CurrentWindow.Content; IElementHandler newWindowHandler = null; NavigationRootManager navigationRootManager = null; try { var scopedContext = new MauiContext(MauiContext.Services); scopedContext.AddWeakSpecific(MauiProgram.CurrentWindow); var mauiContext = scopedContext.MakeScoped(true); navigationRootManager = mauiContext.GetNavigationRootManager(); MauiContext .Services .GetRequiredService <WWindow>() .SetWindowHandler(window, mauiContext); newWindowHandler = window.Handler; var content = window.Content.Handler.ToPlatform(); await content.OnLoadedAsync(); await Task.Delay(10); if (typeof(THandler).IsAssignableFrom(newWindowHandler.GetType())) { await action((THandler)newWindowHandler); } else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType())) { await action((THandler)window.Content.Handler); } else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType())) { await action((THandler)cp.Content.Handler); } else { throw new Exception($"I can't work with {typeof(THandler)}"); } } finally { if (navigationRootManager != null) { navigationRootManager.Disconnect(); } if (newWindowHandler != null) { newWindowHandler.DisconnectHandler(); } // Set the root window panel back to the testing panel if (testingRootPanel != null && MauiProgram.CurrentWindow.Content != testingRootPanel) { MauiProgram.CurrentWindow.Content = testingRootPanel; await testingRootPanel.OnLoadedAsync(); await Task.Delay(10); } // reset the appbar title to our test runner MauiProgram .CurrentWindow .GetWindow() .Handler .MauiContext .GetNavigationRootManager() .UpdateAppTitleBar(true); } }));
MauiNavigationView GetMauiNavigationView(NavigationRootManager navigationRootManager) { return((navigationRootManager.RootView as WindowRootView).NavigationViewControl); }