Skip to content

Commit

Permalink
Merge pull request #2888 from PrismLibrary/dev/ds/dialogs
Browse files Browse the repository at this point in the history
Dialog Consolidation
  • Loading branch information
dansiegel authored Aug 17, 2023
2 parents bf0966a + e72c6c4 commit 9f75a26
Show file tree
Hide file tree
Showing 102 changed files with 1,008 additions and 918 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>$(NoWarn);NU5104;NU5100;NU5118;NU5123;NU1603;CS1701;CS1702;XA0101;MSB3277;CS8785;CS8669;CS1998;NU1507</NoWarn>
<IsCoreProject>$(MSBuildProjectName.Equals('Prism.Core'))</IsCoreProject>
<IsCoreProject>false</IsCoreProject>
<IsCoreProject Condition=" $(MSBuildProjectName.Equals('Prism.Core')) OR $(MSBuildProjectName.Equals('Prism.Events'))">true</IsCoreProject>
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsWpfProject>$(MSBuildProjectName.Contains('Wpf'))</IsWpfProject>
<IsUnoProject>$(MSBuildProjectName.Contains('Uno'))</IsUnoProject>
Expand Down
14 changes: 5 additions & 9 deletions e2e/Forms/src/HelloDialog/ViewModels/DemoDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using Prism.Commands;
using System;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using Prism.Services.Dialogs;
using Prism.Navigation;
using Prism.AppModel;

