Skip to content

Commit

Permalink
removing IPlatformNavigationService - fixes #1990
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Jan 23, 2020
1 parent 74b5ef6 commit 77ed524
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 86 deletions.
53 changes: 46 additions & 7 deletions Source/Xamarin/Prism.Forms/Navigation/INavigationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using System;
using System;
using System.Threading.Tasks;

namespace Prism.Navigation
Expand All @@ -12,23 +11,41 @@ public interface INavigationService
/// <summary>
/// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
/// </summary>
/// <returns>If <c>true</c> a go back operation was successful. If <c>false</c> the go back operation failed.</returns>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
Task<INavigationResult> GoBackAsync();

/// <summary>
/// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
/// </summary>
/// <param name="parameters">The navigation parameters</param>
/// <returns>If <c>true</c> a go back operation was successful. If <c>false</c> the go back operation failed.</returns>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
Task<INavigationResult> GoBackAsync(INavigationParameters parameters);

/// <summary>
/// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
/// </summary>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If set to <c>true</c>, or <c>false</c>, it will explicitly control whether or not to use Modal Navigation. Otherwise Prism will determine the proper context.</param>
/// <param name="animated">If <c>true</c>, animations will be enabled for the pop.</param>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
/// <remarks>You shouldn't need to use this. If you have to explicitly set <paramref name="useModalNavigation"/>, please file a bug.</remarks>
Task<INavigationResult> GoBackAsync(INavigationParameters parameters, bool? useModalNavigation, bool animated);

/// <summary>
/// Pops back to the root of the current context.
/// </summary>
/// <param name="parameters">The navigation parameters</param>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
Task<INavigationResult> GoBackToRootAsync(INavigationParameters parameters);

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri to navigate to</param>
/// <remarks>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
/// <remarks>Navigation parameters can be provided in the Uri.</remarks>
/// <example>
/// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
/// Navigate(new Uri("MainPage?id=3&amp;name=brian", UriKind.RelativeSource), parameters);
/// </example>
Task<INavigationResult> NavigateAsync(Uri uri);

Expand All @@ -37,15 +54,17 @@ public interface INavigationService
/// </summary>
/// <param name="uri">The Uri to navigate to</param>
/// <param name="parameters">The navigation parameters</param>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
/// <remarks>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
/// <example>
/// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
/// Navigate(new Uri("MainPage?id=3&amp;name=brian", UriKind.RelativeSource), parameters);
/// </example>
Task<INavigationResult> NavigateAsync(Uri uri, INavigationParameters parameters);

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
/// <param name="name">The name of the target to navigate to.</param>
Task<INavigationResult> NavigateAsync(string name);

