diff --git a/Source/Windows10/Prism.Windows/Navigation/INavigationServiceExtensions.cs b/Source/Windows10/Prism.Windows/Navigation/INavigationServiceExtensions.cs index 1763c9d936..923551975f 100644 --- a/Source/Windows10/Prism.Windows/Navigation/INavigationServiceExtensions.cs +++ b/Source/Windows10/Prism.Windows/Navigation/INavigationServiceExtensions.cs @@ -53,5 +53,30 @@ public static Task NavigateAsync(this INavigationService serv public static Task NavigateAsync(this INavigationService service, Uri path, INavigationParameters parameter, NavigationTransitionInfo infoOverride) => (service as IPlatformNavigationService).NavigateAsync(path, parameter, infoOverride); + + public static Task GoBackAsync(this INavigationService navigationService, params (string Key, object Value)[] parameters) + { + return navigationService.GoBackAsync(GetNavigationParameters(parameters)); + } + + public static Task NavigateAsync(this INavigationService navigationService, string name, params (string Key, object Value)[] parameters) + { + return navigationService.NavigateAsync(name, GetNavigationParameters(parameters)); + } + + public static Task 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; + } } } diff --git a/Source/Xamarin/Prism.Forms.Tests/Services/PageDialogServiceFixture.cs b/Source/Xamarin/Prism.Forms.Tests/Services/PageDialogServiceFixture.cs index fb015183bd..8e6b890a15 100644 --- a/Source/Xamarin/Prism.Forms.Tests/Services/PageDialogServiceFixture.cs +++ b/Source/Xamarin/Prism.Forms.Tests/Services/PageDialogServiceFixture.cs @@ -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() { diff --git a/Source/Xamarin/Prism.Forms/Navigation/INavigationServiceExtensions.cs b/Source/Xamarin/Prism.Forms/Navigation/INavigationServiceExtensions.cs index 726ddf47b6..4da03684d4 100644 --- a/Source/Xamarin/Prism.Forms/Navigation/INavigationServiceExtensions.cs +++ b/Source/Xamarin/Prism.Forms/Navigation/INavigationServiceExtensions.cs @@ -16,7 +16,7 @@ public static class INavigationServiceExtensions /// The navigation parameters /// If true uses PopModalAsync, if false uses PopAsync /// If true the transition is animated, if false there is no animation on transition. - /// If true a go back operation was successful. If false the go back operation failed. + /// indicating whether the request was successful or if there was an encountered . public static Task GoBackAsync(this INavigationService navigationService, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true) { return ((IPlatformNavigationService)navigationService).GoBackAsync(parameters, useModalNavigation, animated); @@ -27,6 +27,7 @@ public static Task GoBackAsync(this INavigationService naviga /// /// The INavigatinService instance /// The navigation parameters + /// indicating whether the request was successful or if there was an encountered . /// Only works when called from a View within a NavigationPage public static Task GoBackToRootAsync(this INavigationService navigationService, INavigationParameters parameters = null) { @@ -40,6 +41,7 @@ public static Task GoBackToRootAsync(this INavigationService /// The navigation parameters /// If true uses PushModalAsync, if false uses PushAsync /// If true the transition is animated, if false there is no animation on transition. + /// indicating whether the request was successful or if there was an encountered . public static Task NavigateAsync(this INavigationService navigationService, string name, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true) { return ((IPlatformNavigationService)navigationService).NavigateAsync(name, parameters, useModalNavigation, animated); @@ -52,9 +54,10 @@ public static Task NavigateAsync(this INavigationService navi /// The navigation parameters /// If true uses PopModalAsync, if false uses PopAsync /// If true the transition is animated, if false there is no animation on transition. + /// indicating whether the request was successful or if there was an encountered . /// Navigation parameters can be provided in the Uri and by using the . /// - /// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters); + /// NavigateAsync(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters); /// public static Task NavigateAsync(this INavigationService navigationService, Uri uri, INavigationParameters parameters = null, bool? useModalNavigation = null, bool animated = true) { @@ -81,10 +84,59 @@ public static string GetNavigationUriPath(this INavigationService navigationServ return sb.ToString(); } + /// + /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. + /// + /// The navigation parameters + /// indicating whether the request was successful or if there was an encountered . + public static Task GoBackAsync(this INavigationService navigationService, params (string Key, object Value)[] parameters) + { + return navigationService.GoBackAsync(GetNavigationParameters(parameters)); + } + + /// + /// Initiates navigation to the target specified by the . + /// + /// The Uri to navigate to + /// The navigation parameters + /// indicating whether the request was successful or if there was an encountered . + /// Navigation parameters can be provided in the Uri and by using the . + /// + /// NavigateAsync("MainPage?id=3&name=dan", ("person", person), ("foo", bar)); + /// + public static Task NavigateAsync(this INavigationService navigationService, string name, params (string Key, object Value)[] parameters) + { + return navigationService.NavigateAsync(name, GetNavigationParameters(parameters)); + } + + /// + /// Initiates navigation to the target specified by the . + /// + /// The Uri to navigate to + /// The navigation parameters + /// indicating whether the request was successful or if there was an encountered . + /// Navigation parameters can be provided in the Uri and by using the . + /// + /// NavigateAsync(new Uri("MainPage?id=3&name=dan", UriKind.RelativeSource), ("person", person), ("foo", bar)); + /// + public static Task 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 stack) { - var parent = page.Parent as Page; - if (parent != null) + if (page.Parent is Page parent) { if (parent is NavigationPage) { @@ -203,8 +255,7 @@ private static Page ProcessCurrentPageNavigationPath(Page page, Stack 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()); diff --git a/Source/Xamarin/Prism.Forms/Services/PageDialogService/ActionSheetButton.cs b/Source/Xamarin/Prism.Forms/Services/PageDialogService/ActionSheetButton.cs index 3193f4c321..fc52a0368b 100644 --- a/Source/Xamarin/Prism.Forms/Services/PageDialogService/ActionSheetButton.cs +++ b/Source/Xamarin/Prism.Forms/Services/PageDialogService/ActionSheetButton.cs @@ -43,6 +43,13 @@ public static IActionSheetButton CreateCancelButton(string text, ICommand comman return CreateButtonInternal(text, null, isCancel: true, command: command); } + /// + /// Create a new instance of that display as "cancel button" + /// + /// Button text + /// An instance of + public static IActionSheetButton CreateCancelButton(string text) => CreateCancelButton(text, default(Action)); + /// /// Create a new instance of that display as "cancel button" /// @@ -93,6 +100,13 @@ public static IActionSheetButton CreateDestroyButton(string text, ICommand comma return CreateButtonInternal(text, null, isDestroy: true, command: command); } + /// + /// Create a new instance of that display as "destroy button" + /// + /// Button text + /// An instance of + public static IActionSheetButton CreateDestroyButton(string text) => CreateDestroyButton(text, default(Action)); + /// /// Create a new instance of that display as "destroy button" ///