Skip to content
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

Merged
merged 27 commits into from Nov 23, 2017

Conversation

nickrandolph
Copy link
Contributor

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Bug fix

⤵️ What is the current behavior?

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

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated (docs style guide)
  • Nuspec files were updated (when applicable)
  • [ X ] Rebased onto current develop

@@ -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)))
Copy link
Contributor

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)
Copy link
Contributor

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};
Copy link
Contributor

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)
Copy link
Contributor

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?

@nickrandolph
Copy link
Contributor Author

@martijn00, @Cheesebaron hey let me know thoughts on this PR and what needs to be changed/done to get this approved.

@martijn00 martijn00 added this to the 5.5.0 milestone Nov 21, 2017

namespace MvvmCross.Forms.Droid.Platform
{
public abstract class MvxFormsAndroidSetup : MvxAndroidSetup
public abstract class MvxFormsAndroidSetup<TForms> : MvxAndroidSetup
Copy link
Contributor

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?

Copy link
Contributor Author

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>
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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) };
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

@martijn00
Copy link
Contributor

martijn00 commented Nov 21, 2017

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?

@nickrandolph
Copy link
Contributor Author

A couple of questions/comments:

  • Can you be specific on the changes to modal navigation - I tried to make it more consistent as there were cases where it wouldn't show a modal, or when the modal was closed it didn't go back to the master detail
  • I'll fix the issue with the icon
  • The disabled buttons are actually due to a Delay that's in the Initialize method in one of the view models. Should this prevent navigation until this has completed?

@martijn00 martijn00 merged commit d9d6ed8 into MvvmCross:develop Nov 23, 2017
@nickrandolph nickrandolph deleted the btr-masterdetail-forms branch January 13, 2018 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants