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
Fixing Master-Detail Forms implementation #2387
Fixing Master-Detail Forms implementation #2387
Conversation
@@ -199,6 +200,42 @@ public virtual bool CloseCarouselPage(IMvxViewModel viewModel, MvxCarouselPagePr | |||
} | |||
} | |||
|
|||
public virtual MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType) | |||
{ | |||
if (viewType.GetTypeInfo().IsSubclassOf(typeof(ContentPage))) |
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.
We might be able to use this directly again on .NET Standard.
// If this page is to be the master, the default behaviour should be that the page is not wrapped | ||
// in a navigation page. This is not the case for Root or Detail pages where default behaviour | ||
// would be to support navigation | ||
if (position == MasterDetailPosition.Master) |
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.
Good catch
masterDetailHost.Detail = page; | ||
else | ||
masterDetailHost.Detail = new MvxNavigationPage(new MvxContentPage() { Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage) }); | ||
|
||
PushOrReplacePage(FormsApplication.MainPage, masterDetailHost, attribute); | ||
var masterDetailRootAttribute = new MvxMasterDetailPagePresentationAttribute {Position = MasterDetailPosition.Root, WrapInNavigationPage = attribute.WrapInNavigationPage, NoHistory = attribute.NoHistory}; |
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 means that we enforce this? Is it really necessary?
@@ -552,6 +607,31 @@ public virtual bool ClosePage(Page rootPage, Page page, MvxPagePresentationAttri | |||
return rootPage as TPage; | |||
} | |||
|
|||
public virtual void ReplaceMasterDetailRoot(Page existingMasterDetailPage, Page newRootPage, MvxMasterDetailPagePresentationAttribute masterDetailAttribute) |
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 understand what this tries to solve. Can you explain the thought behind it?
bedde7d
to
6b8df42
Compare
@martijn00, @Cheesebaron hey let me know thoughts on this PR and what needs to be changed/done to get this approved. |
|
||
namespace MvvmCross.Forms.Droid.Platform | ||
{ | ||
public abstract class MvxFormsAndroidSetup : MvxAndroidSetup | ||
public abstract class MvxFormsAndroidSetup<TForms> : MvxAndroidSetup |
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.
Why does this need to add a generic? I don't see any value?
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'd suggest I revert to non-generic and that we have a separate generic version of the setup class.
</Reference> | ||
<Reference Include="Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Xamarin.Forms.2.4.0.74863\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath> | ||
<HintPath>..\..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath> |
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.
We should update the nuspec as well if this changes to 2.5
return _formsApplication; | ||
} | ||
} | ||
|
||
protected virtual MvxFormsApplication CreateFormsApplication() => new MvxFormsApplication(); | ||
protected virtual TForms CreateFormsApplication() => new TForms(); |
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.
Maybe we should make this abstract if it gives bugs?
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.
As per my other comment, I think we should revert this change. In the generic setup class the CreateFormsApplication can return a new instance of the generic TForms class
masterDetailHost.Detail = page; | ||
else | ||
masterDetailHost.Detail = new MvxNavigationPage(new MvxContentPage() { Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage) }); | ||
//if (attribute.Position == MasterDetailPosition.Master) |
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 remove any out commented code?
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.
Will do
{ | ||
if (page is MasterDetailPage masterDetailRoot) | ||
{ | ||
if (masterDetailRoot.Master == null) | ||
masterDetailRoot.Master = new MvxContentPage() { Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage) }; | ||
masterDetailRoot.Master = new ContentPage() { Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage) }; |
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.
Why change from using MvxContentPage
to ContentPage
?
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.
We were seeing issues where the View Model was being set on the MvxContentPage (passed down from parent to the Master page) which resulted in the OnAppearing method being called multiple times on the master detail root view model
@@ -0,0 +1,7 @@ | |||
namespace MvvmCross.Core.Platform.LogProviders | |||
{ | |||
internal sealed class NullLogProvider : MvxBaseLogProvider |
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 should be removed, and instead set the logger to None.
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.
Without this class, the None option for logging will break any code which requests ILogProvider as an injected value. Do you have another alternative to this?
public virtual void PushOrReplacePage(Page rootPage, Page page, MvxPagePresentationAttribute attribute) | ||
{ | ||
if (attribute.NoHistory) | ||
// Make sure we always have a rootPage |
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'm a bit unsure if this behaviour works in all situations. Can you confirm?
There is definitely some breaking changes in here in terms of behaviour. When testing the playground the modal navigation is different, and the master detail views don't show up with a toolbar with hamburger icon anymore. Also when navigating and coming back the buttons stay disabled. I didn't notice these things before so i think there might be some bugs in here. PS, can you do a rebase? |
A couple of questions/comments:
|
…ctoring the presenters
Fixing UWP sample to resolve forms presenter
Switching to using injected NavigationPage and ContentPage instead of MVX equivalents
Code cleanup
Removing default content in navigationpage for details
… HasNavigationBar is set to false before first navigation
a0592ea
to
1566f42
Compare
…ive setup class which accepts generics to make it easier for developers to get started with Forms
Removing NullLogProvider Fixed packages.config (again)
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Bug fix
Master Details didn't really work using attributes
🆕 What is the new behavior (if this is a feature change)?
Master Details works - 2 scenarios
Define only Master and Detail pages/view models - automatically generates the MasterDetailsPage
Define Root page/view model where the page inherits from MasterDetailsPage
💥 Does this PR introduce a breaking change?
No
🐛 Recommendations for testing
Playground sample now works for Master-Detail
📝 Links to relevant issues/docs
🤔 Checklist before submitting