Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmCross v5 animation between two root presentations

I have two iOS views marked by MvxRootPresentation attribute: LoginView without wrapping into navigation controller and MainView with wrapping into navigation controller.

When I call ShowViewModel<MainViewModel>() there is no animation between these two views. All subsequent views are animated as usual (within NavigationController).

How can I set animation for this transition?

like image 506
Vasily Kornienko Avatar asked Mar 09 '23 01:03

Vasily Kornienko


1 Answers

Ok, I've did it myself :) I had to add my custom presentation attribute and custom presenter:

public class AnimatedRootPresentationAttribute : MvxRootPresentationAttribute
{
}

public class MyPresenter : MvxIosViewPresenter
{
    public MyPresenter(IUIApplicationDelegate appDelegate, UIWindow window)
        : base(appDelegate, window)
    {
    }

    protected override void RegisterAttributeTypes()
    {
        base.RegisterAttributeTypes();

        _attributeTypesToShowMethodDictionary.Add(typeof(AnimatedRootPresentationAttribute),
            (viewController, attribute, request) => ShowAnimatedRootViewController(
                viewController, (AnimatedRootPresentationAttribute)attribute, request));
    }

    private void ShowAnimatedRootViewController(
        UIViewController viewController,
        AnimatedRootPresentationAttribute attribute,
        MvxViewModelRequest request)
    {
        ShowRootViewController(viewController, attribute, request);
        AddAnimation();
    }

    private void AddAnimation()
    {
        var transition = new CATransition
        {
            Duration = 0.2,
            Type = CAAnimation.TransitionMoveIn,
            Subtype = CAAnimation.TransitionFromTop
        };

        _window.RootViewController.View.Layer.AddAnimation(transition, null);
    }
}
like image 71
Vasily Kornienko Avatar answered Mar 16 '23 07:03

Vasily Kornienko