Bug 23898 - Xamarin Forms View with repeatable Animation never stopped even after disappear
Summary: Xamarin Forms View with repeatable Animation never stopped even after disappear
Status: RESOLVED FEATURE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/xamarin/Duplo/issu...
Depends on:
Blocks:
 
Reported: 2014-10-17 10:19 UTC by Ludovic Thomas
Modified: 2015-06-02 08:05 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Ludovic Thomas 2014-10-17 10:19:33 UTC
*Overview*
When creating a custom view, with a repeatable animation, the animation will never be stopped, even if the parent page is no more visible.

*Steps to reproduce*
1) Create a Xamarin.Forms project and add the code from the following code:

using Xamarin.Forms;
using System.Diagnostics;

namespace Test
{
    public class App
    {
        public static Page GetMainPage()
        {
            return new NavigationPage(CreatePage());
        }

        private static Page CreatePage()
        {
            var page = new ContentPage();
            var contents = new StackLayout();

            contents.Children.Add(
                new Button
                {
                    Text = "Next Page",
                    Command = new Command(() => page.Navigation.PushAsync(CreatePage()))
                });
            contents.Children.Add(
                new MyAnimatedBoxView
                {
                    Color = Color.Blue,
                    HorizontalOptions = LayoutOptions.Center,
                    WidthRequest = 50,
                    HeightRequest = 50
                });

            page.Content = contents;
            return page;
        }
    }

    public class MyAnimatedBoxView : BoxView
    {
        private static int communBoxNumber = 0;

        public MyAnimatedBoxView()
        {
            communBoxNumber++;

            // Start animation
            UploadingAnimation(communBoxNumber);
        }

        private async void UploadingAnimation(int boxNumber)
        {
            new Animation((double f) => this.Scale = f, this.Scale, 2.0, Easing.Linear, null
            ).Commit(this, "ScaleTo", 16, 1000, null,
                delegate(double f, bool a)
                {
                Debug.WriteLine("Animation done for box {0}", boxNumber);
                    this.Scale = 1.0;
                },
                () => IsVisible
            );
        }
    }
}


2) On the page, a box is animated with a scale animation, and on the logs "Animation done for box 1" is visible each second when the animation finished. Clicking on the Next Page button will create a new page, with same animation, and on the logs "Animation done for box 2". 

3) Select the Back button to come back to the main screen.

*Expected results*
On the logs, only the "Animation done for box 1" must continue, as only that screen is still living.

*Actual results*
On the logs, the "Animation done for box 2" is still appended, and will continue forever.

*Versioning information*
Xarmarin Forms Version: 1.2.3.6257
Comment 1 Parmendra Kumar 2014-10-17 11:49:47 UTC
I have checked this issue and I am able to reproduce this issue, To reproduce this issue I have followed steps mentioned in the bug description.

Screencast:http://www.screencast.com/t/DyQi7uMNUYs
Output Log: https://gist.github.com/Parmendrak/043170855c91854484cf
IDE Log: https://gist.github.com/Parmendrak/8464c5e0cd61907322de

Environment Info:
=== Xamarin Studio ===

Version 5.5.2 (build 3)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

=== Xamarin.Android ===

Version: 4.18.0 (Business Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.2.0.207 (Business Edition)
Hash: 3bf072d
Branch: 
Build date: 2014-10-15 21:44:26-0400

=== Xamarin.Mac ===

Version: 1.10.0.13 (Business Edition)

=== Build Information ===

Release ID: 505020003
Git revision: 6d4c806e383ba366b15fbccca9ddc1ba94f8d5ad
Build date: 2014-10-15 15:00:36-04
Xamarin addins: 069ddd29bb70a42238142eee9bac21a5e4b2f9f9

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 2 Stephane Delcroix 2015-06-02 03:52:37 UTC
Page lifetime (creation/destruction) is different from it's visibility. In your case, you start the animation in the Page ctor, that means it starts animating even if the page is not on screen. What you're reporting is the counterpart, i.e., the animation continues when the page is no longer visible.

instead of relying on page creation/destruction for starting/stopping/resuming your animations, you should override OnAppearing/OnDisappearing and start and stop your animations from there.
Comment 3 Adam Kemp 2015-06-02 08:05:04 UTC
Why is it even possible to animate something that's not on screen?