Example #1
0
        public override ValueTask <MvxBasePresentationAttribute?> CreatePresentationAttribute(Type?viewModelType, Type?viewType)
        {
            if (MasterNavigationController == null &&
                (TabBarViewController == null || !TabBarViewController.CanShowChildView()))
            {
                MvxLog.Instance.Trace($"PresentationAttribute nor MasterNavigationController found for {viewType.Name}. " +
                                      $"Assuming Root presentation");
                var rootAttribute = new MvxRootPresentationAttribute()
                {
                    WrapInNavigationController = true,
                    ViewType      = viewType,
                    ViewModelType = viewModelType
                };
                return(new ValueTask <MvxBasePresentationAttribute?>(rootAttribute));
            }
            MvxLog.Instance.Trace($"PresentationAttribute not found for {viewType?.Name}. " +
                                  $"Assuming animated Child presentation");
            var childAttribute = new MvxChildPresentationAttribute()
            {
                ViewType      = viewType,
                ViewModelType = viewModelType
            };

            return(new ValueTask <MvxBasePresentationAttribute?>(childAttribute));
        }
Example #2
0
        protected virtual bool CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute attribute)
        {
            // if there are modals presented
            if (ModalViewControllers.Any())
            {
                foreach (var modalNav in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)modalNav, viewModel))
                    {
                        return(true);
                    }
                }
            }

            //if the current root is a TabBarViewController, delegate close responsibility to it
            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            if (SplitViewController != null && SplitViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            // if the current root is a NavigationController, close it in the stack
            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(true);
            }

            return(false);
        }
        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!");
        }
Example #4
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 bool CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute attribute)
        {
            if (ModalViewControllers.Any())
            {
                foreach (var navController in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)navController, viewModel))
                    {
                        return(true);
                    }
                }
            }

            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(true);
            }

            return(false);
        }
Example #6
0
        protected MvxBasePresentationAttribute GetPresentationAttributes(UIViewController viewController)
        {
            var attributes = viewController.GetType().GetCustomAttributes(typeof(MvxBasePresentationAttribute), true).FirstOrDefault() as MvxBasePresentationAttribute;

            if (attributes == null)
            {
                MvxTrace.Trace($"PresentationAttribute not found for {viewController.GetType().Name}, assuming animated Child presentation");
                attributes = new MvxChildPresentationAttribute();
            }
            return(attributes);
        }
Example #7
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!");
        }
Example #8
0
        protected override void ShowChildViewController(UIViewController viewController, MvxChildPresentationAttribute attribute, MvxViewModelRequest request)
        {
            if (request.ViewModelType == typeof(LoginViewModel))
            {
                MasterNavigationController.View.Layer.AddAnimation(fadeAnimation, CALayer.Transition);
                MasterNavigationController.PushViewController(viewController, false);
                return;
            }

            base.ShowChildViewController(viewController, attribute, request);
        }
Example #9
0
        protected virtual void PushViewControllerIntoStack(UINavigationController navigationController, UIViewController viewController, MvxChildPresentationAttribute attribute)
        {
            navigationController.PushViewController(viewController, attribute.Animated);

            if (viewController is IMvxTabBarViewController tabBarController)
            {
                TabBarViewController = tabBarController;
            }
        }
Example #10
0
        protected virtual bool TryCloseViewControllerInsideStack(UINavigationController navController, IMvxViewModel toClose, MvxChildPresentationAttribute attribute)
        {
            // check for top view controller
            var topView = navController.TopViewController.GetIMvxIosView();

            if (topView != null && topView.ViewModel == toClose)
            {
                navController.PopViewController(attribute.Animated);
                return(true);
            }

            // loop through stack
            var controllers       = navController.ViewControllers.ToList();
            var controllerToClose = controllers.FirstOrDefault(vc => vc.GetIMvxIosView().ViewModel == toClose);

            if (controllerToClose != null)
            {
                controllers.Remove(controllerToClose);
                navController.ViewControllers = controllers.ToArray();

                return(true);
            }

            return(false);
        }
Example #11
0
        protected override void ShowChildViewController(UIViewController viewController, MvxChildPresentationAttribute attribute, MvxViewModelRequest request)
        {
            //Fix to show tabchild child view correctly
            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 stack!");
        }