Reputation: 93
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
Reputation: 1426
For Android X use it like this:
protected override void SetupPageTransition(AndroidX.Fragment.App.FragmentTransaction transaction, bool isPush)
Upvotes: 0
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