Exemplo n.º 1
0
        protected virtual void ShowModalViewController(
            UIViewController viewController,
            MvxModalPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            // setup modal based on attribute
            if (attribute.WrapInNavigationController)
            {
                viewController = CreateNavigationController(viewController);
            }

            viewController.ModalPresentationStyle = attribute.ModalPresentationStyle;
            viewController.ModalTransitionStyle   = attribute.ModalTransitionStyle;
            if (attribute.PreferredContentSize != default(CGSize))
            {
                viewController.PreferredContentSize = attribute.PreferredContentSize;
            }

            // Check if there is a modal already presented first. Otherwise use the window root
            var modalHost = ModalViewControllers.LastOrDefault() ?? _window.RootViewController;

            modalHost.PresentViewController(
                viewController,
                attribute.Animated,
                null);

            ModalViewControllers.Add(viewController);
        }
Exemplo n.º 2
0
 protected void CleanupModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         CloseModalViewController(ModalViewControllers.LastOrDefault());
     }
 }
Exemplo n.º 3
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!");
        }
Exemplo n.º 4
0
        protected virtual bool CloseModalViewController(IMvxViewModel toClose)
        {
            // check if there is a modal stack presented
            if (ModalViewControllers.LastOrDefault() is UINavigationController modalNavController)
            {
                if (TryCloseViewControllerInsideStack(modalNavController, toClose))
                {
                    // First() is the RootViewController of the stack. If it is being closed, then remove the nav stack
                    if (modalNavController.ViewControllers.First().GetIMvxIosView().ViewModel == toClose)
                    {
                        CloseModalViewController(modalNavController);
                    }
                    return(true);
                }
            }
            else
            {
                // close any plain modal presented
                var last = ModalViewControllers.Last();
                if (last.GetIMvxIosView().ViewModel == toClose)
                {
                    CloseModalViewController(last);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        protected virtual Task <bool> ShowModalViewController(
            UIViewController viewController,
            MvxModalPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            // Content size should be set to a target view controller, not the navigation one
            if (attribute.PreferredContentSize != default(CGSize))
            {
                viewController.PreferredContentSize = attribute.PreferredContentSize;
            }

            // setup modal based on attribute
            if (attribute.WrapInNavigationController)
            {
                viewController = CreateNavigationController(viewController);
            }

            viewController.ModalPresentationStyle = attribute.ModalPresentationStyle;
            viewController.ModalTransitionStyle   = attribute.ModalTransitionStyle;

            // Check if there is a modal already presented first. Otherwise use the window root
            var modalHost = ModalViewControllers.LastOrDefault() ?? _window.RootViewController;

            modalHost.PresentViewController(
                viewController,
                attribute.Animated,
                null);

            ModalViewControllers.Add(viewController);
            return(Task.FromResult(true));
        }
Exemplo n.º 6
0
 public virtual void CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute());
     }
 }
Exemplo n.º 7
0
 protected async Task <bool> CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault())))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 8
0
 public virtual async Task <bool> CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute())))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 9
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!");
        }