Skip to content

Add nullable attributes, TimeSpan and overloads to Skottie - #2119

Merged
mattleibow merged 5 commits into
mainfrom
dev/anim-overloads
Jun 20, 2022
Merged

Add nullable attributes, TimeSpan and overloads to Skottie#2119
mattleibow merged 5 commits into
mainfrom
dev/anim-overloads

Conversation

@mattleibow

@mattleibow mattleibow commented Jun 18, 2022

Copy link
Copy Markdown
Contributor

Description of Change

This PR just adds some overloads and nullable annotations to the Skottie Animation type.

While working with the new type, I was unsure what the t in all the seek methods were, so I renamed the parameters to be more explicit: percent, frame, seconds. I also added an overload for SeekFrameTime to take a TimeSpan because that was useful.

I also made a change to make Duration a TimeSpan. This was again to reduce confusion about the actual unit, but also keeps all the time concepts as TimeSpan because it feels more accurate?

I added some "overloads" for the TryCreate and TryParse to just return null instead (Create and Parse). The reason for null and not an exception is that for some reason, null was used to when there was an error reading things. It should have been an exception, but here we are. Skia does not really have "errors" but more it tries and then says nah, here is a big fat null for you. At least it is mostly consistent.

Is the SkiaSharp API perfect? Yes. There have been no regrets in the design and naming of this perfect library. *looks for tissue to dry eyes*

@mattleibow mattleibow changed the title Add nullable attributes and overloads to Skottie Add nullable attributes, TimeSpan and overloads to Skottie Jun 18, 2022
Comment on lines +24 to +27
public static Animation? Parse (string json) =>
TryParse (json, out var animation)
? animation
: null;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "overloads" to return the object, or null on some error that we will never know about.

Comment on lines -56 to +83
public void Seek (double t, InvalidationController ic = null)
=> SkottieApi.skottie_animation_seek (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);
public void Seek (double percent, InvalidationController? ic = null)
=> SkottieApi.skottie_animation_seek (Handle, (float)percent, ic?.Handle ?? IntPtr.Zero);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the parameters.

Comment on lines -65 to +95
public double Duration
=> SkottieApi.skottie_animation_get_duration (Handle);
public void SeekFrameTime (TimeSpan time, InvalidationController? ic = null)
=> SeekFrameTime (time.TotalSeconds, ic);

public TimeSpan Duration
=> TimeSpan.FromSeconds(SkottieApi.skottie_animation_get_duration (Handle));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the new SeekFrameTime(TimeSpan) and changed Duration to be a TimeSpan.

Comment thread source/SkiaSharp.Build.props Outdated
Comment thread source/SkiaSharp.Build.targets
@mattleibow

Copy link
Copy Markdown
Contributor Author

/azp run SkiaSharp

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mattleibow

Copy link
Copy Markdown
Contributor Author

/azp run SkiaSharp

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant