From c9583643bf5f616eea7d2e625cd0889c4f4a1c30 Mon Sep 17 00:00:00 2001 From: bijington Date: Wed, 14 Jul 2021 22:55:50 +0100 Subject: [PATCH 01/10] Base class implementation for pre-built animations --- .../Animations/AnimationBase.shared.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/AnimationBase.shared.cs diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/AnimationBase.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/AnimationBase.shared.cs new file mode 100644 index 000000000..a66cfca84 --- /dev/null +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/AnimationBase.shared.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using Xamarin.Forms; + +namespace Xamarin.CommunityToolkit.Animations +{ + /// + /// Base class representation of a pre-built animation. + /// + public abstract class AnimationBase + { + readonly Easing? easing; + readonly uint length = 250; + readonly Action? onFinished; + readonly IAnimatable? owner; + readonly uint rate = 16; + readonly Func? shouldRepeat; + readonly string name; + protected readonly View[] views; + + protected AnimationBase( + string name, + IAnimatable? owner = null, + uint rate = 16, + uint length = 250, + Easing? easing = null, + Action? onFinished = null, + Func? shouldRepeat = null, + params View[] views) + { + if (views is null || !views.Any()) + { + throw new ArgumentException("Views cannot be null or empty.", nameof(views)); + } + + this.name = name + Guid.NewGuid().ToString(); + this.length = length; + this.views = views; + this.easing = easing; + this.onFinished = onFinished; + this.owner = owner; + this.rate = rate; + this.shouldRepeat = shouldRepeat; + } + + /// + /// Stops the animation. + /// + /// True if successful, false otherwise. + public bool Abort() => GetOwner().AbortAnimation(name); + + /// + /// Runs the animation. + /// + public void Commit() => Create().Commit(GetOwner(), name, rate, length, easing, onFinished, shouldRepeat); + + /// + /// Gets a value indicating whether the animation is running. + /// + public bool IsRunning => GetOwner().AnimationIsRunning(name); + + protected abstract Animation Create(); + + IAnimatable GetOwner() => owner ?? views.First(); + } +} \ No newline at end of file From e09b55d9a2c1aa053e2e1dce10fe52d9704ae26d Mon Sep 17 00:00:00 2001 From: bijington Date: Wed, 14 Jul 2021 22:56:27 +0100 Subject: [PATCH 02/10] TADA! Added the first animation --- .../Behaviors/AnimationBehaviorPage.xaml | 23 ++++++- .../Behaviors/AnimationBehaviorPage.xaml.cs | 17 ++++- .../Animations/TadaAnimation.shared.cs | 66 +++++++++++++++++++ .../TadaAnimationType.shared.cs | 43 ++++++++++++ 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/TadaAnimation.shared.cs create mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/Animations/AnimationTypes/TadaAnimationType.shared.cs diff --git a/samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml b/samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml index 55c55ca0d..0303ee664 100644 --- a/samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml +++ b/samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml @@ -14,7 +14,28 @@ Spacing="10"> + +