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

Make some lottie image source members public #198

Merged
merged 3 commits into from
Aug 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class SKFileLottieImageSource : SKLottieImageSource
{
public static BindableProperty FileProperty = BindableProperty.Create(
public static readonly BindableProperty FileProperty = BindableProperty.Create(
nameof(File), typeof(string), typeof(SKFileLottieImageSource),
propertyChanged: OnSourceChanged);

Expand All @@ -15,7 +15,7 @@ public string? File
public override bool IsEmpty =>
string.IsNullOrEmpty(File);

internal override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
public override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
{
if (IsEmpty || string.IsNullOrEmpty(File))
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
namespace SkiaSharp.Extended.UI.Controls;

[TypeConverter(typeof(Converters.SKLottieImageSourceConverter))]
public class SKLottieImageSource : Element
public abstract class SKLottieImageSource : Element
{
private readonly WeakEventManager weakEventManager = new();

public virtual bool IsEmpty => true;

internal virtual Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default) =>
throw new NotImplementedException();
public abstract Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default);

internal static object FromUri(Uri uri) =>
public static object FromUri(Uri uri) =>
new SKUriLottieImageSource { Uri = uri };

internal static object FromFile(string file) =>
public static object FromFile(string file) =>
new SKFileLottieImageSource { File = file };

internal event EventHandler SourceChanged
public static object FromStream(Func<CancellationToken, Task<Stream?>> getter) =>
new SKStreamLottieImageSource { Stream = getter };

public static object FromStream(Stream stream) =>
FromStream(token => Task.FromResult<Stream?>(stream));

public event EventHandler SourceChanged
{
add => weakEventManager.AddEventHandler(value);
remove => weakEventManager.RemoveEventHandler(value);
}

internal static void OnSourceChanged(BindableObject bindable, object oldValue, object newValue)
protected static void OnSourceChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SKLottieImageSource source)
source.weakEventManager.HandleEvent(source, EventArgs.Empty, nameof(SourceChanged));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class SKStreamLottieImageSource : SKLottieImageSource
{
public static BindableProperty StreamProperty = BindableProperty.Create(
public static readonly BindableProperty StreamProperty = BindableProperty.Create(
nameof(Stream), typeof(Func<CancellationToken, Task<Stream?>>), typeof(SKStreamLottieImageSource),
propertyChanged: OnSourceChanged);

Expand All @@ -14,7 +14,7 @@ public class SKStreamLottieImageSource : SKLottieImageSource

public override bool IsEmpty => Stream is null;

internal override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
public override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
{
if (IsEmpty || Stream is null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class SKUriLottieImageSource : SKLottieImageSource
{
public static BindableProperty UriProperty = BindableProperty.Create(
public static readonly BindableProperty UriProperty = BindableProperty.Create(
nameof(Uri), typeof(Uri), typeof(SKUriLottieImageSource),
propertyChanged: OnSourceChanged);

Expand All @@ -14,7 +14,7 @@ public Uri? Uri

public override bool IsEmpty => Uri is null;

internal override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
public override async Task<Skottie.Animation?> LoadAnimationAsync(CancellationToken cancellationToken = default)
{
if (IsEmpty || Uri is null)
return null;
Expand Down