/// <summary>
        /// Returns self if <paramref name="view"/> is <see cref="FragmentActivity"/> or
        /// <see cref="Fragment.Activity"/> property value if <paramref name="view"/> is <see cref="Fragment"/>.
        /// </summary>
        /// <param name="view">The navigation view.</param>
        /// <returns>The activity instance. Can be <see langword="null"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="view"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="view" /> is derived from a class other than the <see cref="FragmentActivity"/> or <see cref="Fragment"/>.
        /// </exception>
        public static FragmentActivity?GetActivity(this INavigationView <ILifecycleViewModel> view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            return(view.As(
                       activity => activity,
                       fragment => fragment.Activity));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns self if <paramref name="view"/> is <see cref="UINavigationController"/> or
        /// <see cref="UIViewController.NavigationController"/> property value if <paramref name="view"/> is <see cref="UIViewController"/>.
        /// </summary>
        /// <param name="view">The navigation view.</param>
        /// <returns>The view controller instance. Can be <see langword="null"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="view"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="view" /> is derived from a class other than the <see cref="UIViewController"/>.
        /// </exception>
        public static UINavigationController?GetNavigationController(this INavigationView <ILifecycleViewModel> view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            return(view.As(
                       viewController => viewController.NavigationController,
                       navigationController => navigationController));
        }
        /// <summary>
        /// Performs backward navigation from the <paramref name="sourceView"/>.
        /// </summary>
        /// <param name="sourceView">The <see cref="INavigationView{TViewModel}"/> from which navigation is performed from.</param>
        /// <param name="animated">Determines if the transition is to be animated.</param>
        /// <param name="viewControllerNavigationStrategy">
        /// The strategy used for performing navigation. Can be <see langword="null"/>.
        /// <para>The default is <see cref="ViewControllerBackwardNavigationStrategy.DismissViewController(Action?)"/> if <paramref name="sourceView"/> is presented or
        /// <see cref="ViewControllerBackwardNavigationStrategy.PopViewController()"/> if <paramref name="sourceView"/> is pushed.</para>
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="sourceView"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="sourceView" /> is derived from a class other than the <see cref="UIViewController"/>.
        /// </exception>
        public void NavigateBack(
            INavigationView <ILifecycleViewModel> sourceView,
            bool animated,
            ViewControllerBackwardNavigationDelegate?viewControllerNavigationStrategy = null)
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            sourceView.As(
                viewController => (viewControllerNavigationStrategy ?? GetViewControllerBackwardNavigationStrategy(viewController)).Invoke(viewController, animated));
        }
        /// <summary>
        /// Performs backward navigation from the <paramref name="sourceView"/> with returning a lifecycle-aware view model result.
        /// </summary>
        /// <typeparam name="TResult">The type of the source view model result.</typeparam>
        /// <param name="sourceView">The <see cref="INavigationView{TViewModel}"/> from which navigation is performed from.</param>
        /// <param name="resultCode">Determines whether the result should be set as successful or canceled.</param>
        /// <param name="result">The source view model result. Can be <see langword="null"/>.</param>
        /// <param name="animated">Determines if the transition is to be animated.</param>
        /// <param name="viewControllerNavigationStrategy">
        /// The strategy used for performing navigation. Can be <see langword="null"/>.
        /// <para>The default is <see cref="ViewControllerBackwardNavigationStrategy.DismissViewController(Action?)"/> if <paramref name="sourceView"/> is presented or
        /// <see cref="ViewControllerBackwardNavigationStrategy.PopViewController()"/> if <paramref name="sourceView"/> is pushed.</para>
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="sourceView"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="sourceView" /> is derived from a class other than the <see cref="UIViewController"/>.
        /// </exception>
        public void NavigateBack <TResult>(
            INavigationView <ILifecycleViewModelWithResult <TResult> > sourceView,
            ResultCode resultCode,
            TResult?result,
            bool animated,
            ViewControllerBackwardNavigationDelegate?viewControllerNavigationStrategy = null)
            where TResult : Result
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            sourceView.SetResult(resultCode, result);
            sourceView.As(
                viewController => (viewControllerNavigationStrategy ?? GetViewControllerBackwardNavigationStrategy(viewController)).Invoke(viewController, animated));
        }