Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename IsRunning to IsAnimationEnabled on SKAnimatedSurfaceView #125

Merged
merged 6 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/api/ui-forms/skconfettiview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions docs/api/ui-forms/sklottieview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions docs/api/ui-maui/skconfettiview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions docs/api/ui-maui/sklottieview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Source="Lottie/trophy.json"
Duration="{Binding Duration}"
Progress="{Binding Progress}"
IsRunning="{Binding IsBusy}"/>
IsAnimationEnabled="{Binding IsBusy}"/>

<BoxView Color="Green" Opacity="0.5" CornerRadius="12"
WidthRequest="25" HeightRequest="24" Margin="24"
Expand Down
2 changes: 1 addition & 1 deletion samples/Maui/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Source="Lottie/trophy.json"
Duration="{Binding Duration}"
Progress="{Binding Progress}"
IsRunning="{Binding IsBusy}"
IsAnimationEnabled="{Binding IsBusy}"
AnimationFailed="OnAnimationFailed"
AnimationLoaded="OnAnimationLoaded" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SKConfettiParticle> particles = new List<SKConfettiParticle>();
Expand All @@ -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
Expand Down Expand Up @@ -231,7 +231,7 @@ public bool IsComplete

public void Update(TimeSpan deltaTime)
{
if (IsRunning)
if (IsAnimationEnabled)
Emitter?.Update(deltaTime);

var g = Gravity.ToSKPoint();
Expand Down Expand Up @@ -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)
{
Expand All @@ -370,7 +370,7 @@ private bool UpdateIsComplete() =>
IsComplete =
particles.Count == 0 &&
Emitter?.IsComplete != false &&
IsRunning;
IsAnimationEnabled;

private static SKConfettiColorCollection CreateDefaultColors() =>
new SKConfettiColorCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public SKLottieView()
{
Themes.SKLottieViewResources.EnsureRegistered();

IsRunning = true;
IsAnimationEnabled = true;
}

public SKLottieImageSource? Source
Expand Down Expand Up @@ -191,7 +191,7 @@ private void UpdateProgress(TimeSpan progress)
repeatsCompleted >= totalRepeatCount;
}

if (!IsRunning)
if (!IsAnimationEnabled)
Invalidate();
}

Expand Down Expand Up @@ -223,7 +223,7 @@ private async Task LoadAnimationAsync(SKLottieImageSource? imageSource, Cancella
AnimationLoaded?.Invoke(this, EventArgs.Empty);
}

if (!IsRunning)
if (!IsAnimationEnabled)
Invalidate();

void Reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -17,10 +17,13 @@ internal SKAnimatedSurfaceView()
Loaded += OnLoaded;
}

public bool IsRunning
/// <summary>
/// Gets or sets a value indicating whether this control will play the animation provided.
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
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)
Expand All @@ -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(
Expand All @@ -76,7 +79,7 @@ private void UpdateIsRunning()
{
Invalidate();

return IsRunning;
return IsAnimationEnabled;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public void DefaultIsNotComplete()
{
var system = new SKConfettiSystem();

Assert.True(system.IsRunning);
Assert.True(system.IsAnimationEnabled);
Assert.False(system.IsComplete);
}

[Fact]
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);
}
}
Expand Down