-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement DialogView for Uap #3074
Conversation
@nickrandolph can you have a look at why the playground doesn't start? |
@@ -23,6 +23,9 @@ public class MvxWindowsViewPresenter | |||
{ | |||
protected readonly IMvxWindowsFrame _rootFrame; | |||
|
|||
private MvxWindowsContentDialog mDialogView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid by any chance holding a strong reference to the dialog view here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to do it. You have access to the ViewModel, but not to the View.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't follow the naming conventions we use.
To run the Playground, throw this exception. I don't now if this error is reported. MvvmCross.Exceptions.MvxException Inner Exception 1: Inner Exception 2: Inner Exception 3: |
@@ -23,6 +23,9 @@ public class MvxWindowsViewPresenter | |||
{ | |||
protected readonly IMvxWindowsFrame _rootFrame; | |||
|
|||
private MvxWindowsContentDialog mDialogView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't follow the naming conventions we use.
try | ||
{ | ||
var modalAttribute = (MvxModalViewPresentationAttribute)attribute; | ||
var instanceReques = (MvxViewModelInstanceRequest)request; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this cast closer to usage. Also typo.
{ | ||
get | ||
{ | ||
return _viewModel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use Expression body
{ | ||
public new TViewModel ViewModel | ||
{ | ||
get { return (TViewModel)base.ViewModel; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expression body
@@ -240,5 +250,39 @@ protected virtual Task<bool> ShowPage(Type viewType, MvxBasePresentationAttribut | |||
return Task.FromResult(false); | |||
} | |||
} | |||
|
|||
protected virtual async Task<bool> ShowModal(Type viewType, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you pass in MvxModalViewPresentationAttribute as type?
{ | ||
if (Activator.CreateInstance(viewType) is MvxWindowsContentDialog modalView) | ||
{ | ||
var instanceReques = (MvxViewModelInstanceRequest)request; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
@@ -23,6 +23,8 @@ public class MvxWindowsViewPresenter | |||
{ | |||
protected readonly IMvxWindowsFrame _rootFrame; | |||
|
|||
private MvxWindowsContentDialog _windowsContentDialog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is good to keep an instance reference like this. We probably need something to find the view back in the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made.
|
||
protected virtual Task<bool> CloseModal(IMvxViewModel viewModel, MvxBasePresentationAttribute attribute) | ||
{ | ||
_windowsContentDialog?.Hide(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Hide correct, or do we really need to remove it as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's the right one. PrimaryButtonCommand can be invoked, but it's rare.
|
||
namespace MvvmCross.Platforms.Uap.Presenters.Attributes | ||
{ | ||
public sealed class MvxModalViewPresentationAttribute : MvxBasePresentationAttribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make it sealed
typeof(MvxModalViewPresentationAttribute), | ||
new MvxPresentationAttributeAction | ||
{ | ||
ShowAction = (view, attribute, request) => ShowModal(view, (MvxModalViewPresentationAttribute)attribute, (MvxViewModelInstanceRequest)request), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not cast to MvxViewModelInstanceRequest here, but in the method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why attribute yes and request no. What criterion do you have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
try | ||
{ | ||
if (Activator.CreateInstance(viewType) is MvxWindowsContentDialog modalView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a view creator for Windows? @nickrandolph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentDialog is created with the new command. But if you know another way to do it, propose it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way viewmodel events like prepare and Initialize are not triggered. If there is nothing for this on Windows yet we need to make it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ContentDialog not is a page. I can create a method to create the ContentDialog. I can't think of anything else.
|
||
protected virtual Task<bool> CloseModal(IMvxViewModel viewModel, MvxBasePresentationAttribute attribute) | ||
{ | ||
var popups = VisualTreeHelper.GetOpenPopups(Window.Current).FirstOrDefault(p => p.Child is ContentDialog); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for MvxWindowsContentDialog
to get a closer match. If possible also check the viewmodel type or something to make sure we don't close the wrong one when multiple modals are open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot open two ContentDialog at a time.
typeof(MvxModalViewPresentationAttribute), | ||
new MvxPresentationAttributeAction | ||
{ | ||
ShowAction = (view, attribute, request) => ShowModal(view, (MvxModalViewPresentationAttribute)attribute, (MvxViewModelInstanceRequest)request), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
try | ||
{ | ||
if (Activator.CreateInstance(viewType) is MvxWindowsContentDialog modalView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way viewmodel events like prepare and Initialize are not triggered. If there is nothing for this on Windows yet we need to make it.
{ | ||
if (Activator.CreateInstance(viewType) is MvxWindowsContentDialog modalView) | ||
{ | ||
modalView.ViewModel = request.ViewModelInstance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, you should not set the instance manually. It should be done from a helper or something.
@@ -256,14 +256,15 @@ protected virtual async Task<bool> ShowModal(Type viewType, MvxModalViewPresenta | |||
{ | |||
try | |||
{ | |||
if (Activator.CreateInstance(viewType) is MvxWindowsContentDialog modalView) | |||
IMvxWindowsContentDialog contentDialog; | |||
if ((contentDialog = CreateContentDialog(attribute, viewType)) != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split assignment and null check
I changed the modal name to dialog. A ContentDialog is not a modal window. And it can confuse. |
This is a sample for can use x:Bind in XAML. |
Is there anything left to do? Codefactor's warnings are for putting two classes in the same file. |
Apologies been unavailable to contribute. A quick glance - I think in the close method we should be confirming that the open dialogue is for the viewmodel being closed |
If it leaves you calmer. Here's the modification. But you can only open one ContentDialog per window. I'm trying to be able to open Standalone windows. And if you can open two ContentDialog. But they are placed in different visual trees. When you closed this change I send the window modal. I need help because you have to modify MvxWindowsMainThreadDispatcher. |
@andrechi1 @nickrandolph @Cheesebaron i've done a rebase and implemented the changes to get this merged in. |
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
New feature. Implement ModalView for Uap
I haven't been able to prove it well, because the Playground.Uwp project doesn't start.
🆕 What is the new behavior (if this is a feature change)?
💥 Does this PR introduce a breaking change?
🐛 Recommendations for testing
📝 Links to relevant issues/docs
🤔 Checklist before submitting