xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Animations not working #7255

Closed markosmilja closed 5 years ago

markosmilja commented 5 years ago

Description

Custom animation not working on latest version of Xamarin Forms

Steps to Reproduce

  1. Use code from official Microsoft docs for custom animations var animation = new Animation (v => image.Scale = v, 0, 1); animation.Commit (this, "SimpleAnimation", 16, 2000, Easing.Linear, (v, c) => image.Scale = 1, () => true);
  2. Trigger code from a button or somewhere else

Expected Behavior

Animation working

Actual Behavior

Animation hot working. The value passed to the callback function goes from 0 to 1 directly with no intermediate values (0.1, 0.2...)

Basic Information

Screenshots

Reproduction Link

MitchBomcanhao commented 5 years ago

Even some stuff like built in controls seem to be broken - tapping a switch flicks between 0 and 1, instead of animating the state change.

samhouts commented 5 years ago

@markosmilja Can you please attach a small project that demonstrates this issue? Thanks!

markosmilja commented 5 years ago

AndroidAnimationsBug.zip

Here is the simple project. A box view and a button that triggers the box view scale animation.

The working versions are: Xamarin.Essentials 1.1.0 Xamarin.Forms 4.1.0.555618

Install the latest versions and the animations are not working: Xamarin.Essentials 1.3.0 Xamarin.Forms 4.2.0.709249

joshardt commented 5 years ago

@markosmilja I cannot confirm the described behavior. I checked out your code and it works fine on a Nexus 5x with Android 8.1.0 with Xamarin.Forms 4.2.0.709249.

On which device did you test your code? Can you please try the code in an Android emulator with a greater version than Android 6.0? Can you please test your code with an iPhone or iPhone simulator?

I ask you to do this because I'd like to find out under which circumstances this bug can get reproduced.

Arbalets commented 5 years ago

I am experiencing the same problem when updating Xamarin.Forms to 4.2.0.709249. @JFMG I tried @markosmilja sample and I'm seeing the same problem on emulators running Android 8.1 and 9.0 and on an older device Sony Z3 with Android 6.0, however no problems on Huawei P20 pro with Android 9.0. Also no problems on iOS (both device and simulator).

bentmar commented 5 years ago

Same issue, none of my XF animations work (they completete instantly) Tried on different devices from oreo to pie.

bentmar commented 5 years ago

So I did a lil research.

In the latest 4.2 the AndroidTicker.cs was modified to care about the animation duration scale (a setting in developer options)

var scale = global::Android.Provider.Settings.Global.GetFloat(resolver, global::Android.Provider.Settings.Global.AnimatorDurationScale, 0);

I found that IF the Animation duriation scale setting has never been touched on the device. The scale will allways return 0 = no animations will be rendered.

By changing the line to this instead, we default to 1 (wich also is the default on android). This means, if we never changed the value in developer settings, we will get 1 instead of 0 = animation will work like they did pre 4.2

var scale = global::Android.Provider.Settings.Global.GetFloat(resolver, global::Android.Provider.Settings.Global.AnimatorDurationScale, 1);

bentmar commented 5 years ago

As a workawound you can go in to developer settings, change the animation duration scale to 1,5 (or something) and then back to 1.