Skip to content

Commit

Permalink
Merge pull request PrismLibrary#1669 from PrismLibrary/api-enhancements
Browse files Browse the repository at this point in the history
API Enhancements
  • Loading branch information
brianlagunas authored Jan 23, 2019
2 parents b55b967 + 6506daf commit e7cecd0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,30 @@ public static Task<INavigationResult> NavigateAsync(this INavigationService serv

public static Task<INavigationResult> NavigateAsync(this INavigationService service, Uri path, INavigationParameters parameter, NavigationTransitionInfo infoOverride)
=> (service as IPlatformNavigationService).NavigateAsync(path, parameter, infoOverride);

public static Task<INavigationResult> GoBackAsync(this INavigationService navigationService, params (string Key, object Value)[] parameters)
{
return navigationService.GoBackAsync(GetNavigationParameters(parameters));
}

public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, string name, params (string Key, object Value)[] parameters)
{
return navigationService.NavigateAsync(name, GetNavigationParameters(parameters));
}

public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, Uri uri, params (string Key, object Value)[] parameters)
{
return navigationService.NavigateAsync(uri, GetNavigationParameters(parameters));
}

private static INavigationParameters GetNavigationParameters((string Key, object Value)[] parameters)
{
var navParams = new NavigationParameters();
foreach (var (Key, Value) in parameters)
{
navParams.Add(Key, Value);
}
return navParams;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ public PageDialogServiceFixture()
_applicationProvider = new ApplicationProviderMock();
}

[Fact]
public void CancelActionSheetButton_WithNoAction_DoNotThrowException()
{
var cancel = ActionSheetButton.CreateCancelButton("Foo");
var ex = Record.Exception(() => cancel.PressButton());
Assert.Null(ex);
}

[Fact]
public void DestroyActionSheetButton_WithNoAction_DoNotThrowException()
{
var destroy = ActionSheetButton.CreateDestroyButton("Foo");
var ex = Record.Exception(() => destroy.PressButton());
Assert.Null(ex);
}

[Fact]
public async Task DisplayActionSheetNoButtons_ShouldThrowException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class INavigationServiceExtensions
/// <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>If <c>true</c> a go back operation was successful. If <c>false</c> the go back operation failed.</returns>
/// <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);
Expand All @@ -27,6 +27,7 @@ public static Task<INavigationResult> GoBackAsync(this INavigationService naviga
/// </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)
{
Expand All @@ -40,6 +41,7 @@ public static Task<INavigationResult> GoBackToRootAsync(this INavigationService
/// <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);
Expand All @@ -52,9 +54,10 @@ public static Task<INavigationResult> NavigateAsync(this INavigationService navi
/// <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>
/// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
/// 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)
{
Expand All @@ -81,10 +84,59 @@ public static string GetNavigationUriPath(this INavigationService navigationServ
return sb.ToString();
}

/// <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><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, params (string Key, object Value)[] parameters)
{
return navigationService.GoBackAsync(GetNavigationParameters(parameters));
}

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <param name="name">The Uri to navigate to</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>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
/// <example>
/// NavigateAsync("MainPage?id=3&name=dan", ("person", person), ("foo", bar));
/// </example>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, string name, params (string Key, object Value)[] parameters)
{
return navigationService.NavigateAsync(name, GetNavigationParameters(parameters));
}

/// <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>
/// <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=dan", UriKind.RelativeSource), ("person", person), ("foo", bar));
/// </example>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, Uri uri, params (string Key, object Value)[] parameters)
{
return navigationService.NavigateAsync(uri, GetNavigationParameters(parameters));
}

private static INavigationParameters GetNavigationParameters((string Key, object Value)[] parameters)
{
var navParams = new NavigationParameters();
foreach(var (Key, Value) in parameters)
{
navParams.Add(Key, Value);
}
return navParams;
}

private static void ProcessNavigationPath(Page page, Stack<string> stack)
{
var parent = page.Parent as Page;
if (parent != null)
if (page.Parent is Page parent)
{
if (parent is NavigationPage)
{
Expand Down Expand Up @@ -203,8 +255,7 @@ private static Page ProcessCurrentPageNavigationPath(Page page, Stack<string> st
var currentPageKeyInfo = PageNavigationRegistry.GetPageNavigationInfo(page.GetType());
string currentSegment = $"{currentPageKeyInfo.Name}";

var parent = page.Parent as Page;
if (parent != null)
if (page.Parent is Page parent)
{
var parentKeyInfo = PageNavigationRegistry.GetPageNavigationInfo(parent.GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public static IActionSheetButton CreateCancelButton(string text, ICommand comman
return CreateButtonInternal(text, null, isCancel: true, command: command);
}

/// <summary>
/// Create a new instance of <see cref="ActionSheetButton"/> that display as "cancel button"
/// </summary>
/// <param name="text">Button text</param>
/// <returns>An instance of <see cref="ActionSheetButton"/></returns>
public static IActionSheetButton CreateCancelButton(string text) => CreateCancelButton(text, default(Action));

/// <summary>
/// Create a new instance of <see cref="ActionSheetButton"/> that display as "cancel button"
/// </summary>
Expand Down Expand Up @@ -93,6 +100,13 @@ public static IActionSheetButton CreateDestroyButton(string text, ICommand comma
return CreateButtonInternal(text, null, isDestroy: true, command: command);
}

/// <summary>
/// Create a new instance of <see cref="ActionSheetButton"/> that display as "destroy button"
/// </summary>
/// <param name="text">Button text</param>
/// <returns>An instance of <see cref="ActionSheetButton"/></returns>
public static IActionSheetButton CreateDestroyButton(string text) => CreateDestroyButton(text, default(Action));

/// <summary>
/// Create a new instance of <see cref="ActionSheetButton"/> that display as "destroy button"
/// </summary>
Expand Down

0 comments on commit e7cecd0

Please sign in to comment.