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

Add change presentation hints to Forms to allow pop #2412

Merged
merged 4 commits into from
Nov 29, 2017

Conversation

martijn00
Copy link
Contributor

@martijn00 martijn00 commented Nov 27, 2017

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

Feature

⤵️ What is the current behavior?

🆕 What is the new behavior (if this is a feature change)?

You can pop and pop to root in Forms

💥 Does this PR introduce a breaking change?

No

🐛 Recommendations for testing

Playground app

📝 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)
  • Rebased onto current develop

@martijn00 martijn00 added this to the 5.5.1 milestone Nov 27, 2017
using System;
using MvvmCross.Core.ViewModels;

namespace MvvmCross.Forms.Views.Hints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the hint is located in this namespace, and a user has defined all ViewModels in a separate dll from the views, then the hint won't be available.

I guess this kind of makes sense because the hint uses the View type, but then again... I'm not sure if it's a good practise to request presentation changes at a platform level.

Maybe the hint can take a ViewModel type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nico here. Hints should probably be platform agnostic so they can be used anywhere no matter whether you use forms or not.

using System;
using MvvmCross.Core.ViewModels;

namespace MvvmCross.Forms.Views.Hints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about this presentation hint

@Cheesebaron Cheesebaron added the p/forms Xamarin.Forms platform label Nov 27, 2017
@martijn00
Copy link
Contributor Author

@Cheesebaron @nmilcoff Can you do another review?

Close((hint as MvxClosePresentationHint).ViewModelToClose);
var host = GetHostPageOfType<NavigationPage>();
var page = host.Navigation.NavigationStack.OfType<IMvxPage>().FirstOrDefault(x => x.ViewModel.GetType() == removeHint.ViewModelToRemove) as Page;
host.Navigation.RemovePage(page);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does RemovePage handle cases when page == null?

{
Close((hint as MvxClosePresentationHint).ViewModelToClose);
var host = GetHostPageOfType<NavigationPage>();
var page = host.Navigation.NavigationStack.OfType<IMvxPage>().FirstOrDefault(x => x.ViewModel.GetType() == removeHint.ViewModelToRemove) as Page;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chain is awfully long. Also x is not very descriptive.

if (HandlePresentationChange(hint)) return;

if (hint is MvxClosePresentationHint)
if (hint is MvxPopToRootPresentationHint popToRootHint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetHostPageOfType<NavigationPage>() is used in all the if statements. Can you just call this once and reuse?

if (page is IMvxPage mvxPage && mvxPage.ViewModel.GetType() == popHint.ViewModelToPopTo)
{
page.Navigation.PopAsync(popHint.Animated);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloud be return;

page.Navigation.PopAsync(popHint.Animated);
break;
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant else as there is a break; above

@martijn00 martijn00 merged commit cce14f7 into MvvmCross:develop Nov 29, 2017
@martijn00 martijn00 deleted the forms-hints branch December 11, 2017 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/forms Xamarin.Forms platform
Development

Successfully merging this pull request may close these issues.

3 participants