diff --git a/docs/api/ui-forms/skconfettiview.md b/docs/api/ui-forms/skconfettiview.md index f0cb042f..48527ac3 100644 --- a/docs/api/ui-forms/skconfettiview.md +++ b/docs/api/ui-forms/skconfettiview.md @@ -10,11 +10,11 @@ The confetti view is a container for one or more systems of particles. The main property of a confetti view is the `Systems` property: -| Property | Type | Description | -| :-------------- | :---------------------------- | :---------- | -| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. | -| **IsRunning** | `bool` | Controls whether the all systems are running or not. | -| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | +| Property | Type | Description | +| :--------------------- | :---------------------------- | :---------- | +| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. | +| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. | +| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | ## Parts @@ -51,7 +51,7 @@ Every confetti view consists up one or more systems (`SKConfettiSystem`). Each s | **MaximumVelocity** | `double` | The maximum velocity the confetti particle can reach. | | **FadeOut** | `bool` | Whether or not the particle should fade out at the end of its life. | | **Lifetime** | `double` | The duration in seconds for how long the particle is allowed to live. | -| **IsRunning** | `bool` | Controls whether the system is running or not. | +| **IsAnimationEnabled** | `bool` | Controls whether the system is running or not. | | **IsComplete** | `bool` | A value that indicates whether the system is complete and all systems and particles are also complete. | # Emitter diff --git a/docs/api/ui-forms/sklottieview.md b/docs/api/ui-forms/sklottieview.md index 6e8748c2..4d7567d8 100644 --- a/docs/api/ui-forms/sklottieview.md +++ b/docs/api/ui-forms/sklottieview.md @@ -10,15 +10,15 @@ The Lottie view is a animated view that can playback Lottie files. There are several properties that can be used to control th animation playback: -| Property | Type | Description | -| :--------------- | :--------------------- | :---------- | -| **Source** | `SKLottieImageSource` | The Lottie [image source](#source) to playback in the view. | -| **Duration** | `TimeSpan` | A value indicating the total duration of the animation. | -| **Progress** | `TimeSpan` | The current playback progress of the animation. | -| **RepeatCount** | `int` | The number of times to repeat the animation. Default is 0 (no repeat). | -| **RepeatMode** | `SKLottieRepeatMode` | The way in which to repeat the animation. Default is `Restart`. | -| **IsRunning** | `bool` | Controls whether the all systems are running or not. | -| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | +| Property | Type | Description | +| :--------------------- | :--------------------- | :---------- | +| **Source** | `SKLottieImageSource` | The Lottie [image source](#source) to playback in the view. | +| **Duration** | `TimeSpan` | A value indicating the total duration of the animation. | +| **Progress** | `TimeSpan` | The current playback progress of the animation. | +| **RepeatCount** | `int` | The number of times to repeat the animation. Default is 0 (no repeat). | +| **RepeatMode** | `SKLottieRepeatMode` | The way in which to repeat the animation. Default is `Restart`. | +| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. | +| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | ## Events diff --git a/docs/api/ui-maui/skconfettiview.md b/docs/api/ui-maui/skconfettiview.md index f0cb042f..48527ac3 100644 --- a/docs/api/ui-maui/skconfettiview.md +++ b/docs/api/ui-maui/skconfettiview.md @@ -10,11 +10,11 @@ The confetti view is a container for one or more systems of particles. The main property of a confetti view is the `Systems` property: -| Property | Type | Description | -| :-------------- | :---------------------------- | :---------- | -| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. | -| **IsRunning** | `bool` | Controls whether the all systems are running or not. | -| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | +| Property | Type | Description | +| :--------------------- | :---------------------------- | :---------- | +| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. | +| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. | +| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | ## Parts @@ -51,7 +51,7 @@ Every confetti view consists up one or more systems (`SKConfettiSystem`). Each s | **MaximumVelocity** | `double` | The maximum velocity the confetti particle can reach. | | **FadeOut** | `bool` | Whether or not the particle should fade out at the end of its life. | | **Lifetime** | `double` | The duration in seconds for how long the particle is allowed to live. | -| **IsRunning** | `bool` | Controls whether the system is running or not. | +| **IsAnimationEnabled** | `bool` | Controls whether the system is running or not. | | **IsComplete** | `bool` | A value that indicates whether the system is complete and all systems and particles are also complete. | # Emitter diff --git a/docs/api/ui-maui/sklottieview.md b/docs/api/ui-maui/sklottieview.md index 6e8748c2..4d7567d8 100644 --- a/docs/api/ui-maui/sklottieview.md +++ b/docs/api/ui-maui/sklottieview.md @@ -10,15 +10,15 @@ The Lottie view is a animated view that can playback Lottie files. There are several properties that can be used to control th animation playback: -| Property | Type | Description | -| :--------------- | :--------------------- | :---------- | -| **Source** | `SKLottieImageSource` | The Lottie [image source](#source) to playback in the view. | -| **Duration** | `TimeSpan` | A value indicating the total duration of the animation. | -| **Progress** | `TimeSpan` | The current playback progress of the animation. | -| **RepeatCount** | `int` | The number of times to repeat the animation. Default is 0 (no repeat). | -| **RepeatMode** | `SKLottieRepeatMode` | The way in which to repeat the animation. Default is `Restart`. | -| **IsRunning** | `bool` | Controls whether the all systems are running or not. | -| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | +| Property | Type | Description | +| :--------------------- | :--------------------- | :---------- | +| **Source** | `SKLottieImageSource` | The Lottie [image source](#source) to playback in the view. | +| **Duration** | `TimeSpan` | A value indicating the total duration of the animation. | +| **Progress** | `TimeSpan` | The current playback progress of the animation. | +| **RepeatCount** | `int` | The number of times to repeat the animation. Default is 0 (no repeat). | +| **RepeatMode** | `SKLottieRepeatMode` | The way in which to repeat the animation. Default is `Restart`. | +| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. | +| **IsComplete** | `bool` | A value that indicates whether all systems are complete. | ## Events diff --git a/samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml b/samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml index 4745e6f6..277cf126 100644 --- a/samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml +++ b/samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml @@ -11,7 +11,7 @@ Source="Lottie/trophy.json" Duration="{Binding Duration}" Progress="{Binding Progress}" - IsRunning="{Binding IsBusy}"/> + IsAnimationEnabled="{Binding IsBusy}"/> diff --git a/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiSystem.shared.cs b/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiSystem.shared.cs index e72516aa..74a3cbc9 100644 --- a/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiSystem.shared.cs +++ b/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiSystem.shared.cs @@ -105,12 +105,12 @@ public class SKConfettiSystem : BindableObject public static readonly BindableProperty IsCompleteProperty = IsCompletePropertyKey.BindableProperty; - public static readonly BindableProperty IsRunningProperty = BindableProperty.Create( - nameof(IsRunning), + public static readonly BindableProperty IsAnimationEnabledProperty = BindableProperty.Create( + nameof(IsAnimationEnabled), typeof(bool), typeof(SKConfettiSystem), true, - propertyChanged: OnIsRunningPropertyChanged); + propertyChanged: OnIsAnimationEnabledPropertyChanged); private readonly Random random = new Random(); private readonly List particles = new List(); @@ -125,10 +125,10 @@ public SKConfettiSystem() OnEmitterChanged(this, null, Emitter); } - public bool IsRunning + public bool IsAnimationEnabled { - get => (bool)GetValue(IsRunningProperty); - set => SetValue(IsRunningProperty, value); + get => (bool)GetValue(IsAnimationEnabledProperty); + set => SetValue(IsAnimationEnabledProperty, value); } public SKConfettiEmitterBounds EmitterBounds @@ -231,7 +231,7 @@ public bool IsComplete public void Update(TimeSpan deltaTime) { - if (IsRunning) + if (IsAnimationEnabled) Emitter?.Update(deltaTime); var g = Gravity.ToSKPoint(); @@ -358,7 +358,7 @@ private static void OnEmitterChanged(BindableObject bindable, object? oldValue, } } - private static void OnIsRunningPropertyChanged(BindableObject bindable, object oldValue, object newValue) + private static void OnIsAnimationEnabledPropertyChanged(BindableObject bindable, object oldValue, object newValue) { if (bindable is SKConfettiSystem system) { @@ -370,7 +370,7 @@ private bool UpdateIsComplete() => IsComplete = particles.Count == 0 && Emitter?.IsComplete != false && - IsRunning; + IsAnimationEnabled; private static SKConfettiColorCollection CreateDefaultColors() => new SKConfettiColorCollection diff --git a/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiView.shared.cs b/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiView.shared.cs index 18f9de64..32554302 100644 --- a/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiView.shared.cs +++ b/source/SkiaSharp.Extended.UI/Controls/Confetti/SKConfettiView.shared.cs @@ -27,11 +27,11 @@ public SKConfettiView() SizeChanged += OnSizeChanged; PropertyChanged += (_, e) => { - if (nameof(IsRunning).Equals(e.PropertyName, StringComparison.OrdinalIgnoreCase)) - OnIsRunningPropertyChanged(); + if (nameof(IsAnimationEnabled).Equals(e.PropertyName, StringComparison.OrdinalIgnoreCase)) + OnIsAnimationEnabledPropertyChanged(); }; - IsRunning = true; + IsAnimationEnabled = true; OnSystemsPropertyChanged(this, null, Systems); } @@ -100,7 +100,7 @@ private void OnSystemsCollectionChanged(object? sender, NotifyCollectionChangedE foreach (SKConfettiSystem system in e.NewItems) { system.UpdateEmitterBounds(Width, Height); - system.IsRunning = IsRunning; + system.IsAnimationEnabled = IsAnimationEnabled; } Invalidate(); @@ -109,14 +109,14 @@ private void OnSystemsCollectionChanged(object? sender, NotifyCollectionChangedE UpdateIsComplete(); } - private void OnIsRunningPropertyChanged() + private void OnIsAnimationEnabledPropertyChanged() { if (Systems is null) return; foreach (var system in Systems) { - system.IsRunning = IsRunning; + system.IsAnimationEnabled = IsAnimationEnabled; } } diff --git a/source/SkiaSharp.Extended.UI/Controls/Lottie/SKLottieView.shared.cs b/source/SkiaSharp.Extended.UI/Controls/Lottie/SKLottieView.shared.cs index 5e8b0ea6..b4d1d072 100644 --- a/source/SkiaSharp.Extended.UI/Controls/Lottie/SKLottieView.shared.cs +++ b/source/SkiaSharp.Extended.UI/Controls/Lottie/SKLottieView.shared.cs @@ -54,7 +54,7 @@ public SKLottieView() { Themes.SKLottieViewResources.EnsureRegistered(); - IsRunning = true; + IsAnimationEnabled = true; } public SKLottieImageSource? Source @@ -191,7 +191,7 @@ private void UpdateProgress(TimeSpan progress) repeatsCompleted >= totalRepeatCount; } - if (!IsRunning) + if (!IsAnimationEnabled) Invalidate(); } @@ -223,7 +223,7 @@ private async Task LoadAnimationAsync(SKLottieImageSource? imageSource, Cancella AnimationLoaded?.Invoke(this, EventArgs.Empty); } - if (!IsRunning) + if (!IsAnimationEnabled) Invalidate(); void Reset() diff --git a/source/SkiaSharp.Extended.UI/Controls/SKAnimatedSurfaceView.shared.cs b/source/SkiaSharp.Extended.UI/Controls/SKAnimatedSurfaceView.shared.cs index e9a188f3..6dbe9bc8 100644 --- a/source/SkiaSharp.Extended.UI/Controls/SKAnimatedSurfaceView.shared.cs +++ b/source/SkiaSharp.Extended.UI/Controls/SKAnimatedSurfaceView.shared.cs @@ -2,13 +2,13 @@ public class SKAnimatedSurfaceView : SKSurfaceView { - public static readonly BindableProperty IsRunningProperty = BindableProperty.Create( - nameof(IsRunning), + public static readonly BindableProperty IsAnimationEnabledProperty = BindableProperty.Create( + nameof(IsAnimationEnabled), typeof(bool), typeof(SKAnimatedSurfaceView), false, - BindingMode.TwoWay, - propertyChanged: OnIsRunningPropertyChanged); + BindingMode.OneWay, + propertyChanged: OnIsAnimationEnabledPropertyChanged); private readonly SKFrameCounter frameCounter = new SKFrameCounter(); @@ -17,10 +17,13 @@ internal SKAnimatedSurfaceView() Loaded += OnLoaded; } - public bool IsRunning + /// + /// Gets or sets a value indicating whether this control will play the animation provided. + /// + public bool IsAnimationEnabled { - get => (bool)GetValue(IsRunningProperty); - set => SetValue(IsRunningProperty, value); + get => (bool)GetValue(IsAnimationEnabledProperty); + set => SetValue(IsAnimationEnabledProperty, value); } protected virtual void Update(TimeSpan deltaTime) @@ -45,29 +48,29 @@ internal override void InvalidateCore() private void UpdateCore() { - var deltaTime = IsRunning + var deltaTime = IsAnimationEnabled ? frameCounter.NextFrame() : TimeSpan.Zero; Update(deltaTime); } - private static void OnIsRunningPropertyChanged(BindableObject bindable, object? oldValue, object? newValue) => - (bindable as SKAnimatedSurfaceView)?.UpdateIsRunning(); + private static void OnIsAnimationEnabledPropertyChanged(BindableObject bindable, object? oldValue, object? newValue) => + (bindable as SKAnimatedSurfaceView)?.UpdateIsAnimationEnabled(); private void OnLoaded(object? sender, EventArgs e) { - UpdateIsRunning(); + UpdateIsAnimationEnabled(); } - private void UpdateIsRunning() + private void UpdateIsAnimationEnabled() { if (!this.IsLoadedEx()) return; frameCounter.Reset(); - if (!IsRunning) + if (!IsAnimationEnabled) return; Dispatcher.StartTimer( @@ -76,7 +79,7 @@ private void UpdateIsRunning() { Invalidate(); - return IsRunning; + return IsAnimationEnabled; }); } } diff --git a/tests/SkiaSharp.Extended.UI.Tests/Controls/Confetti/SKConfettiSystemTest.cs b/tests/SkiaSharp.Extended.UI.Tests/Controls/Confetti/SKConfettiSystemTest.cs index 944b7f30..657fb876 100644 --- a/tests/SkiaSharp.Extended.UI.Tests/Controls/Confetti/SKConfettiSystemTest.cs +++ b/tests/SkiaSharp.Extended.UI.Tests/Controls/Confetti/SKConfettiSystemTest.cs @@ -10,7 +10,7 @@ public void DefaultIsNotComplete() { var system = new SKConfettiSystem(); - Assert.True(system.IsRunning); + Assert.True(system.IsAnimationEnabled); Assert.False(system.IsComplete); } @@ -18,9 +18,9 @@ public void DefaultIsNotComplete() public void NotRunningIsNotComplete() { var system = new SKConfettiSystem(); - system.IsRunning = false; + system.IsAnimationEnabled = false; - Assert.False(system.IsRunning); + Assert.False(system.IsAnimationEnabled); Assert.False(system.IsComplete); } }