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

Package clean-up for Extensions, Animations, and Behaviors #121

Merged
merged 5 commits into from
Jul 13, 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
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<ToolkitExtensionSourceProject>$(RepositoryDirectory)\components\Extensions\src\CommunityToolkit.WinUI.Extensions.csproj</ToolkitExtensionSourceProject>
<ToolkitHelperSourceProject>$(RepositoryDirectory)\components\Helpers\src\CommunityToolkit.WinUI.Helpers.csproj</ToolkitHelperSourceProject>
<ToolkitEffectSourceProject>$(RepositoryDirectory)\components\Effects\src\CommunityToolkit.WinUI.Effects.csproj</ToolkitEffectSourceProject>
<ToolkitBehaviorSourceProject>$(RepositoryDirectory)\components\Behaviors\src\CommunityToolkit.WinUI.Behaviors.csproj</ToolkitBehaviorSourceProject>
<ToolkitAnimationSourceProject>$(RepositoryDirectory)\components\Animations\src\CommunityToolkit.WinUI.Animations.csproj</ToolkitAnimationSourceProject>
<ToolkitPrimitiveSourceProject>$(RepositoryDirectory)\components\Primitives\src\CommunityToolkit.WinUI.Controls.Primitives.csproj</ToolkitPrimitiveSourceProject>
Expand Down
48 changes: 48 additions & 0 deletions components/Animations/src/Builders/AnimationBuilder.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public AnimationBuilder Opacity(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -128,7 +132,11 @@ public AnimationBuilder Translation(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -162,7 +170,11 @@ public AnimationBuilder Translation(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -297,7 +309,11 @@ public AnimationBuilder Scale(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -337,7 +353,11 @@ public AnimationBuilder Scale(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -371,7 +391,11 @@ public AnimationBuilder Scale(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -432,7 +456,11 @@ public AnimationBuilder CenterPoint(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -466,7 +494,11 @@ public AnimationBuilder CenterPoint(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -525,7 +557,11 @@ public AnimationBuilder Rotation(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -562,7 +598,11 @@ public AnimationBuilder RotationInDegrees(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -800,7 +840,11 @@ public AnimationBuilder Size(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -834,7 +878,11 @@ public AnimationBuilder Size(
RepeatOption? repeat = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down
51 changes: 46 additions & 5 deletions components/Animations/src/Builders/AnimationBuilder.KeyFrames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public IPropertyAnimationBuilder<Vector2> AnchorPoint()
/// </summary>
/// <param name="layer">The target framework layer to animate.</param>
/// <returns>An <see cref="IPropertyAnimationBuilder{T}"/> instance to configure the animation.</returns>
public IPropertyAnimationBuilder<double> Opacity(FrameworkLayer layer = FrameworkLayer.Composition)
public IPropertyAnimationBuilder<double> Opacity(
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
return new PropertyAnimationBuilder<double>(this, nameof(Visual.Opacity), layer);
}
Expand All @@ -52,7 +57,12 @@ public IPropertyAnimationBuilder<double> Opacity(FrameworkLayer layer = Framewor
/// <param name="axis">The target translation axis to animate.</param>
/// <param name="layer">The target framework layer to animate.</param>
/// <returns>An <see cref="IPropertyAnimationBuilder{T}"/> instance to configure the animation.</returns>
public IPropertyAnimationBuilder<double> Translation(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
public IPropertyAnimationBuilder<double> Translation(Axis axis,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -99,7 +109,12 @@ public IPropertyAnimationBuilder<Vector3> Offset()
/// <param name="axis">The target scale axis to animate.</param>
/// <param name="layer">The target framework layer to animate.</param>
/// <returns>An <see cref="IPropertyAnimationBuilder{T}"/> instance to configure the animation.</returns>
public IPropertyAnimationBuilder<double> Scale(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
public IPropertyAnimationBuilder<double> Scale(Axis axis,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand All @@ -125,7 +140,12 @@ public IPropertyAnimationBuilder<Vector3> Scale()
/// <param name="axis">The target scale axis to animate.</param>
/// <param name="layer">The target framework layer to animate.</param>
/// <returns>An <see cref="IPropertyAnimationBuilder{T}"/> instance to configure the animation.</returns>
public IPropertyAnimationBuilder<double> CenterPoint(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
public IPropertyAnimationBuilder<double> CenterPoint(Axis axis,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -160,7 +180,12 @@ public IPropertyAnimationBuilder<double> Rotation()
/// </summary>
/// <param name="layer">The target framework layer to animate.</param>
/// <returns>An <see cref="IPropertyAnimationBuilder{T}"/> instance to configure the animation.</returns>
public IPropertyAnimationBuilder<double> RotationInDegrees(FrameworkLayer layer = FrameworkLayer.Composition)
public IPropertyAnimationBuilder<double> RotationInDegrees(
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
{
if (layer == FrameworkLayer.Composition)
{
Expand Down Expand Up @@ -246,7 +271,11 @@ public AnimationBuilder NormalizedKeyFrames<T>(
TimeSpan? duration = null,
RepeatOption? repeatOption = null,
AnimationDelayBehavior? delayBehavior = null,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
where T : unmanaged
{
if (layer == FrameworkLayer.Composition)
Expand Down Expand Up @@ -300,7 +329,11 @@ public AnimationBuilder NormalizedKeyFrames<T, TState>(
TimeSpan? duration = null,
RepeatOption? repeatOption = null,
AnimationDelayBehavior? delayBehavior = null,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
where T : unmanaged
{
if (layer == FrameworkLayer.Composition)
Expand Down Expand Up @@ -349,7 +382,11 @@ public AnimationBuilder TimedKeyFrames<T>(
TimeSpan? delay = null,
RepeatOption? repeat = null,
AnimationDelayBehavior? delayBehavior = null,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
where T : unmanaged
{
if (layer == FrameworkLayer.Composition)
Expand Down Expand Up @@ -396,7 +433,11 @@ public AnimationBuilder TimedKeyFrames<T, TState>(
TimeSpan? delay = null,
RepeatOption? repeatOption = null,
AnimationDelayBehavior? delayBehavior = null,
#if !HAS_UNO
FrameworkLayer layer = FrameworkLayer.Composition)
#else
FrameworkLayer layer = FrameworkLayer.Xaml)
#endif
where T : unmanaged
{
if (layer == FrameworkLayer.Composition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
// We can retrieve the total duration from the last timed keyframe, and then set
// this as the target duration and use it to normalize the keyframe progresses.
ArraySegment<KeyFrameInfo> keyFrames = this.keyFrames.GetArraySegment();
#if !NETSTANDARD2_0
TimeSpan duration = keyFrames[keyFrames.Count - 1].GetTimedProgress(default);
#else
TimeSpan duration = keyFrames.Array[keyFrames.Count - 1].GetTimedProgress(default);
#endif

return NormalizedKeyFrameAnimationBuilder<T>.GetAnimation(
targetHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ public bool TryInsertExpressionKeyFrame(KeyFrameAnimation animation, TimeSpan du
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetNormalizedProgress(TimeSpan duration)
{
#if !NETSTANDARD2_0
return (float)Math.Clamp(this.progress.TotalMilliseconds / duration.TotalMilliseconds, 0, 1);
#else
var result = this.progress.TotalMilliseconds / duration.TotalMilliseconds;
return (float)Math.Max(Math.Min(result, 1), 0);
#endif
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<PropertyGroup>
<ToolkitComponentName>Animations</ToolkitComponentName>
<Description>This package contains Animations.</Description>
<Version>8.0.0-beta.1</Version>
<Version>8.0.0-beta.2</Version>

<!-- Rns suffix is required for namespaces shared across projects. See https://github.com/CommunityToolkit/Labs-Windows/issues/152 -->
<RootNamespace>CommunityToolkit.WinUI.AnimationsRns</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="CommunityToolkit.WinUI.Behaviors.Animations" />
<InternalsVisibleTo Include="CommunityToolkit.WinUI.Behaviors" />
<PackageReference Include="PolySharp" Version="1.13.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -19,7 +19,6 @@

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)" />
<ProjectReference Include="$(ToolkitEffectSourceProject)" />
</ItemGroup>

<!-- Sets this up as a toolkit component's source project -->
Expand Down
2 changes: 1 addition & 1 deletion components/Animations/src/MultiTarget.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
MultiTarget is a custom property that indicates which target a project is designed to be built for / run on.
Used to create project references, generate solution files, enable/disable TargetFrameworks, and build nuget packages.
-->
<MultiTarget>uwp;wasdk;</MultiTarget>
<MultiTarget>uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android;</MultiTarget>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion components/Animations/src/Xaml/Abstract/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CommunityToolkit.WinUI.Animations;
/// <summary>
/// A base model representing an animation that can be used in XAML.
/// </summary>
public abstract class Animation : DependencyObject, ITimeline
public abstract partial class Animation : DependencyObject, ITimeline
{
/// <summary>
/// Gets or sets the optional initial delay for the animation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ public abstract class CustomAnimation<TValue, TKeyFrame> : ImplicitAnimation<TVa
/// Gets or sets the target framework layer for the animation. This is only supported
/// for a set of animation types (see the docs for more on this). Furthermore, this is
/// ignored when the animation is being used as an implicit composition animation.
#if !HAS_UNO
/// The default value is <see cref="FrameworkLayer.Composition"/>.
/// </summary>
public FrameworkLayer Layer { get; set; }
#else
/// The default value is <see cref="FrameworkLayer.Xaml"/>.
/// </summary>
public FrameworkLayer Layer { get; set; } = FrameworkLayer.Xaml;
#endif

/// <inheritdoc/>
protected override string ExplicitTarget => Target!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

namespace CommunityToolkit.WinUI.Animations;

#if HAS_UNO
/// <summary>
/// A base model representing a key frame for Uno Platform compatibility
/// </summary>
public abstract partial class KeyFrame : DependencyObject
{
}
#endif

/// <summary>
/// A base model representing a typed keyframe that can be used in XAML.
/// </summary>
Expand All @@ -14,7 +23,11 @@ namespace CommunityToolkit.WinUI.Animations;
/// This can differ from <typeparamref name="TKeyFrame"/> to facilitate XAML parsing.
/// </typeparam>
/// <typeparam name="TKeyFrame">The actual type of keyframe values in use.</typeparam>
public abstract class KeyFrame<TValue, TKeyFrame> : DependencyObject, IKeyFrame<TKeyFrame>
#if !HAS_UNO
public abstract partial class KeyFrame<TValue, TKeyFrame> : DependencyObject, IKeyFrame<TKeyFrame>
#else
public abstract partial class KeyFrame<TValue, TKeyFrame> : KeyFrame, IKeyFrame<TKeyFrame>
#endif
{
/// <summary>
/// Gets or sets the key time for the current keyframe. This is a normalized
Expand Down
2 changes: 1 addition & 1 deletion components/Animations/src/Xaml/Activities/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CommunityToolkit.WinUI.Animations;
/// <summary>
/// Base class to use when creating activities which accept a <see cref="Delay"/>.
/// </summary>
public abstract class Activity : DependencyObject, IActivity
public abstract partial class Activity : DependencyObject, IActivity
{
/// <summary>
/// Gets or sets the <see cref="TimeSpan"/> to wait before running the activity.
Expand Down
Loading