Xamarin.forms: Still no way to turn off animation on navigating back

Created on 15 Jun 2018  路  6Comments  路  Source: xamarin/Xamarin.Forms

Description

You can turn off the navigation animation when pushing a page. Its a simple argument
Navigation.PushAsync(new MyCoolPage(), false);
But when you hit [Back] there is a still a zooming animation.

Steps to Reproduce

Navigate from page to page, then hit the back button (android) - I presume back from the navbar is the same on iOS.



    1. 2.
  1. 3.

Expected Behavior

If animation is set to false when you go TO a page, I would expect LEAVING that page would also be False. It just seems natural.

Actual Behavior

Animation is always on when you go [back] even if it was false when pushing the page out.

Basic Information

  • Version with issue: Xamarin.Forms 3
  • Last known good version: Its never worked as expected (or wanted in MANY forum threads)
  • IDE:
  • Platform Target Frameworks:

    • iOS:

    • Android:

    • UWP:

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

4 help wanted bug up-for-grabs

Most helpful comment

using Android.Content;
using System.Threading.Tasks;
using TestApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android.AppCompat;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CNavigationPageRenderer))]
namespace TestApp.Droid
{
    public class CNavigationPageRenderer : NavigationPageRenderer
    {
        public CNavigationPageRenderer(Context context) : base(context)
        {

        }

        protected override Task<bool> OnPushAsync(Page view, bool animated)
        {
            return base.OnPushAsync(view, false);
        }

        protected override Task<bool> OnPopViewAsync(Page page, bool animated)
        {
            return base.OnPopViewAsync(page, false);
        }

        protected override Task<bool> OnPopToRootAsync(Page page, bool animated)
        {
            return base.OnPopToRootAsync(page, false);
        }
    }
}

Do the same thing for other platforms. As I said, this is making the animated flag in Core useless, but at least it disables all page animations even when you use the Back button because it should call OnPopViewAsync.

You could potentially add custom logic here to scan for page types or certain set of criteria (like your custom logic [i.e. non-animated push should be coupled with a non-animated pop for that specific page]).

All 6 comments

The fix for this could potentially be a breaking change for people who implemented a custom pop animation and expect to see it even if the push was without an animation. The likelihood is probably minimal, however.

If animation is set to false when you go TO a page, I would expect LEAVING that page would also be False

Why do you make this assumption?

- (void)pushViewController:(UIViewController *)viewController 
                  animated:(BOOL)animated;

- (UIViewController *)popViewControllerAnimated:(BOOL)animated;

I think the APIs here are pretty clear as they can be animated independently of each other.

I also needed to disable both push and pop transitions for custom design, and my workaround was creating custom NavigationPageRenderers and overriding the async navigation methods to pass a false flag to their base. This has the side effect of rendering Core animated flag useless, but at least it's handling the Back button animation.

@adrianknight89 Said:

I also needed to disable both push and pop transitions for custom design, and my workaround was creating custom NavigationPageRenderers and overriding the async navigation methods to pass a false flag to their base.

Would you mind sharing those renderers for the rest of us facing the same problem?

using Android.Content;
using System.Threading.Tasks;
using TestApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android.AppCompat;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CNavigationPageRenderer))]
namespace TestApp.Droid
{
    public class CNavigationPageRenderer : NavigationPageRenderer
    {
        public CNavigationPageRenderer(Context context) : base(context)
        {

        }

        protected override Task<bool> OnPushAsync(Page view, bool animated)
        {
            return base.OnPushAsync(view, false);
        }

        protected override Task<bool> OnPopViewAsync(Page page, bool animated)
        {
            return base.OnPopViewAsync(page, false);
        }

        protected override Task<bool> OnPopToRootAsync(Page page, bool animated)
        {
            return base.OnPopToRootAsync(page, false);
        }
    }
}

Do the same thing for other platforms. As I said, this is making the animated flag in Core useless, but at least it disables all page animations even when you use the Back button because it should call OnPopViewAsync.

You could potentially add custom logic here to scan for page types or certain set of criteria (like your custom logic [i.e. non-animated push should be coupled with a non-animated pop for that specific page]).

@adrianknight89 Your solution doesn't work for basic content pages with a Navigation.PushModalAsync(new ContentPage())

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

This issue is still present and relevant today.
A proposal has been made to extend the current navigation api to fix this issue https://github.com/xamarin/Xamarin.Forms/issues/5116

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmilAlipiev picture EmilAlipiev  路  3Comments

joseluisct picture joseluisct  路  3Comments

simontocknell picture simontocknell  路  3Comments

mfeingol picture mfeingol  路  3Comments

suihanhbr picture suihanhbr  路  3Comments