Expand All @@ -55,5 +74,25 @@ public interface INavigationService
/// <param name="name">The name of the target to navigate to.</param>
/// <param name="parameters">The navigation parameters</param>
Task<INavigationResult> NavigateAsync(string name, INavigationParameters parameters);

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the target to navigate to.</param>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If set to <c>true</c>, or <c>false</c>, it will explicitly control whether or not to use Modal Navigation. Otherwise Prism will determine the proper context.</param>
/// <param name="animated">If <c>true</c>, animations will be enabled for the pop.</param>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
Task<INavigationResult> NavigateAsync(string name, INavigationParameters parameters, bool? useModalNavigation, bool animated);

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri to navigate to</param>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If set to <c>true</c>, or <c>false</c>, it will explicitly control whether or not to use Modal Navigation. Otherwise Prism will determine the proper context.</param>
/// <param name="animated">If <c>true</c>, animations will be enabled for the pop.</param>
/// <returns><see cref="INavigationResult" />. If the Success parameter is <c>true</c>, then the Page successfully was popped. Otherwise you may have an Exception in the result.</returns>
Task<INavigationResult> NavigateAsync(Uri uri, INavigationParameters parameters, bool? useModalNavigation, bool animated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,6 @@ namespace Prism.Navigation
{
public static class INavigationServiceExtensions
{
/// <summary>
/// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
/// </summary>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
/// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
/// <returns><see cref="INavigationResult"/> indicating whether the request was successful or if there was an encountered <see cref="Exception"/>.</returns>
public static Task<INavigationResult> GoBackAsync(this INavigationService navigationService, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true)
{
return ((IPlatformNavigationService)navigationService).GoBackAsync(parameters, useModalNavigation, animated);
}

/// <summary>
/// When navigating inside a NavigationPage: Pops all but the root Page off the navigation stack
/// </summary>
/// <param name="navigationService">The INavigatinService instance</param>
/// <param name="parameters">The navigation parameters</param>
/// <returns><see cref="INavigationResult"/> indicating whether the request was successful or if there was an encountered <see cref="Exception"/>.</returns>
/// <remarks>Only works when called from a View within a NavigationPage</remarks>
public static Task<INavigationResult> GoBackToRootAsync(this INavigationService navigationService, INavigationParameters parameters = null)
{
return ((IPlatformNavigationService)navigationService).GoBackToRootAsync(parameters);
}

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the target to navigate to.</param>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If <c>true</c> uses PushModalAsync, if <c>false</c> uses PushAsync</param>
/// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
/// <returns><see cref="INavigationResult"/> indicating whether the request was successful or if there was an encountered <see cref="Exception"/>.</returns>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, string name, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true)
{
return ((IPlatformNavigationService)navigationService).NavigateAsync(name, parameters, useModalNavigation, animated);
}

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri to navigate to</param>
/// <param name="parameters">The navigation parameters</param>
/// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
/// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
/// <returns><see cref="INavigationResult"/> indicating whether the request was successful or if there was an encountered <see cref="Exception"/>.</returns>
/// <remarks>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
/// <example>
/// NavigateAsync(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
/// </example>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, Uri uri, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true)
{
return ((IPlatformNavigationService)navigationService).NavigateAsync(uri, parameters, useModalNavigation, animated);
}

/// <summary>
/// Gets an absolute path of the current page as it relates to it's position in the navigation stack.
/// </summary>
Expand Down

This file was deleted.

27 changes: 18 additions & 9 deletions Source/Xamarin/Prism.Forms/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Behaviors;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Logging;
Expand All @@ -13,7 +13,7 @@ namespace Prism.Navigation
/// <summary>
/// Provides page based navigation for ViewModels.
/// </summary>
public class PageNavigationService : INavigationService, IPlatformNavigationService, IPageAware
public class PageNavigationService : INavigationService, IPageAware
{
internal const string RemovePageRelativePath = "../";
internal const string RemovePageInstruction = "__RemovePage/";
Expand All @@ -23,15 +23,24 @@ public class PageNavigationService : INavigationService, IPlatformNavigationServ
protected internal static PageNavigationSource NavigationSource { get; protected set; } = PageNavigationSource.Device;

private readonly IContainerProvider _container;

/// <summary>
/// The <see cref="IApplicationProvider" /> to access the Application MainPage
/// </summary>
protected readonly IApplicationProvider _applicationProvider;

/// <summary>
/// The <see cref="IPageBehaviorFactory" /> to apply application wide Behaviors for the given page.
/// </summary>
protected readonly IPageBehaviorFactory _pageBehaviorFactory;

protected readonly ILoggerFacade _logger;

protected Page _page;
Page IPageAware.Page
{
get { return _page; }
set { _page = value; }
get => _page;
set => _page = value;
}

public PageNavigationService(IContainerExtension container, IApplicationProvider applicationProvider, IPageBehaviorFactory pageBehaviorFactory, ILoggerFacade logger)
Expand Down Expand Up @@ -61,7 +70,7 @@ public virtual Task<INavigationResult> GoBackAsync(INavigationParameters paramet
return GoBackInternal(parameters, null, true);
}

Task<INavigationResult> IPlatformNavigationService.GoBackAsync(INavigationParameters parameters, bool? useModalNavigation, bool animated)
public virtual Task<INavigationResult> GoBackAsync(INavigationParameters parameters, bool? useModalNavigation, bool animated)
{
return GoBackInternal(parameters, useModalNavigation, animated);
}
Expand Down Expand Up @@ -165,15 +174,14 @@ private static bool IsMainPage(Page currentPage, Page mainPage)
return false;
}

Task<INavigationResult> IPlatformNavigationService.GoBackToRootAsync(INavigationParameters parameters)
public virtual Task<INavigationResult> GoBackToRootAsync(INavigationParameters parameters)
{
return GoBackToRootInternal(parameters);
}

/// <summary>
/// When navigating inside a NavigationPage: Pops all but the root Page off the navigation stack
/// </summary>
/// <param name="navigationService">The INavigatinService instance</param>
/// <param name="parameters">The navigation parameters</param>
/// <remarks>Only works when called from a View within a NavigationPage</remarks>
protected async virtual Task<INavigationResult> GoBackToRootInternal(INavigationParameters parameters)
Expand Down Expand Up @@ -239,7 +247,7 @@ public virtual Task<INavigationResult> NavigateAsync(string name, INavigationPar
return NavigateInternal(name, parameters, null, true);
}

Task<INavigationResult> IPlatformNavigationService.NavigateAsync(string name, INavigationParameters parameters, bool? useModalNavigation, bool animated)
public virtual Task<INavigationResult> NavigateAsync(string name, INavigationParameters parameters, bool? useModalNavigation, bool animated)
{
return NavigateInternal(name, parameters, useModalNavigation, animated);
}
Expand Down Expand Up @@ -286,7 +294,8 @@ public virtual Task<INavigationResult> NavigateAsync(Uri uri, INavigationParamet
return NavigateInternal(uri, parameters, null, true);
}

Task<INavigationResult> IPlatformNavigationService.NavigateAsync(Uri uri, INavigationParameters parameters, bool? useModalNavigation, bool animated)

public virtual Task<INavigationResult> NavigateAsync(Uri uri, INavigationParameters parameters, bool? useModalNavigation, bool animated)
{
return NavigateInternal(uri, parameters, useModalNavigation, animated);
}
Expand Down

0 comments on commit 77ed524

Please sign in to comment.