MvvMCross moves multiple view / truncate navigation stacks

I have two questions regarding navigation in MvvMCross.

  • How to return to the view model in the navigation stack? Accordingly: How can I return to the specified number of viewing models?
  • How can I crop the navigation stack?

    for example: A | B | C on the stack, going to D makes the stack look like: D

+4
source share
2 answers

The functionality for controlling the rear stack depends on the platform and application - for example:

  • these are very different manipulations with the backstack of Android activity than iOS UINavigation controller one
  • It depends on whether your application uses tabs, actions, fragments, pop-ups, modals, hamburger menus, etc.

Because of this, the actual implementation of user interface changes like this is not defined in MvvmCross.

Instead, you need to implement presenter in your applications.

The main thread you need to execute is as follows:

  • Find out what the structure of your application is and what effects you want to achieve.

  • For this effect, declare a custom presentation hint - for example,

  public class MyFunkyPresentationHint : MvxPresentationHint { public int DegreeOfFunkiness { get; set; } } 
  1. You can create and send this tooltip from any ViewModel
  base.ChangePresentation(new MyFunkyPresentationHint() { DegreeOfFunkiness=27 }); 
  1. In your custom presenter, you can execute the required hacking-backstack-screen:
  public override void ChangePresentation(MvxPresentationHint hint) { if (hint is MyFunkyPresentationHint) { // your code goes here return; } base.ChangePresentation(hint); } 

For examples of custom speakers, see: http://slodge.blogspot.com/2013/06/presenter-roundup.html

For one example of Backstack processing, see how Close(this) is implemented in some standard presenters.

+8
source

There is a good article with information to do this here . This applies to navigation based on iOS and Android. There is no situation that is based on activity. In this particular case, the androidโ€™s intentions can help add a few flags to it.

 private class CustomPresenter : MvxAndroidViewPresenter { public override void Show(MvxViewModelRequest request) { if (request.PresentationValues?["NavigationMode"] == "ClearStack") { var intent = CreateIntentForRequest(request); intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.NewTask); Show(intent); return; } base.Show(request); } } 

Note that ActivityFlags.ClearTask | ActivityFlags.NewTask ActivityFlags.ClearTask | ActivityFlags.NewTask will make your new action the only one on the stack.

+4
source

Source: https://habr.com/ru/post/1489768/


All Articles