mark.muniz
mark.muniz

Reputation: 93

Xamarin AppCompat.NavigationPageRenderer transitions

I would like to change the animation between page transitions on Android by extending the NavigationPageRenderer. However, unlike the Xamarin.Forms.Platform.Android.NavigationRenderer, there aren't any methods for OnPopToRootAsync, OnPopViewAsync, and OnPushAsync. Is it possible to override the transition on a page with the AppCompat.NavigationPageRenderer?

Upvotes: 2

Views: 1791

Answers (2)

Manoj Alwis
Manoj Alwis

Reputation: 1426

For Android X use it like this:

protected override void SetupPageTransition(AndroidX.Fragment.App.FragmentTransaction transaction, bool isPush)

Upvotes: 0

oddbear
oddbear

Reputation: 193

You will need to add a custom renderer for the NavigationPageRenderer, and override the SetupPageTransition.

[assembly: ExportRenderer(typeof(NavigationPage), typeof(AnimationNavigationRenderer))]
namespace ProjectName.Droid
{
    public class AnimationNavigationRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
    {
        protected override void SetupPageTransition(Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
        {
            if (isPush)
                transaction.SetCustomAnimations(Resource.Animation.abc_slide_in_top, 0, 0, Resource.Animation.abc_slide_out_top);
            else
                transaction.SetCustomAnimations(Resource.Animation.abc_slide_in_top, 0, 0, Resource.Animation.abc_slide_out_top);
        }
    }
}

Upvotes: 3

Related Questions