示例#1
0
        public static IMauiContext MakeScoped(this IMauiContext mauiContext, bool registerNewNavigationRoot)
        {
            var scopedContext = new MauiContext(mauiContext.Services);

            if (registerNewNavigationRoot)
            {
                scopedContext.AddWeakSpecific(new NavigationRootManager(scopedContext.GetPlatformWindow()));
            }

            return(scopedContext);
        }
示例#2
0
        protected override MauiPicker CreatePlatformView()
        {
            var platformPicker = new MauiPicker(null)
            {
                BorderStyle = UITextBorderStyle.RoundedRect
            };

            platformPicker.ShouldBeginEditing += (textField) =>
            {
                var alertController = CreateAlert(textField);
                var platformWindow  = MauiContext?.GetPlatformWindow();
                platformWindow?.BeginInvokeOnMainThread(() =>
                {
                    _ = platformWindow?.RootViewController?.PresentViewControllerAsync(alertController, true);
                });
                return(false);
            };

            return(platformPicker);
        }
示例#3
0
        public async Task SwipingAwayModalRemovesEntireNavigationPage()
        {
            Routing.RegisterRoute(nameof(SwipingAwayModalRemovesEntireNavigationPage), typeof(ModalShellPage));

            SetupBuilder();
            var shell = await CreateShellAsync((shell) =>
            {
                shell.Items.Add(new ContentPage());
            });

            await CreateHandlerAndAddToWindow <ShellRenderer>(shell, async (handler) =>
            {
                var modalPage = new Controls.NavigationPage(new ContentPage());
                modalPage.On <iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet);
                var platformWindow = MauiContext.GetPlatformWindow().RootViewController;

                await shell.Navigation.PushModalAsync(modalPage);
                await shell.GoToAsync(nameof(SwipingAwayModalRemovesEntireNavigationPage));
                await shell.GoToAsync(nameof(SwipingAwayModalRemovesEntireNavigationPage));
                await shell.GoToAsync(nameof(SwipingAwayModalRemovesEntireNavigationPage));

                var modalVC        = GetModalWrapper(modalPage);
                int navigatedFired = 0;
                ShellNavigationSource?shellNavigationSource = null;
                var finishedNavigation = new TaskCompletionSource <bool>();
                shell.Navigated       += ShellNavigated;

                modalVC.DidDismiss(null);
                await finishedNavigation.Task.WaitAsync(TimeSpan.FromSeconds(2));
                Assert.Equal(1, navigatedFired);
                Assert.Equal(ShellNavigationSource.PopToRoot, shellNavigationSource.Value);
                Assert.Equal(0, shell.Navigation.ModalStack.Count);

                void ShellNavigated(object sender, ShellNavigatedEventArgs e)
                {
                    navigatedFired++;
                    shellNavigationSource = e.Source;
                    finishedNavigation.SetResult(true);
                }
            });
        }