Custom Animation with MvvmCross Droid
Asked Answered
Q

2

5

With MvvmCross, if I want a button to open a new screen, I wire up the command handler and use ShowViewModel, like this:

        ShowViewModel<InfoViewModel>();

Is there anyway to plug in custom animations, which are very platform specific, and still use ShowViewModel in the core? If I were doing this in a Droid project, it would look like this:

        OverridePendingTransition(Resource.Animation.push_up_in, Resource.Animation.push_up_out);

So basically I want a way to hook into the MvvmCross Activity creation from the Droid project.

Qua answered 11/7, 2013 at 15:55 Comment(0)
Q
2

Solved by calling the command from the MvxActivity in the UI.

        var infoBtn = FindViewById<RelativeLayout>(Resource.Id.infobtn);
        infoBtn.Click += delegate(object sender, EventArgs args)
            {
                ((MainMenuViewModel)ViewModel).InfoCommand.Execute(null);
                OverridePendingTransition(Resource.Animation.push_up_in, Resource.Animation.push_up_out);                 
            };
Qua answered 11/7, 2013 at 16:20 Comment(3)
If you want to do this in the 'correct' place, then it's probably best to do this in a custom presenter - see links from slodge.blogspot.co.uk/2013/06/presenter-roundup.htmlDurante
Thanks! I'm looking into this.Qua
Did you manage to do it in the 'correct' place? Looking at the link @Durante provided but can not find anything relevant.Dyslogia
D
7

Finally managed to do it!

In the Setup override the CreateViewPresenter()

public class Setup : MvxAndroidSetup
{
 ...
 ...
    protected override IMvxAndroidViewPresenter CreateViewPresenter()
    {
        return new CustomPresenter();
    }
}

and created a CustomPresenter class to do the animation:

public class CustomPresenter : MvxAndroidViewPresenter
{

    protected override void Show(Intent intent)
    {
        Activity.StartActivity(intent);
        Activity.OverridePendingTransition(Resource.Animator.slide_in_left, Resource.Animator.slide_out_left);
    }
}
Dyslogia answered 11/2, 2016 at 17:37 Comment(0)
Q
2

Solved by calling the command from the MvxActivity in the UI.

        var infoBtn = FindViewById<RelativeLayout>(Resource.Id.infobtn);
        infoBtn.Click += delegate(object sender, EventArgs args)
            {
                ((MainMenuViewModel)ViewModel).InfoCommand.Execute(null);
                OverridePendingTransition(Resource.Animation.push_up_in, Resource.Animation.push_up_out);                 
            };
Qua answered 11/7, 2013 at 16:20 Comment(3)
If you want to do this in the 'correct' place, then it's probably best to do this in a custom presenter - see links from slodge.blogspot.co.uk/2013/06/presenter-roundup.htmlDurante
Thanks! I'm looking into this.Qua
Did you manage to do it in the 'correct' place? Looking at the link @Durante provided but can not find anything relevant.Dyslogia

© 2022 - 2024 — McMap. All rights reserved.