Skip to content

Commit

Permalink
Clean-up ShadowAnimation type and add rest of animatable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-hawker committed Aug 25, 2021
1 parent 71322fc commit b88e4a2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/XamlOnlyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
<ani:SaturationEffectAnimation />
<ani:AnimationScope />
<ani:ExposureEffectAnimation />
<ani:BlurRadiusDropShadowAnimation />
<ani:ColorDropShadowAnimation />
<ani:OffsetDropShadowAnimation />
<ani:OpacityDropShadowAnimation />
</ani:AnimationSet>
</ani:Explicit.Animations>
<media:UIElementExtensions.VisualFactory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// A custom animation targeting a property on an <see cref="AttachedShadowBase"/> instance.
/// A custom animation targeting a property on an <see cref="IAttachedShadow"/> instance.
/// </summary>
/// <typeparam name="TShadow">The <see cref="FrameworkElement"/> containing the shadow to animate.</typeparam>
/// <typeparam name="TValue">
/// The type to use for the public <see cref="Animation{TValue,TKeyFrame}.To"/> and <see cref="Animation{TValue,TKeyFrame}.From"/>
/// properties. 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 ShadowAnimation<TShadow, TValue, TKeyFrame> : Animation<TValue, TKeyFrame>, IAttachedTimeline
where TShadow : AttachedShadowBase
public abstract class ShadowAnimation<TValue, TKeyFrame> : Animation<TValue, TKeyFrame>, IAttachedTimeline
where TKeyFrame : unmanaged
{
/// <summary>
/// Gets or sets the linked <typeparamref name="TShadow"/> instance to animate.
/// Gets or sets the linked <see cref="IAttachedShadow"/> instance to animate.
/// </summary>
public TShadow? Target
public IAttachedShadow? Target
{
get => (TShadow?)GetValue(TargetProperty);
get => (IAttachedShadow?)GetValue(TargetProperty);
set => SetValue(TargetProperty, value);
}

Expand All @@ -39,8 +37,8 @@ public TShadow? Target
/// </summary>
public static readonly DependencyProperty TargetProperty = DependencyProperty.Register(
nameof(Target),
typeof(TShadow),
typeof(ShadowAnimation<TShadow, TValue, TKeyFrame>),
typeof(IAttachedShadow),
typeof(ShadowAnimation<TValue, TKeyFrame>),
new PropertyMetadata(null));

/// <inheritdoc/>
Expand All @@ -63,7 +61,7 @@ static AnimationBuilder ThrowArgumentNullException()
return ThrowArgumentNullException();
}

if (Target is TShadow allShadows)
if (Target is IAttachedShadow allShadows)
{
// in this case we'll animate all the shadows being used.
foreach (var context in allShadows.GetElementContextEnumerable()) //// TODO: Find better way!!!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI.Composition;

namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// A blur radius animation working on the composition layer.
/// </summary>
public sealed class BlurRadiusDropShadowAnimation : ShadowAnimation<double?, double>
{
/// <inheritdoc/>
protected override string ExplicitTarget => nameof(DropShadow.BlurRadius);

/// <inheritdoc/>
protected override (double?, double?) GetParsedValues()
{
return (To, From);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI;
using Windows.UI.Composition;

#pragma warning disable CS0419

namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// A custom <see cref="Color"/> animation on a <see cref="DropShadow"/>.
/// </summary>
public sealed class ColorDropShadowAnimation : ShadowAnimation<Color?, Color>
{
/// <inheritdoc/>
protected override string ExplicitTarget => nameof(DropShadow.Color);

/// <inheritdoc/>
protected override (Color?, Color?) GetParsedValues()
{
return (To, From);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

using System.Numerics;
using Windows.UI.Composition;
using Windows.UI.Xaml;

namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// An offset animation working on the composition layer.
/// </summary>
public sealed class OffsetDropShadowAnimation : ShadowAnimation<AttachedShadowBase, string, Vector3>
public sealed class OffsetDropShadowAnimation : ShadowAnimation<string, Vector3>
{
/// <inheritdoc/>
protected override string ExplicitTarget => nameof(DropShadow.Offset);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI.Composition;

namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// An opacity animation working on the composition layer.
/// </summary>
public sealed class OpacityDropShadowAnimation : ShadowAnimation<double?, double>
{
/// <inheritdoc/>
protected override string ExplicitTarget => nameof(DropShadow.Opacity);

/// <inheritdoc/>
protected override (double?, double?) GetParsedValues()
{
return (To, From);
}
}
}

0 comments on commit b88e4a2

Please sign in to comment.