Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Animation with MvvmCross Droid

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.

like image 463
Ryan Langton Avatar asked Jul 11 '13 15:07

Ryan Langton


2 Answers

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);
    }
}
like image 178
Riga Avatar answered Oct 20 '22 08:10

Riga


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);                 
            };
like image 2
Ryan Langton Avatar answered Oct 20 '22 06:10

Ryan Langton