Exemple #1
0
        protected virtual ValueTask <bool> ShowChildViewController(UIViewController viewController,
                                                                   MvxChildPresentationAttribute attribute,
                                                                   MvxViewModelRequest request)
        {
            if (viewController is MvxSplitViewController)
            {
                throw new MvxException("A SplitViewController can't be present in a child.  Consider using a Root instead.");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController navigationController)
                {
                    PushViewControllerIntoStack(navigationController, viewController, attribute.Animated);
                    return(new ValueTask <bool>(true));
                }
                else
                {
                    throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
                }
            }

            if (TabBarViewController != null && TabBarViewController.ShowChildView(viewController))
            {
                return(new ValueTask <bool>(true));
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute.Animated);
                return(new ValueTask <bool>(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
        protected virtual void ShowChildViewController(
            UIViewController viewController,
            MvxChildPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (viewController is IMvxSplitViewController)
            {
                throw new MvxException("A SplitViewController cannot be presented as a child. Consider using Root instead");
            }

            if (ModalNavigationController != null)
            {
                ModalNavigationController.PushViewController(viewController, attribute.Animated);
                return;
            }

            if (TabBarViewController != null && TabBarViewController.ShowChildView(viewController))
            {
                return;
            }

            if (MasterNavigationController != null)
            {
                MasterNavigationController.PushViewController(viewController, attribute.Animated);

                if (viewController is IMvxTabBarViewController)
                {
                    TabBarViewController = viewController as IMvxTabBarViewController;
                }

                return;
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current Root!");
        }
Exemple #3
0
        protected override Task <bool> ShowChildViewController(
            UIViewController viewController,
            MvxChildPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (viewController is IMvxSplitViewController)
            {
                throw new MvxException("A SplitViewController cannot be presented as a child. Consider using Root instead");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController modalNavController)
                {
                    PushViewControllerIntoStack(modalNavController, viewController, attribute);

                    return(Task.FromResult(true));
                }
                throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
            }

            if (TabBarViewController != null)
            {
                if (request.PresentationValues != null &&
                    request.PresentationValues.ContainsKey(Presenter.NavigationModeKey))
                {
                    if (request.PresentationValues[Presenter.NavigationModeKey] == Presenter.ReplaceKey)
                    {
                        if (TabBarViewController is MainView mv)
                        {
                            mv.ReplaceTopChildViewModel(viewController);
                            return(Task.FromResult(true));
                        }
                    }
                }
                else
                {
                    return(Task.FromResult(TabBarViewController.ShowChildView(viewController)));
                }
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute);
                return(Task.FromResult(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
        protected virtual void ShowChildViewController(UIViewController viewController)
        {
            // dismiss ModalViewController if shown
            Window.RootViewController?.DismissViewController(true, null);

            // if current RootViewController is a TabBarViewController, the TabBarViewController takes care of it
            if (TabBarViewController != null)
            {
                TabBarViewController?.ShowChildView(viewController);
                return;
            }

            // if current RootViewController is a NavigationController, push it
            if (NavigationController != null)
            {
                NavigationController.PushViewController(viewController, true);
                return;
            }

            // there is no Root, so let's start this way!
            Mvx.Trace(MvvmCross.Platform.Platform.MvxTraceLevel.Warning, $"Showing View type: {typeof(UIViewController).Name} as Root, but it's attributed as Child");
            ShowRootViewController(viewController);
        }