diff --git a/src/Blauhaus.MVVM.Abstractions/Dialogs/IDialogService.cs b/src/Blauhaus.MVVM.Abstractions/Dialogs/IDialogService.cs index 7f7e710..8e0675c 100644 --- a/src/Blauhaus.MVVM.Abstractions/Dialogs/IDialogService.cs +++ b/src/Blauhaus.MVVM.Abstractions/Dialogs/IDialogService.cs @@ -7,6 +7,7 @@ public interface IDialogService Task DisplayAlertAsync(string title, string message, string cancelButtonText = "OK"); Task DisplayConfirmationAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK"); Task DisplayActionSheetAsync(string title, string cancel, string destruction, params string[] buttons); + Task DisplayPromptAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK"); } } \ No newline at end of file diff --git a/src/Blauhaus.MVVM.Maui/Services/MauiDialogService.cs b/src/Blauhaus.MVVM.Maui/Services/MauiDialogService.cs index 87932e0..78af10a 100644 --- a/src/Blauhaus.MVVM.Maui/Services/MauiDialogService.cs +++ b/src/Blauhaus.MVVM.Maui/Services/MauiDialogService.cs @@ -29,4 +29,12 @@ public async Task DisplayActionSheetAsync(string title, string cancel, s return await Application.Current.MainPage.DisplayActionSheet(title, cancel, destruction, FlowDirection.MatchParent, buttons); } + + public async Task DisplayPromptAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK") + { + if (Application.Current is null) throw new InvalidOperationException("Current application is null"); + if (Application.Current.MainPage is null) throw new InvalidOperationException("Current main application page is null"); + + return await Application.Current.MainPage.DisplayPromptAsync(title, message, acceptButtonText, cancelButtonText); + } } \ No newline at end of file diff --git a/src/Blauhaus.MVVM.TestHelpers/MockBuilders/Services/DialogServiceMockBuilder.cs b/src/Blauhaus.MVVM.TestHelpers/MockBuilders/Services/DialogServiceMockBuilder.cs index 6180184..b267343 100644 --- a/src/Blauhaus.MVVM.TestHelpers/MockBuilders/Services/DialogServiceMockBuilder.cs +++ b/src/Blauhaus.MVVM.TestHelpers/MockBuilders/Services/DialogServiceMockBuilder.cs @@ -17,6 +17,12 @@ public DialogServiceMockBuilder Where_DisplayConfirmationAsync_returns(bool resu .ReturnsAsync(result); return this; } + public DialogServiceMockBuilder Where_DisplayPromptAsync_returns(string? result) + { + Mock.Setup(x => x.DisplayPromptAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(result); + return this; + } public void Verify_DisplayAlert_called(string title, string message, string accept) { diff --git a/src/Blauhaus.MVVM.Xamarin/Dialogs/FormsDialogService.cs b/src/Blauhaus.MVVM.Xamarin/Dialogs/FormsDialogService.cs index 9a0ad58..3f741bb 100644 --- a/src/Blauhaus.MVVM.Xamarin/Dialogs/FormsDialogService.cs +++ b/src/Blauhaus.MVVM.Xamarin/Dialogs/FormsDialogService.cs @@ -35,5 +35,11 @@ public Task DisplayActionSheetAsync(string title, string cancel, string return _threadService.InvokeOnMainThreadAsync(async () => await _application .DisplayActionSheetAsync(title, cancel, destruction, buttons)); } + + public Task DisplayPromptAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK") + { + return _threadService.InvokeOnMainThreadAsync(async () => await _application + .DisplayPromptAsync(title, message, cancelButtonText, acceptButtonText)); + } } } \ No newline at end of file diff --git a/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/FormsApplicationProxy.cs b/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/FormsApplicationProxy.cs index 9dc64a1..0246df5 100644 --- a/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/FormsApplicationProxy.cs +++ b/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/FormsApplicationProxy.cs @@ -25,9 +25,10 @@ public Task DisplayActionSheetAsync(string title, string cancel, string return Application.Current.MainPage.DisplayActionSheet(title, cancel, destruction, buttons); } - public Task GoToAsync(string route, bool animate) + public Task DisplayPromptAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK") { - return Shell.Current.GoToAsync(route, animate); + return Application.Current.MainPage.DisplayPromptAsync(title, message, acceptButtonText, cancelButtonText); } + } } \ No newline at end of file diff --git a/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/IFormsApplicationProxy.cs b/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/IFormsApplicationProxy.cs index 17ad6e5..f1c75df 100644 --- a/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/IFormsApplicationProxy.cs +++ b/src/Blauhaus.MVVM.Xamarin/Navigation/FormsApplicationProxy/IFormsApplicationProxy.cs @@ -9,5 +9,7 @@ public interface IFormsApplicationProxy Task DisplayAlertAsync(string title, string message, string cancel, string accept); Task DisplayAlertAsync(string title, string message, string cancel); Task DisplayActionSheetAsync(string title, string cancel, string destruction, params string[] buttons); + Task DisplayPromptAsync(string title, string message, string cancelButtonText = "Cancel", string acceptButtonText = "OK"); + } } \ No newline at end of file