Skip to content

Commit

Permalink
Revert "Rename IsCompleted to IsRunning (#127)" (#129)
Browse files Browse the repository at this point in the history
This reverts commit ce6c5c0.
  • Loading branch information
mattleibow authored Jul 13, 2022
1 parent ce6c5c0 commit 25d0124
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 167 deletions.
6 changes: 3 additions & 3 deletions docs/api/ui-forms/skconfettiview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The main property of a confetti view is the `Systems` property:
| :--------------------- | :---------------------------- | :---------- |
| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. |
| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. |
| **IsRunning** | `bool` | Determines whether the control is currently rendering confetti. |
| **IsComplete** | `bool` | A value that indicates whether all systems are complete. |

## Parts

Expand Down Expand Up @@ -52,7 +52,7 @@ Every confetti view consists up one or more systems (`SKConfettiSystem`). Each s
| **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. |
| **IsAnimationEnabled** | `bool` | Controls whether the system is running or not. |
| **IsRunning** | `bool` | Determines whether the system is complete and all systems and particles are also complete. |
| **IsComplete** | `bool` | A value that indicates whether the system is complete and all systems and particles are also complete. |

# Emitter

Expand All @@ -63,7 +63,7 @@ Each system has an emitter instance that controls how the confetti particles are
| **ParticleRate** | `int` | The number of particles to generate each second. |
| **MaxParticles** | `int` | The maximum number of particles allowed by the emitter. A value of `-1` indicates no limit. |
| **Duration** | `double` | The duration in seconds of how long the emitter runs for. A value of `0` indicates that all particles are emitted instantly. |
| **IsRunning** | `bool` | Determines whether the emitter has generated all the particles and they have all disappeared. |
| **IsComplete** | `bool` | A value that indicates whether the emitter has generated all the particles and they have all disappeared. |

## Helper Emitters

Expand Down
2 changes: 1 addition & 1 deletion docs/api/ui-forms/sklottieview.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are several properties that can be used to control th animation playback:
| **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. |
| **IsRunning** | `bool` | Determines whether the control is currently rendering the animation. |
| **IsComplete** | `bool` | A value that indicates whether all systems are complete. |

## Events

Expand Down
7 changes: 3 additions & 4 deletions docs/api/ui-maui/skconfettiview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The main property of a confetti view is the `Systems` property:
| :--------------------- | :---------------------------- | :---------- |
| **Systems** | `SKConfettiSystemCollection` | The collection of [systems](#system) in the view. |
| **IsAnimationEnabled** | `bool` | Determines whether the control will play the animation provided. |
| **IsRunning** | `bool` | Determines whether the control is currently rendering confetti. |
| **IsComplete** | `bool` | A value that indicates whether all systems are complete. |

## Parts

Expand Down Expand Up @@ -52,7 +52,7 @@ Every confetti view consists up one or more systems (`SKConfettiSystem`). Each s
| **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. |
| **IsAnimationEnabled** | `bool` | Controls whether the system is running or not. |
| **IsRunning** | `bool` | Determines whether the system is complete and all systems and particles are also complete. |
| **IsComplete** | `bool` | A value that indicates whether the system is complete and all systems and particles are also complete. |

# Emitter

Expand All @@ -63,8 +63,7 @@ Each system has an emitter instance that controls how the confetti particles are
| **ParticleRate** | `int` | The number of particles to generate each second. |
| **MaxParticles** | `int` | The maximum number of particles allowed by the emitter. A value of `-1` indicates no limit. |
| **Duration** | `double` | The duration in seconds of how long the emitter runs for. A value of `0` indicates that all particles are emitted instantly. |
| **IsRunning** | `bool` | Determines whether the control is currently rendering confetti. |
| **IsRunning** | `bool` | Determines whether the emitter has generated all the particles and they have all disappeared. |
| **IsComplete** | `bool` | A value that indicates whether the emitter has generated all the particles and they have all disappeared. |

## Helper Emitters

Expand Down
2 changes: 1 addition & 1 deletion docs/api/ui-maui/sklottieview.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are several properties that can be used to control th animation playback:
| **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. |
| **IsRunning** | `bool` | Determines whether the control is currently rendering the animation. |
| **IsComplete** | `bool` | A value that indicates whether all systems are complete. |

## Events

Expand Down
18 changes: 0 additions & 18 deletions samples/Forms/SkiaSharpDemo/Converters/InvertedBooleanConverter.cs

This file was deleted.

7 changes: 1 addition & 6 deletions samples/Forms/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
xmlns:converters="clr-namespace:SkiaSharpDemo.Converters"
xmlns:views="clr-namespace:SkiaSharpDemo.Views"
x:Class="SkiaSharpDemo.Demos.ConfettiPage"
Title="Confetti">

<ContentPage.Resources>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
</ContentPage.Resources>

<Grid>

<Label Text="{Binding Message}" FontSize="32" FontAttributes="Bold"
Expand All @@ -25,7 +20,7 @@
<BoxView Color="Green" Opacity="0.5" CornerRadius="12"
WidthRequest="25" HeightRequest="24" Margin="24"
HorizontalOptions="End" VerticalOptions="Start"
IsVisible="{Binding IsRunning, Source={Reference confettiView}, Converter={StaticResource InvertedBooleanConverter}}" />
IsVisible="{Binding IsComplete, Source={Reference confettiView}}" />

<views:BottomTabBar SelectedIndex="{Binding SelectedTab}" PagePadding="12,6">
<views:BottomTabCollection>
Expand Down
8 changes: 2 additions & 6 deletions samples/Forms/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
xmlns:converters="clr-namespace:SkiaSharpDemo.Converters"
xmlns:views="clr-namespace:SkiaSharpDemo.Views"
x:Class="SkiaSharpDemo.Demos.LottiePage"
Title="Lottie">

<ContentPage.Resources>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
</ContentPage.Resources>

<Grid RowDefinitions="*,Auto">

<controls:SKLottieView x:Name="lottieView"
Expand All @@ -20,7 +16,7 @@
<BoxView Color="Green" Opacity="0.5" CornerRadius="12"
WidthRequest="25" HeightRequest="24" Margin="24"
HorizontalOptions="End" VerticalOptions="Start"
IsVisible="{Binding IsRunning, Source={Reference confettiView}, Converter={StaticResource InvertedBooleanConverter}}" />
IsVisible="{Binding IsComplete, Source={Reference lottieView}}" />

<StackLayout Spacing="12" Padding="12" Grid.Row="1">

Expand Down
16 changes: 0 additions & 16 deletions samples/Maui/SkiaSharpDemo/Converters/InvertedBoolConverter.cs

This file was deleted.

7 changes: 1 addition & 6 deletions samples/Maui/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
xmlns:converters="clr-namespace:SkiaSharpDemo.Converters"
xmlns:views="clr-namespace:SkiaSharpDemo.Views"
x:Class="SkiaSharpDemo.Demos.ConfettiPage"
Title="Confetti">

<ContentPage.Resources>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
</ContentPage.Resources>

<Grid>

<Label Text="{Binding Message}" FontSize="32" FontAttributes="Bold"
Expand All @@ -25,7 +20,7 @@
<BoxView Color="Green" Opacity="0.5" CornerRadius="12"
WidthRequest="25" HeightRequest="24" Margin="24"
HorizontalOptions="End" VerticalOptions="Start"
IsVisible="{Binding IsRunning, Source={Reference confettiView}, Converter={StaticResource InvertedBooleanConverter}}" />
IsVisible="{Binding IsComplete, Source={Reference confettiView}}" />

<views:BottomTabBar SelectedIndex="{Binding SelectedTab}" PagePadding="12,6">
<views:BottomTabCollection>
Expand Down
7 changes: 1 addition & 6 deletions samples/Maui/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
xmlns:converters="clr-namespace:SkiaSharpDemo.Converters"
xmlns:views="clr-namespace:SkiaSharpDemo.Views"
x:Class="SkiaSharpDemo.Demos.LottiePage"
Title="Lottie">

<ContentPage.Resources>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
</ContentPage.Resources>

<Grid RowDefinitions="*,Auto">

<controls:SKLottieView x:Name="lottieView"
Expand All @@ -23,7 +18,7 @@
<BoxView Color="Green" Opacity="0.5" CornerRadius="12"
WidthRequest="25" HeightRequest="24" Margin="24"
HorizontalOptions="End" VerticalOptions="Start"
IsVisible="{Binding IsRunning, Source={Reference confettiView}, Converter={StaticResource InvertedBooleanConverter}}" />
IsVisible="{Binding IsComplete, Source={Reference lottieView}}" />

<VerticalStackLayout Spacing="12" Padding="12" Grid.Row="1">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ public class SKConfettiEmitter : BindableObject
typeof(SKConfettiEmitter),
5.0);

private static readonly BindablePropertyKey IsRunningPropertyKey = BindableProperty.CreateReadOnly(
nameof(IsRunning),
private static readonly BindablePropertyKey IsCompletePropertyKey = BindableProperty.CreateReadOnly(
nameof(IsComplete),
typeof(bool),
typeof(SKConfettiEmitter),
true,
defaultBindingMode: BindingMode.OneWayToSource);
false);

public static readonly BindableProperty IsRunningProperty = IsRunningPropertyKey.BindableProperty;
public static readonly BindableProperty IsCompleteProperty = IsCompletePropertyKey.BindableProperty;

private int totalParticles = 0;
private double totalDuration = 0;
Expand Down Expand Up @@ -65,20 +64,17 @@ public double Duration
set => SetValue(DurationProperty, value);
}