namespace HelloDialog.ViewModels
{
public class DemoDialogViewModel : BindableBase, IDialogAware
{
public DemoDialogViewModel()
{
CloseCommand = new DelegateCommand(() => RequestClose(null));
CloseCommand = new DelegateCommand(() => RequestClose.Invoke());
}

private string title = "Message";
Expand All @@ -32,7 +28,7 @@ public string Message

public DelegateCommand CloseCommand { get; }

public event Action<IDialogParameters> RequestClose;
public DialogCloseListener RequestClose { get; }

public bool CanCloseDialog() => true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using Prism.Services;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;

namespace HelloDialog.ViewModels
{
Expand Down
12 changes: 5 additions & 7 deletions e2e/Forms/src/HelloDialog/ViewModels/UserAlertViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Prism.Commands;
using System;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;

namespace HelloDialog.ViewModels
{
Expand All @@ -24,15 +22,15 @@ public string Name

public DelegateCommand SubmitCommand { get; }

public event Action<IDialogParameters> RequestClose;
public DialogCloseListener RequestClose { get; }

private void ExecuteSubmitCommand()
{
var dialogParams = new DialogParameters
{
{ "name", Name }
};
RequestClose(dialogParams);
RequestClose.Invoke(dialogParams);
}

public bool CanCloseDialog()
Expand Down
4 changes: 2 additions & 2 deletions e2e/Forms/src/HelloWorld.Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]

// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
Expand Down
4 changes: 1 addition & 3 deletions e2e/Maui/MauiModule/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public string Name

public DelegateCommand LoginCommand { get; }

public DialogCloseEvent RequestClose { get; set; }

//public event Action<IDialogParameters> RequestClose;
public DialogCloseListener RequestClose { get; }

public bool CanCloseDialog() => _canClose;

Expand Down
6 changes: 4 additions & 2 deletions e2e/Uno/HelloWorld.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32210.308
MinimumVisualStudioVersion = 15.0.26124.0
Expand Down Expand Up @@ -39,7 +40,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{F67B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleA", "ModuleA\ModuleA.csproj", "{5AD22541-BC5D-45E0-9C95-87B51300FF1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prism.Events", "..\..\src\Prism.Events\Prism.Events.csproj", "{ABC0F8AF-6FED-4C3E-80B3-54F1A7CC5930}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Events", "..\..\src\Prism.Events\Prism.Events.csproj", "{ABC0F8AF-6FED-4C3E-80B3-54F1A7CC5930}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -444,6 +445,7 @@ Global
{8D59D64C-EAF1-4BF7-9E69-556114C96A95} = {2C5D7523-6030-4B75-ABE0-3CB8AA0953CB}
{F67BA438-F236-460B-B279-A71AB8033B54} = {5E74EB0D-FBD3-4399-8F38-AD888DEFFC73}
{5AD22541-BC5D-45E0-9C95-87B51300FF1C} = {F67BA438-F236-460B-B279-A71AB8033B54}
{ABC0F8AF-6FED-4C3E-80B3-54F1A7CC5930} = {2C5D7523-6030-4B75-ABE0-3CB8AA0953CB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {757C5D89-969E-4F38-B8F1-3098C8E17307}
Expand Down
2 changes: 1 addition & 1 deletion e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Services.Dialogs;
using Prism.Dialogs;
using System;

namespace HelloWorld.Core
Expand Down
2 changes: 1 addition & 1 deletion e2e/Wpf/HelloWorld/Dialogs/AnotherDialogWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Services.Dialogs;
using Prism.Dialogs;
using System.Windows;

namespace HelloWorld.Dialogs
Expand Down
2 changes: 1 addition & 1 deletion e2e/Wpf/HelloWorld/Dialogs/CustomDialogWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Services.Dialogs;
using Prism.Dialogs;
using System.Windows;

namespace HelloWorld.Dialogs
Expand Down
21 changes: 11 additions & 10 deletions e2e/Wpf/HelloWorld/Dialogs/DialogViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using Prism.Dialogs;
using System;

namespace HelloWorld.Dialogs
Expand All @@ -18,18 +18,19 @@ public string Title
set { SetProperty(ref _title, value); }
}

public event Action<IDialogResult> RequestClose;
public DialogCloseListener RequestClose { get; }

protected virtual void CloseDialog(string parameter)
{
ButtonResult result = ButtonResult.None;

if (parameter?.ToLower() == "true")
result = ButtonResult.OK;
else if (parameter?.ToLower() == "false")
result = ButtonResult.Cancel;

RequestClose?.Invoke(new DialogResult(result));
var result = parameter?.ToLower() switch
{
"true" => ButtonResult.OK,
"false" => ButtonResult.Cancel,
_ => ButtonResult.None
};

//RequestClose.Invoke(new DialogResult(result));
RequestClose.Invoke(result);
}

public virtual bool CanCloseDialog()
Expand Down
2 changes: 1 addition & 1 deletion e2e/Wpf/HelloWorld/Dialogs/NotificationDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Services.Dialogs;
using Prism.Dialogs;

namespace HelloWorld.Dialogs
{
Expand Down
2 changes: 1 addition & 1 deletion e2e/Wpf/HelloWorld/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using Prism.Dialogs;

namespace HelloWorld.ViewModels
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using Prism.Dialogs;
using HelloWorld.Core;

namespace HelloWorld.Modules.ModuleA.ViewModels
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Prism.Forms/Common/UriParsingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Prism.Dialogs;
using Prism.Navigation;
using Prism.Services.Dialogs;

namespace Prism.Common
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Xamarin.Forms;

namespace Prism.Services.Dialogs
namespace Prism.Dialogs
{
internal class DialogContainer : ContentView
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;

namespace Prism.Services.Dialogs
namespace Prism.Dialogs
{
internal class DialogPage : ContentPage, IDialogContainer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Linq;
using Prism.AppModel;
using System.Threading.Tasks;
using Prism.Common;
using Prism.Dialogs.Xaml;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services.Dialogs.Xaml;
using Xamarin.Forms;

namespace Prism.Services.Dialogs
namespace Prism.Dialogs
{
/// <summary>
/// Provides the ability to display dialogs from ViewModels.
Expand All @@ -35,7 +34,7 @@ public DialogService(IApplicationProvider applicationProvider, IContainerProvide
}

/// <inheritdoc/>
public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback)
public async void ShowDialog(string name, IDialogParameters parameters, DialogCallback callback)
{
try
{
Expand All @@ -47,21 +46,21 @@ public void ShowDialog(string name, IDialogParameters parameters, Action<IDialog
var currentPage = GetCurrentContentPage();

var dialogModal = new DialogPage();
dialogAware.RequestClose += DialogAware_RequestClose;

async void DialogAware_RequestClose(IDialogParameters outParameters)
DialogUtilities.InitializeListener(dialogAware, DialogAware_RequestClose);

async Task DialogAware_RequestClose(IDialogResult outResult)
{
try
{
var result = await CloseDialogAsync(outParameters ?? new DialogParameters(), currentPage, dialogModal);
var result = await CloseDialogAsync(outResult ?? new DialogResult(), currentPage, dialogModal);
dialogModal.RaiseDialogResult(result);
if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse)
{
return;
}

dialogAware.RequestClose -= DialogAware_RequestClose;
callback?.Invoke(result);
await callback.Invoke(result);
GC.Collect();
}
catch (DialogException dex)
Expand All @@ -75,7 +74,7 @@ async void DialogAware_RequestClose(IDialogParameters outParameters)

if (dex.Message != DialogException.CanCloseIsFalse)
{
callback?.Invoke(result);
await callback.Invoke(result);
}
}
catch (Exception ex)
Expand All @@ -86,7 +85,7 @@ async void DialogAware_RequestClose(IDialogParameters outParameters)
Parameters = parameters
};
dialogModal.RaiseDialogResult(result);
callback?.Invoke(result);
await callback.Invoke(result);
}
}

Expand All @@ -99,27 +98,33 @@ async void DialogAware_RequestClose(IDialogParameters outParameters)
}
}

InsertPopupViewInCurrentPage(currentPage as ContentPage, dialogModal, view, closeOnBackgroundTapped, DialogAware_RequestClose);
InsertPopupViewInCurrentPage(currentPage as ContentPage, dialogModal, view, closeOnBackgroundTapped, dialogAware.RequestClose);

PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(currentPage, aa => aa.IsActive = false);
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(view, aa => aa.IsActive = true);
}
catch (Exception ex)
{
var error = ex.ToString();
callback?.Invoke(new DialogResult { Exception = ex });
await callback.Invoke(new DialogResult { Exception = ex });
}
}

private async System.Threading.Tasks.Task<IDialogResult> CloseDialogAsync(IDialogParameters parameters, ContentPage currentPage, DialogPage dialogModal)
private async System.Threading.Tasks.Task<IDialogResult> CloseDialogAsync(IDialogResult result, ContentPage currentPage, DialogPage dialogModal)
{
try
{
PageNavigationService.NavigationSource = PageNavigationSource.DialogService;

if (parameters is null)
result ??= new DialogResult();
if (result.Parameters is null)
{
parameters = new DialogParameters();
result = new DialogResult
{
Exception = result.Exception,
Parameters = new DialogParameters(),
Result = result.Result
};
}

var view = dialogModal.DialogView;
Expand All @@ -136,10 +141,7 @@ private async System.Threading.Tasks.Task<IDialogResult> CloseDialogAsync(IDialo
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(currentPage, aa => aa.IsActive = true);
dialogAware.OnDialogClosed();

return new DialogResult
{
Parameters = parameters
};
return result;
}
catch (DialogException)
{
Expand All @@ -150,7 +152,8 @@ private async System.Threading.Tasks.Task<IDialogResult> CloseDialogAsync(IDialo
return new DialogResult
{
Exception = ex,
Parameters = parameters
Parameters = result.Parameters,
Result = result.Result
};
}
finally
Expand Down Expand Up @@ -247,7 +250,7 @@ private ContentPage GetCurrentPage(Page page = null)
}
}

private async void InsertPopupViewInCurrentPage(ContentPage currentPage, DialogPage modalPage, View popupView, bool hideOnBackgroundTapped, Action<IDialogParameters> callback)
private async void InsertPopupViewInCurrentPage(ContentPage currentPage, DialogPage modalPage, View popupView, bool hideOnBackgroundTapped, DialogCloseListener closeEvent)
{
View mask = DialogLayout.GetMask(popupView);

Expand All @@ -264,7 +267,7 @@ private async void InsertPopupViewInCurrentPage(ContentPage currentPage, DialogP
mask.SetBinding(VisualElement.WidthRequestProperty, new Binding { Path = "Width", Source = modalPage });
mask.SetBinding(VisualElement.HeightRequestProperty, new Binding { Path = "Height", Source = modalPage });

var dismissCommand = new Command(() => callback(new DialogParameters()));
var dismissCommand = new Command(closeEvent.Invoke);
if (hideOnBackgroundTapped)
{
mask.GestureRecognizers.Add(new TapGestureRecognizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Windows.Input;
using Xamarin.Forms;

namespace Prism.Services.Dialogs
namespace Prism.Dialogs
{
public interface IDialogContainer
{
Expand Down
Loading

0 comments on commit 9f75a26

Please sign in to comment.