dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Animation StartDelay property has no effect #18422

Open jeremy-visionaid opened 1 year ago

jeremy-visionaid commented 1 year ago

Description

Setting Animation.StartDelay does not delay the start of an animation (dotnet 7.0.96 and 8.0.0-rc.2)

Steps to Reproduce

Add an animation with StartDelay configured. Expected: Animation begins after the specified delay Actual: Animation begins immediately

Link to public reproduction project repository

https://github.com/molesmoke/MauiTestApp/tree/animation-start-delay

Version with bug

7.0.96

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

Use Task.Delay or create a no-op animation. e.g.

public static class ViewExtensions
{
    public static Task<bool> DelayFor(this VisualElement view, uint length = 250)
    {
        TaskCompletionSource<bool> tcs = new();
        Animation animation = new();
        animation.Commit(view, nameof(DelayFor), 16, length, Easing.Linear, (f, a) => tcs.SetResult(a));
        return tcs.Task;
    }
}

Relevant log output

No response

jeremy-visionaid commented 1 year ago

Seems like there might be a more general issue with the whole design of the animation system. The "finished" delegate provided to the constructor is also never triggered if it is provided, only the finished delegate provided to the "Commit" function gets triggered. I tried to debug the issue by putting some breakpoints on the OnTick methods in the Animation - but it seems like they're never called either (at least not on Windows)! Seems like there might just be a whole bunch of cruft leftover from some previous design?

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 5.0(8.0.0-rc.2.9373). Repro on Windows 11, Android 14.0-API34 and iOS 16.4 with below Project: MauiTestApp.zip Animation

Dhivya-SF4094 commented 11 months ago

I've encountered the same issue with Animation.StartDelay not working as expected. This seems to be a common concern, and I believe addressing it would significantly improve the overall functionality of the library. Looking forward to any updates or suggestions for a workaround.

molesmoke commented 11 months ago

@Dhivya-SF4094 As a workaround, you can implement an extension method similar to "FadeTo" etc. that just does nothing for the length of the desired delay. Unfortunately, CancelAnimations won't be aware of it, so you'd have to cancel it manually if needed.