/// <summary>
/// Gets a value indicating whether confetti is being emitted.
/// </summary>
public bool IsRunning
public bool IsComplete
{
get => (bool)GetValue(IsRunningProperty);
private set => SetValue(IsRunningPropertyKey, value);
get => (bool)GetValue(IsCompleteProperty);
private set => SetValue(IsCompletePropertyKey, value);
}

public event Action<int>? ParticlesCreated;

public void Update(TimeSpan deltaTime)
{
if (!IsRunning)
if (IsComplete)
return;

var prevDuration = totalDuration;
Expand All @@ -100,7 +96,10 @@ public void Update(TimeSpan deltaTime)

ParticlesCreated?.Invoke(particles);

UpdateIsRunning();
IsComplete =
Duration == 0 || // burst mode
(MaxParticles > 0 && totalParticles >= MaxParticles) || // reached the max particles
(Duration > 0 && totalDuration >= Duration); // reached the max duration
}

public static SKConfettiEmitter Burst(int particles) =>
Expand All @@ -114,13 +113,5 @@ public static SKConfettiEmitter Infinite(int particleRate) =>

public static SKConfettiEmitter Infinite(int particleRate, int maxParticles) =>
new SKConfettiEmitter(particleRate, maxParticles, -1);

private void UpdateIsRunning()
{
IsRunning =
Duration != 0 && // burst mode
(MaxParticles > 0 && totalParticles < MaxParticles) || // reached the max particles
(Duration > 0 && totalDuration < Duration); // reached the max duration
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public float Size

public SKRect Bounds { get; private set; }

public bool IsRunning { get; private set; } = true;
public bool IsComplete { get; private set; }

public void Draw(SKCanvas canvas)
{
if (!IsRunning || Shape == null)
if (IsComplete || Shape == null)
return;

canvas.Save();
Expand All @@ -81,7 +81,7 @@ public void Draw(SKCanvas canvas)

public void ApplyForce(SKPoint force, TimeSpan deltaTime)
{
if (!IsRunning)
if (IsComplete)
return;

var secs = (float)deltaTime.TotalSeconds;
Expand Down Expand Up @@ -119,11 +119,11 @@ public void ApplyForce(SKPoint force, TimeSpan deltaTime)
var c = Color;
var alpha = c.Alpha - secs;
Color = c.WithAlpha(alpha);
IsRunning = alpha > 0;
IsComplete = alpha <= 0;
}
else
{
IsRunning = false;
IsComplete = true;
}
}

Expand Down
Loading

0 comments on commit 25d0124

Please sign in to comment.