From 33628908248430882ed7ce22f8a49a09f64b01db Mon Sep 17 00:00:00 2001
From: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Date: Wed, 16 Dec 2020 17:29:51 -0800
Subject: [PATCH 001/171] Creating Microsoft.Toolkit.Uwp.UI.Behaviors
Removes ScrollHeader from the Controls Package
Updates Sample pages to use Behaviors instead from new Behaviors package
TODO/Broken:
- Animation Behaviors Currently don't have a home (still in folder structure of Animations, most likely removed for new approach using Behaviors directly w/ new Animation System)
- General Animation extensions removed (to be replaced with a new coordinated system)
- Blur/Saturation Effect extensions don't have a home (to move to Media package?)
- Sample App
- Graph Control Samples (needs to be rebuilt with new Behaviors package)
- ViewportBehavior Example (was using Blur Extension)
- Re-apply Blur effect to the backgrounds in Shell.xaml as was using Behavior
---
.../Microsoft.Toolkit.Uwp.SampleApp.csproj | 77 +------
.../Models/Sample.cs | 22 +-
.../FadeHeader/FadeHeaderBehaviorPage.xaml | 10 +-
.../FadeHeader/FadeHeaderBehaviorXaml.bind | 4 +-
.../IconExtensions/IconExtensionsPage.xaml.cs | 4 -
.../ImplicitAnimationsCode.bind | 16 +-
.../LoginButton/LoginButtonPage.xaml | 12 +-
.../SamplePages/OnDevice/OnDevicePage.xaml.cs | 4 -
.../PeoplePicker/PeoplePickerPage.xaml | 8 +-
.../PersonView/PersonViewPage.xaml | 4 +-
.../ScrollHeader/ScrollHeaderCode.bind | 45 +++--
.../ScrollHeader/ScrollHeaderPage.xaml | 18 +-
.../ScrollViewerExtensionsPage.xaml | 131 ++++++------
.../ScrollViewerExtensionsXaml.bind | 47 +++--
.../ViewportBehaviorPage.xaml.cs | 6 +-
Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml | 157 +++++++++------
.../Custom/PivotHeaderItemUnderlineStyle.xaml | 173 ++++++++++------
...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 20 +-
.../SurfaceLoader.cs | 190 ------------------
.../ApiInformationHelper.cs | 14 ++
.../BehaviorBase.cs | 0
.../Focus}/AutoFocusBehavior.cs | 0
.../Focus}/FocusBehavior.cs | 0
.../Headers}/FadeHeaderBehavior.cs | 4 +-
.../Headers}/QuickReturnHeaderBehavior.cs | 3 +-
.../Headers}/StickyHeaderBehavior.cs | 3 +-
.../Microsoft.Toolkit.Uwp.UI.Behaviors.csproj | 31 +++
.../Microsoft.Toolkit.Uwp.UI.Behaviors.rd.xml | 5 +
.../Viewport}/ViewportBehavior.cs | 0
.../Microsoft.Toolkit.Uwp.UI.Controls.csproj | 1 +
.../ScrollHeader/ScrollHeader.cs | 96 ---------
.../ScrollHeader/ScrollHeader.xaml | 16 --
.../ScrollHeader/ScrollHeaderMode.cs | 32 ---
.../Themes/Generic.xaml | 1 -
.../Microsoft.Toolkit.Uwp.UI.csproj | 10 +-
Windows Community Toolkit.sln | 23 +++
36 files changed, 466 insertions(+), 721 deletions(-)
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/SurfaceLoader.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Behaviors/ApiInformationHelper.cs
rename {Microsoft.Toolkit.Uwp.UI/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors}/BehaviorBase.cs (100%)
rename {Microsoft.Toolkit.Uwp.UI/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Focus}/AutoFocusBehavior.cs (100%)
rename {Microsoft.Toolkit.Uwp.UI/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Focus}/FocusBehavior.cs (100%)
rename {Microsoft.Toolkit.Uwp.UI.Animations/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Headers}/FadeHeaderBehavior.cs (98%)
rename {Microsoft.Toolkit.Uwp.UI.Animations/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Headers}/QuickReturnHeaderBehavior.cs (99%)
rename {Microsoft.Toolkit.Uwp.UI.Animations/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Headers}/StickyHeaderBehavior.cs (98%)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
create mode 100644 Microsoft.Toolkit.Uwp.UI.Behaviors/Properties/Microsoft.Toolkit.Uwp.UI.Behaviors.rd.xml
rename {Microsoft.Toolkit.Uwp.UI/Behaviors => Microsoft.Toolkit.Uwp.UI.Behaviors/Viewport}/ViewportBehavior.cs (100%)
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.xaml
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeaderMode.cs
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
index c163498a562..8c9bb57abca 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
@@ -112,9 +112,6 @@
10.1901.28001
-
- 6.1.0-build.6
- 2.4.2
@@ -294,7 +291,6 @@
-
@@ -303,7 +299,6 @@
-
@@ -325,7 +320,6 @@
-
@@ -336,7 +330,6 @@
-
@@ -344,10 +337,7 @@
-
-
-
@@ -380,11 +370,7 @@
-
-
-
-
@@ -396,13 +382,7 @@
-
-
-
-
-
-
@@ -422,8 +402,6 @@
-
- Designer
@@ -440,8 +418,6 @@
-
- Designer
@@ -832,9 +808,6 @@
BladePage.xaml
-
- BlurBehaviorPage.xaml
- AlignmentGridPage.xaml
@@ -844,9 +817,6 @@
MicrosoftTranslatorPage.xaml
-
- SaturationBehaviorPage.xaml
- TileControlPage.xaml
@@ -867,9 +837,6 @@
-
- LightBehaviorPage.xaml
- LinkedInPage.xaml
@@ -915,12 +882,6 @@
TwitterPage.xaml
-
- OffsetBehaviorPage.xaml
-
-
- FadeBehaviorPage.xaml
- ImageExPage.xaml
@@ -934,12 +895,6 @@
WeatherLiveTileAndToastPage.xaml
-
- RotateBehaviorPage.xaml
-
-
- ScaleBehaviorPage.xaml
- RadialGaugePage.xaml
@@ -1305,10 +1260,6 @@
DesignerMSBuild:Compile
-
- MSBuild:Compile
- Designer
- MSBuild:CompileDesigner
@@ -1325,10 +1276,6 @@
MSBuild:CompileDesigner
-
- Designer
- MSBuild:Compile
- MSBuild:CompileDesigner
@@ -1357,10 +1304,6 @@
MSBuild:CompileDesigner
-
- Designer
- MSBuild:Compile
- DesignerMSBuild:Compile
@@ -1393,14 +1336,6 @@
MSBuild:CompileDesigner
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
- DesignerMSBuild:Compile
@@ -1453,14 +1388,6 @@
MSBuild:CompileDesigner
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
- DesignerMSBuild:Compile
@@ -1531,6 +1458,10 @@
{1ae2cb5c-58a0-4f12-8e6f-2cd4aaadb34c}Microsoft.Toolkit.Uwp.Samples.BackgroundTasks
+
+ {d4ff799d-0df2-495a-adc9-3bbc4aef8971}
+ Microsoft.Toolkit.Uwp.UI.Behaviors
+ {daeb9cec-c817-33b2-74b2-bc379380db72}Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
index 805261aa7ec..6bc44c71e22 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
@@ -16,8 +16,6 @@
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
-using Microsoft.Toolkit.Graph.Converters;
-using Microsoft.Toolkit.Graph.Providers;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using Microsoft.Toolkit.Uwp.SampleApp.Models;
@@ -658,16 +656,16 @@ private static Type LookForTypeByName(string typeName)
}
// Search in Microsoft.Toolkit.Graph.Controls
- var graphControlsProxyType = typeof(UserToPersonConverter);
- assembly = graphControlsProxyType.GetTypeInfo().Assembly;
-
- foreach (var typeInfo in assembly.ExportedTypes)
- {
- if (typeInfo.Name == typeName)
- {
- return typeInfo;
- }
- }
+ //var graphControlsProxyType = typeof(UserToPersonConverter);
+ //assembly = graphControlsProxyType.GetTypeInfo().Assembly;
+
+ //foreach (var typeInfo in assembly.ExportedTypes)
+ //{
+ // if (typeInfo.Name == typeName)
+ // {
+ // return typeInfo;
+ // }
+ //}
// Search in Microsoft.Toolkit.Uwp.UI.Animations
var animationsProxyType = EasingType.Default;
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorPage.xaml
index a2ae6567063..ce25561b9d0 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorPage.xaml
@@ -7,12 +7,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
-
-
-
-
-
-
-
-
+
+
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorXaml.bind
index 851181f5164..60ffa5965b2 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorXaml.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader/FadeHeaderBehaviorXaml.bind
@@ -3,7 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
- xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
+ xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
mc:Ignorable="d">
@@ -24,7 +24,7 @@
Margin="12" />
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs
index 0311ad04acf..35971fb6a53 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs
@@ -2,10 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using Microsoft.Toolkit.Uwp.UI.Animations.Behaviors;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
-using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit Animations/ImplicitAnimationsCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit Animations/ImplicitAnimationsCode.bind
index 71ab3ffa96e..ca217f3cd13 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit Animations/ImplicitAnimationsCode.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit Animations/ImplicitAnimationsCode.bind
@@ -19,24 +19,24 @@
extensions:VisualExtensions.CenterPoint="50,50,0">
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/LoginButton/LoginButtonPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/LoginButton/LoginButtonPage.xaml
index cd37f20d156..ca429d0df3f 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/LoginButton/LoginButtonPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/LoginButton/LoginButtonPage.xaml
@@ -1,19 +1,19 @@
-
+
-
-
+
+
-
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OnDevice/OnDevicePage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OnDevice/OnDevicePage.xaml.cs
index 9943ccb283d..274c96025f0 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OnDevice/OnDevicePage.xaml.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OnDevice/OnDevicePage.xaml.cs
@@ -2,10 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using Microsoft.Toolkit.Uwp.UI.Animations.Behaviors;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
-using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PeoplePicker/PeoplePickerPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PeoplePicker/PeoplePickerPage.xaml
index 829819c6c95..c4da0eaa5ae 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PeoplePicker/PeoplePickerPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PeoplePicker/PeoplePickerPage.xaml
@@ -7,10 +7,12 @@
xmlns:wgt="using:Microsoft.Toolkit.Graph.Controls"
mc:Ignorable="d">
-
+
-
+
-
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PersonView/PersonViewPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PersonView/PersonViewPage.xaml
index 702efbf97d2..fc19d88e848 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PersonView/PersonViewPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PersonView/PersonViewPage.xaml
@@ -5,8 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wgt="using:Microsoft.Toolkit.Graph.Controls"
mc:Ignorable="d">
-
+
-
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderCode.bind
index 8303522e746..9edcd2542b6 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderCode.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderCode.bind
@@ -2,34 +2,37 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:models="using:Microsoft.Toolkit.Uwp.SampleApp.Models"
+ xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
+ xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderPage.xaml
index d95346f0b88..44a877fd63d 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollHeader/ScrollHeaderPage.xaml
@@ -1,19 +1,15 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsPage.xaml
index 08bf65c2e7c..d4da6b9a6da 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsPage.xaml
@@ -1,10 +1,12 @@
-
@@ -14,47 +16,49 @@
+ extensions:ScrollViewerExtensions.VerticalScrollBarMargin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}">
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+ Grid.Column="0"
+ Width="100"
+ Height="100"
+ Margin="0,0,24,0"
+ Source="ms-appx:///Assets/ToolkitLogo.png" />
+ VerticalAlignment="Center"
+ Text="{Binding Title}"
+ TextTrimming="CharacterEllipsis" />
@@ -66,45 +70,44 @@
-
-
+
-
-
+ HorizontalAlignment="Center"
+ VerticalAlignment="Center"
+ Orientation="Horizontal"
+ Spacing="4">
+
+
-
-
-
-
+
+
+
+
-
+ Fill="Crimson"
+ Points="0,0 0,60 60,60 60,0"
+ Stroke="DarkRed" />
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsXaml.bind
index 555377bdebe..6b28c95e185 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsXaml.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions/ScrollViewerExtensionsXaml.bind
@@ -5,6 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
+ xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
mc:Ignorable="d">
@@ -15,29 +17,30 @@
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ViewportBehavior/ViewportBehaviorPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ViewportBehavior/ViewportBehaviorPage.xaml.cs
index eb09f531121..17a683842cb 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ViewportBehavior/ViewportBehaviorPage.xaml.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ViewportBehavior/ViewportBehaviorPage.xaml.cs
@@ -39,7 +39,7 @@ public void OnXamlRendered(FrameworkElement control)
if (control.FindChildByName("EffectElement") is Image effectElement)
{
_effectElement = effectElement;
- _effectElement.Blur(value: 10, duration: 0).Start();
+ ////TODO: _effectElement.Blur(value: 10, duration: 0).Start();
}
if (control.FindChildByName("EffectElementHost") is FrameworkElement effectElementHost)
@@ -72,7 +72,7 @@ private async void EffectElementHost_EnteredViewport(object sender, EventArgs e)
{
AddLog("Entered viewport");
- await _effectElement.Blur(value: 0, duration: 1500).StartAsync();
+ ////TODO: await _effectElement.Blur(value: 0, duration: 1500).StartAsync();
}
private void EffectElementHost_EnteringViewport(object sender, EventArgs e)
@@ -87,7 +87,7 @@ private async void EffectElementHost_ExitedViewport(object sender, EventArgs e)
AddLog("Exited viewport");
_effectElement.Source = null;
- await _effectElement.Blur(value: 8, duration: 0).StartAsync();
+ ////TODO: await _effectElement.Blur(value: 8, duration: 0).StartAsync();
}
private void EffectElementHost_ExitingViewport(object sender, EventArgs e)
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml b/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml
index 7aa45fcdc86..fc16ce0693f 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml
@@ -1,15 +1,15 @@
+ Style="{StaticResource ToolkitNavViewStyle}">
+ QueryIcon="Find"
+ QuerySubmitted="SearchBox_QuerySubmitted"
+ TextChanged="SearchBox_TextChanged" />
-
+
-
+ Duration="0" />-->
-
+
-
+
-
+
+ ShadowOpacity="0.7"
+ Color="Black">
@@ -89,35 +93,47 @@
-
+
-
+
-
-
+
+
-
-
+
+
@@ -125,30 +141,30 @@
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Styles/Custom/PivotHeaderItemUnderlineStyle.xaml b/Microsoft.Toolkit.Uwp.SampleApp/Styles/Custom/PivotHeaderItemUnderlineStyle.xaml
index 73231c861a7..7d7ad535788 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Styles/Custom/PivotHeaderItemUnderlineStyle.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Styles/Custom/PivotHeaderItemUnderlineStyle.xaml
@@ -1,14 +1,17 @@
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -43,71 +79,97 @@
+ Storyboard.TargetProperty="X"
+ To="{ThemeResource PivotHeaderItemLockedTranslation}"
+ Duration="0" />
+ Storyboard.TargetProperty="(UIElement.Opacity)"
+ To="0"
+ Duration="0" />
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -121,25 +183,6 @@
-
-
-
-
-
-
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
index df6558d9426..f31624a8267 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
@@ -7,22 +7,34 @@
This library provides helpers and extensions on top of Windows Composition and XAML storyboards. It is part of the Windows Community Toolkit.
Namespace:
- - Behaviors: Blur, CompositionBehaviorBase, CompositionBehaviorBase, Fade, FadeHeaderBehavior, Light, Offset, QuickReturnHeaderBehavior, Rotate, Saturation, Scale, StickyHeaderBehavior.
- CompositionAnimations:
- Animations: AnimationBase, OffsetAnimation, OpacityAnimation, RotationAnimation, RotationInDegreesAnimation, ScalarAnimation, ScaleAnimation, TranslationAnimation, TypedAnimationBase, Vector2Animation, Vector3Animation, Vector4Animation
- CompositionAnimations: ExpressionKeyFrame, KeyFrame, KeyFrameCollection, ScalarKeyFrame, TypedKeyFrame, Vector2KeyFrame, Vector3KeyFrame, Vector4KeyFrame
- ConnectedAnimations: Connected, ConnectedAnimationHelper, ConnectedAnimationListProperty, ConnectedAnimationProperties
- - Effects: AnimationEffect, Blur, Saturation
- Expressions: ExpressionNodes, ExpressionValues, ReferenceNodes, CompositionExtensions, ExpressionFunctions, OperationType
- AnimationExtensions: Blur, Fade, Light, Offset, Rotate, Saturation, Scale
UWP Toolkit Windows Animations Composition Connected Implicit XAML
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/SurfaceLoader.cs b/Microsoft.Toolkit.Uwp.UI.Animations/SurfaceLoader.cs
deleted file mode 100644
index 8610c13fb83..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/SurfaceLoader.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-// 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 System;
-using System.Threading.Tasks;
-using Microsoft.Graphics.Canvas;
-using Microsoft.Graphics.Canvas.Text;
-using Microsoft.Graphics.Canvas.UI.Composition;
-using Windows.Foundation;
-using Windows.Foundation.Metadata;
-using Windows.Graphics.DirectX;
-using Windows.UI;
-using Windows.UI.Composition;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// A delegate for load time effects.
- ///
- /// The bitmap.
- /// The device.
- /// The size target.
- /// A CompositeDrawingSurface
- public delegate CompositionDrawingSurface LoadTimeEffectHandler(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget);
-
- ///
- /// The SurfaceLoader is responsible to loading images into Composition Objects.
- ///
- [Deprecated("This class is deprecated, please use the SurfaceLoader class from the Microsoft.Toolkit.Uwp.UI.Media package.", DeprecationType.Deprecate, 6)]
- public class SurfaceLoader
- {
- ///
- /// A flag to store the initialized state.
- ///
- private static bool _intialized;
-
- ///
- /// The compositor
- ///
- private static Compositor _compositor;
-
- ///
- /// The canvas device
- ///
- private static CanvasDevice _canvasDevice;
-
- ///
- /// The composition graphic device to determine which GPU is handling the request.
- ///
- private static CompositionGraphicsDevice _compositionDevice;
-
- ///
- /// Initializes the specified compositor.
- ///
- /// The compositor.
- public static void Initialize(Compositor compositor)
- {
- if (!_intialized)
- {
- _compositor = compositor;
- _canvasDevice = new CanvasDevice();
- _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
-
- _intialized = true;
- }
- }
-
- ///
- /// Uninitializes this instance.
- ///
- public static void Uninitialize()
- {
- _compositor = null;
-
- if (_compositionDevice != null)
- {
- _compositionDevice.Dispose();
- _compositionDevice = null;
- }
-
- if (_canvasDevice != null)
- {
- _canvasDevice.Dispose();
- _canvasDevice = null;
- }
-
- _intialized = false;
- }
-
- ///
- /// Gets a value indicating whether this instance is initialized.
- ///
- ///
- /// true if this instance is initialized; otherwise, false.
- ///
- public static bool IsInitialized
- {
- get
- {
- return _intialized;
- }
- }
-
- ///
- /// Loads an image from the URI.
- ///
- /// The URI.
- ///
- public static async Task LoadFromUri(Uri uri)
- {
- return await LoadFromUri(uri, Size.Empty);
- }
-
- ///
- /// Loads an image from URI with a specified size.
- ///
- /// The URI.
- /// The size target.
- ///
- public static async Task LoadFromUri(Uri uri, Size sizeTarget)
- {
- CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);
- Size sizeSource = bitmap.Size;
-
- if (sizeTarget.IsEmpty)
- {
- sizeTarget = sizeSource;
- }
-
- CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(
- sizeTarget,
- DirectXPixelFormat.B8G8R8A8UIntNormalized,
- DirectXAlphaMode.Premultiplied);
-
- using (var ds = CanvasComposition.CreateDrawingSession(surface))
- {
- ds.Clear(Color.FromArgb(0, 0, 0, 0));
- ds.DrawImage(bitmap, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), new Rect(0, 0, sizeSource.Width, sizeSource.Height));
- }
-
- return surface;
- }
-
- ///
- /// Loads the text on to a .
- ///
- /// The text.
- /// The size target.
- /// The text format.
- /// Color of the text.
- /// Color of the bg.
- ///
- public static CompositionDrawingSurface LoadText(string text, Size sizeTarget, CanvasTextFormat textFormat, Color textColor, Color bgColor)
- {
- CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(
- sizeTarget,
- DirectXPixelFormat.B8G8R8A8UIntNormalized,
- DirectXAlphaMode.Premultiplied);
-
- using (var ds = CanvasComposition.CreateDrawingSession(surface))
- {
- ds.Clear(bgColor);
- ds.DrawText(text, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), textColor, textFormat);
- }
-
- return surface;
- }
-
- ///
- /// Loads an image from URI, with a specified size.
- ///
- /// The URI.
- /// The size target.
- /// The load effect handler callback.
- ///
- public static async Task LoadFromUri(Uri uri, Size sizeTarget, LoadTimeEffectHandler loadEffectHandler)
- {
- if (loadEffectHandler != null)
- {
- var bitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);
- return loadEffectHandler(bitmap, _compositionDevice, sizeTarget);
- }
- else
- {
- return await LoadFromUri(uri, sizeTarget);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/ApiInformationHelper.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/ApiInformationHelper.cs
new file mode 100644
index 00000000000..a7875948b3b
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/ApiInformationHelper.cs
@@ -0,0 +1,14 @@
+// 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.Foundation.Metadata;
+
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors
+{
+ internal class ApiInformationHelper
+ {
+ // 1903 - 18362
+ public static bool IsXamlRootAvailable { get; } = ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "XamlRoot");
+ }
+}
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.UI/Behaviors/BehaviorBase.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/BehaviorBase.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI/Behaviors/BehaviorBase.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/BehaviorBase.cs
diff --git a/Microsoft.Toolkit.Uwp.UI/Behaviors/AutoFocusBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/AutoFocusBehavior.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI/Behaviors/AutoFocusBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/AutoFocusBehavior.cs
diff --git a/Microsoft.Toolkit.Uwp.UI/Behaviors/FocusBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/FocusBehavior.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI/Behaviors/FocusBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/FocusBehavior.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/FadeHeaderBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/FadeHeaderBehavior.cs
similarity index 98%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/FadeHeaderBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/FadeHeaderBehavior.cs
index c965f783473..231a354515f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/FadeHeaderBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/FadeHeaderBehavior.cs
@@ -3,13 +3,13 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
-using Microsoft.Toolkit.Uwp.UI.Behaviors;
using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors
{
///
/// Performs an fade animation on a ListView or GridView Header using composition.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/QuickReturnHeaderBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/QuickReturnHeaderBehavior.cs
similarity index 99%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/QuickReturnHeaderBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/QuickReturnHeaderBehavior.cs
index fe86fd75bbb..ffe9e518cd5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/QuickReturnHeaderBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/QuickReturnHeaderBehavior.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
-using Microsoft.Toolkit.Uwp.UI.Behaviors;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.Foundation;
using Windows.UI.Composition;
@@ -12,7 +11,7 @@
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Input;
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors
{
///
/// Performs an animation on a ListView or GridView Header to make it quick return using composition.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/StickyHeaderBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/StickyHeaderBehavior.cs
similarity index 98%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/StickyHeaderBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/StickyHeaderBehavior.cs
index ec322bf6eb3..5ca0fbf764e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/StickyHeaderBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Headers/StickyHeaderBehavior.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
-using Microsoft.Toolkit.Uwp.UI.Behaviors;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.Foundation;
using Windows.UI.Composition;
@@ -13,7 +12,7 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors
{
///
/// Performs an animation on a ListView or GridView Header to make it sticky using composition.
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
new file mode 100644
index 00000000000..045cbbc0cec
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
@@ -0,0 +1,31 @@
+
+
+
+ uap10.0.17763
+ 8.0
+ Windows Community Toolkit UI Behaviors
+
+ This library provides UI behaviors built on the XAML behaviors SDK. It is part of the Windows Community Toolkit.
+
+ Behaviors:
+ - BehaviorBase: Helper for building Behaviors
+ - AutoFocusBehevior: Sets focus to the associated control.
+ - FocusBehavior: Sets focus to a specified control.
+ - ViewportBehavior: Listening for element to enter or exit the ScrollViewer viewport
+ - FadeHeaderBehavior, QuickReturnHeaderBehavior, StickyHeaderBehavior: Helpers for ListViewBase Header Behavior
+
+ UWP Toolkit Windows UI Behaviors XAML
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Properties/Microsoft.Toolkit.Uwp.UI.Behaviors.rd.xml b/Microsoft.Toolkit.Uwp.UI.Behaviors/Properties/Microsoft.Toolkit.Uwp.UI.Behaviors.rd.xml
new file mode 100644
index 00000000000..2a652962f91
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Properties/Microsoft.Toolkit.Uwp.UI.Behaviors.rd.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.UI/Behaviors/ViewportBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Viewport/ViewportBehavior.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI/Behaviors/ViewportBehavior.cs
rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Viewport/ViewportBehavior.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj b/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
index bf18c15c898..26ff92e907a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
@@ -47,6 +47,7 @@
+
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.cs b/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.cs
deleted file mode 100644
index 21c44fcf9b0..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-// 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 System;
-using Microsoft.Toolkit.Uwp.UI.Animations.Behaviors;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
-using Microsoft.Xaml.Interactivity;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-
-namespace Microsoft.Toolkit.Uwp.UI.Controls
-{
- ///
- /// Scroll header control to be used with ListViews or GridViews
- ///
- public class ScrollHeader : ContentControl
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public ScrollHeader()
- {
- DefaultStyleKey = typeof(ScrollHeader);
- HorizontalContentAlignment = HorizontalAlignment.Stretch;
- }
-
- ///
- /// Identifies the property.
- ///
- public static readonly DependencyProperty ModeProperty =
- DependencyProperty.Register(nameof(Mode), typeof(ScrollHeaderMode), typeof(ScrollHeader), new PropertyMetadata(ScrollHeaderMode.None, OnModeChanged));
-
- ///
- /// Gets or sets a value indicating whether the current mode.
- /// Default is none.
- ///
- public ScrollHeaderMode Mode
- {
- get { return (ScrollHeaderMode)GetValue(ModeProperty); }
- set { SetValue(ModeProperty, value); }
- }
-
- ///
- /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call .
- ///
- protected override void OnApplyTemplate()
- {
- UpdateScrollHeaderBehavior();
- }
-
- private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as ScrollHeader)?.UpdateScrollHeaderBehavior();
- }
-
- private static void OnTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as ScrollHeader)?.OnApplyTemplate();
- }
-
- private void UpdateScrollHeaderBehavior()
- {
- var targetListViewBase = this.FindAscendant();
-
- if (targetListViewBase == null)
- {
- return;
- }
-
- // Remove previous behaviors
- foreach (var behavior in Interaction.GetBehaviors(targetListViewBase))
- {
- if (behavior is FadeHeaderBehavior || behavior is QuickReturnHeaderBehavior || behavior is StickyHeaderBehavior)
- {
- Interaction.GetBehaviors(targetListViewBase).Remove(behavior);
- }
- }
-
- switch (Mode)
- {
- case ScrollHeaderMode.None:
- break;
- case ScrollHeaderMode.QuickReturn:
- Interaction.GetBehaviors(targetListViewBase).Add(new QuickReturnHeaderBehavior());
- break;
- case ScrollHeaderMode.Sticky:
- Interaction.GetBehaviors(targetListViewBase).Add(new StickyHeaderBehavior());
- break;
- case ScrollHeaderMode.Fade:
- Interaction.GetBehaviors(targetListViewBase).Add(new FadeHeaderBehavior());
- break;
- }
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.xaml
deleted file mode 100644
index 2521843c6f5..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeader.xaml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeaderMode.cs b/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeaderMode.cs
deleted file mode 100644
index 5774585a90d..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Controls/ScrollHeader/ScrollHeaderMode.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.
-
-namespace Microsoft.Toolkit.Uwp.UI.Controls
-{
- ///
- /// Define mode available for
- ///
- public enum ScrollHeaderMode
- {
- ///
- /// No change. This is the default value.
- ///
- None,
-
- ///
- /// Enable quick return mode.
- ///
- QuickReturn,
-
- ///
- /// Enable sticky mode.
- ///
- Sticky,
-
- ///
- /// Enable fade mode.
- ///
- Fade
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml
index 6422f8690d2..a6c650d3a4b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml
@@ -27,7 +27,6 @@
-
diff --git a/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj b/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj
index 99767ff0f0c..a9387db46e3 100644
--- a/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj
+++ b/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj
@@ -9,10 +9,6 @@
AdvancedCollectionView: It's a collection view implementation that support filtering, sorting and incremental loading. It's meant to be used in a viewmodel.
- Behaviors:
- - BehaviorBase: Helper for building Behaviors
- - ViewportBehavior: Listening for element to enter or exit the ScrollViewer viewport
-
CacheBase: Provides methods and tools to cache files in a folder.
Converters: Commonly used converters that allow the data to be modified as it passes through the binding engine.
@@ -47,11 +43,7 @@
true
-
-
-
-
-
+
diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln
index 17df1370cd3..9f57b24e708 100644
--- a/Windows Community Toolkit.sln
+++ b/Windows Community Toolkit.sln
@@ -135,6 +135,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.Tests.TAEF", "UITes
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "UITests.Tests.Shared", "UITests\UITests.Tests.Shared\UITests.Tests.Shared.shproj", "{1D8B0260-5C17-41DA-9C38-1E37441B3925}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI.Behaviors", "Microsoft.Toolkit.Uwp.UI.Behaviors\Microsoft.Toolkit.Uwp.UI.Behaviors.csproj", "{D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}"
+EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
UITests\UITests.Tests.Shared\UITests.Tests.Shared.projitems*{05c83067-fa46-45e2-bec4-edee84ad18d0}*SharedItemsImports = 4
@@ -956,6 +958,26 @@ Global
{C8182EF0-77FB-4B43-A588-C71748A309C7}.Release|x64.Build.0 = Release|Any CPU
{C8182EF0-77FB-4B43-A588-C71748A309C7}.Release|x86.ActiveCfg = Release|Any CPU
{C8182EF0-77FB-4B43-A588-C71748A309C7}.Release|x86.Build.0 = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|ARM.ActiveCfg = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|ARM.Build.0 = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|ARM64.Build.0 = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|x64.Build.0 = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Debug|x86.Build.0 = Debug|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|ARM.ActiveCfg = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|ARM.Build.0 = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|ARM64.ActiveCfg = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|ARM64.Build.0 = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|x64.ActiveCfg = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|x64.Build.0 = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|x86.ActiveCfg = Release|Any CPU
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -997,6 +1019,7 @@ Global
{5F720475-E263-4A5A-8C88-2B805B45B5BC} = {6FAA1CFE-3368-4FD2-9DBD-F4700F69174C}
{C8182EF0-77FB-4B43-A588-C71748A309C7} = {6FAA1CFE-3368-4FD2-9DBD-F4700F69174C}
{1D8B0260-5C17-41DA-9C38-1E37441B3925} = {6FAA1CFE-3368-4FD2-9DBD-F4700F69174C}
+ {D4FF799D-0DF2-495A-ADC9-3BBC4AEF8971} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5403B0C4-F244-4F73-A35C-FE664D0F4345}
From 9d874a8913ad7b690190918ff4f896370f677720 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Thu, 17 Dec 2020 22:07:26 +0100
Subject: [PATCH 002/171] Ported enum types
---
.../Enums/Axis.cs | 28 +++++++++
.../Enums/Easing.cs | 62 +++++++++++++++++++
.../Enums/FrameworkLayer.cs | 22 +++++++
.../Enums/Side.cs | 32 ++++++++++
4 files changed, 144 insertions(+)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/Axis.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/FrameworkLayer.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/Side.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Axis.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Axis.cs
new file mode 100644
index 00000000000..1b4e69f00d7
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Axis.cs
@@ -0,0 +1,28 @@
+// 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.
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// Indicates an axis in the 3D space.
+ ///
+ public enum Axis
+ {
+ ///
+ /// The X axis (horizontal).
+ ///
+ X,
+
+ ///
+ /// The Y axis (vertical).
+ ///
+ Y,
+
+ ///
+ /// The Z axis (depth).
+ ///
+ /// This axis might only be available in certain scenarios, such as when working with composition APIs.
+ Z
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
new file mode 100644
index 00000000000..20188082135
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
@@ -0,0 +1,62 @@
+// 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.
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// Indicates an easing function for an animation.
+ ///
+ public enum Easing
+ {
+ ///
+ /// The linear easing, with [0, 0] and [1, 1] as control points.
+ ///
+ Linear,
+
+ ///
+ /// The sine in easing, with [0.4, 0] and [1, 1] as control points.
+ ///
+ SineEaseIn,
+
+ ///
+ /// The sine out easing, with [0, 0] and [0.6, 1] as control points.
+ ///
+ SineEaseOut,
+
+ ///
+ /// The sine in out easing, with [0.4, 0] and [0.6, 1] as control points.
+ ///
+ SineEaseInOut,
+
+ ///
+ /// The quadratic in easing, with [0.8, 0] and [1, 1] as control points.
+ ///
+ QuadraticEaseIn,
+
+ ///
+ /// The quadratic out easing, with [0, 0] and [0.2, 1] as control points.
+ ///
+ QuadraticEaseOut,
+
+ ///
+ /// The quadratic in out easing, with [0.8, 0] and [0.2, 1] as control points.
+ ///
+ QuadraticEaseInOut,
+
+ ///
+ /// The circle in easing, with [1, 0] and [1, 0.8] as control points.
+ ///
+ CircleEaseIn,
+
+ ///
+ /// The circle out easing, with [0, 0.3] and [0, 1] as control points.
+ ///
+ CircleEaseOut,
+
+ ///
+ /// The circle in out easing, with [0.9, 0] and [0.1, 1] as control points.
+ ///
+ CircleEaseInOut
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/FrameworkLayer.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/FrameworkLayer.cs
new file mode 100644
index 00000000000..e43462fdd5d
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/FrameworkLayer.cs
@@ -0,0 +1,22 @@
+// 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.
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// An that indicates the framework layer to target in a specific animation.
+ ///
+ public enum FrameworkLayer
+ {
+ ///
+ /// Indicates the APIs.
+ ///
+ Composition,
+
+ ///
+ /// Indicates the APIs.
+ ///
+ Xaml
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Side.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Side.cs
new file mode 100644
index 00000000000..856909a8e93
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Side.cs
@@ -0,0 +1,32 @@
+// 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.
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// Indicates a side to animate in the bounds of a given element.
+ ///
+ public enum Side
+ {
+ ///
+ /// Maps the top side of the target bounds.
+ ///
+ Top,
+
+ ///
+ /// Maps the bottom side of the target bounds.
+ ///
+ Bottom,
+
+ ///
+ /// Maps the left side of the target bounds.
+ ///
+ Left,
+
+ ///
+ /// Maps the right side of the target bounds.
+ ///
+ Right
+ }
+}
From 1cd580269b4935b91c39939199088312854277bf Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Thu, 17 Dec 2020 22:18:38 +0100
Subject: [PATCH 003/171] Code refactoring, switched to previous EasingType
---
.../EasingType.cs | 67 -----
.../Enums/Easing.cs | 62 ----
.../Enums/EasingType.cs | 67 +++++
.../Extensions/AnimationExtensions.Blur.cs | 76 -----
.../Extensions/AnimationExtensions.Fade.cs | 110 -------
.../Extensions/AnimationExtensions.Light.cs | 193 ------------
.../Extensions/AnimationExtensions.Offset.cs | 122 --------
.../Extensions/AnimationExtensions.Rotate.cs | 126 --------
.../AnimationExtensions.Saturation.cs | 72 -----
.../Extensions/AnimationExtensions.Scale.cs | 134 ---------
.../Extensions/AnimationExtensions.cs | 282 ------------------
.../Extensions/AnimationTools.cs | 43 ---
...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 4 -
13 files changed, 67 insertions(+), 1291 deletions(-)
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/EasingType.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Enums/EasingType.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Blur.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Fade.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Offset.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Rotate.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Saturation.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Scale.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationTools.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/EasingType.cs b/Microsoft.Toolkit.Uwp.UI.Animations/EasingType.cs
deleted file mode 100644
index b233d652652..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/EasingType.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// 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.
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// EasingType is used to describe how the animation interpolates between keyframes.
- ///
- public enum EasingType
- {
- ///
- /// Creates an animation that accelerates with the default EasingType which is specified in AnimationExtensions.DefaultEasingType which is by default Cubic.
- ///
- Default,
-
- ///
- /// Creates an animation that accelerates or decelerates linearly.
- ///
- Linear,
-
- ///
- /// Creates an animation that accelerates or decelerates using the formula f(t) = t3.
- ///
- Cubic,
-
- ///
- /// Retracts the motion of an animation slightly before it begins to animate in the path indicated.
- ///
- Back,
-
- ///
- /// Creates a bouncing effect.
- ///
- Bounce,
-
- ///
- /// Creates an animation that resembles a spring oscillating back and forth until it comes to rest.
- ///
- Elastic,
-
- ///
- /// Creates an animation that accelerates or decelerates using a circular function.
- ///
- Circle,
-
- ///
- /// Creates an animation that accelerates or decelerates using the formula f(t) = t2.
- ///
- Quadratic,
-
- ///
- /// Creates an animation that accelerates or decelerates using the formula f(t) = t4.
- ///
- Quartic,
-
- ///
- /// Create an animation that accelerates or decelerates using the formula f(t) = t5.
- ///
- Quintic,
-
- ///
- /// Creates an animation that accelerates or decelerates using a sine formula.
- ///
- Sine
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
deleted file mode 100644
index 20188082135..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/Easing.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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.
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// Indicates an easing function for an animation.
- ///
- public enum Easing
- {
- ///
- /// The linear easing, with [0, 0] and [1, 1] as control points.
- ///
- Linear,
-
- ///
- /// The sine in easing, with [0.4, 0] and [1, 1] as control points.
- ///
- SineEaseIn,
-
- ///
- /// The sine out easing, with [0, 0] and [0.6, 1] as control points.
- ///
- SineEaseOut,
-
- ///
- /// The sine in out easing, with [0.4, 0] and [0.6, 1] as control points.
- ///
- SineEaseInOut,
-
- ///
- /// The quadratic in easing, with [0.8, 0] and [1, 1] as control points.
- ///
- QuadraticEaseIn,
-
- ///
- /// The quadratic out easing, with [0, 0] and [0.2, 1] as control points.
- ///
- QuadraticEaseOut,
-
- ///
- /// The quadratic in out easing, with [0.8, 0] and [0.2, 1] as control points.
- ///
- QuadraticEaseInOut,
-
- ///
- /// The circle in easing, with [1, 0] and [1, 0.8] as control points.
- ///
- CircleEaseIn,
-
- ///
- /// The circle out easing, with [0, 0.3] and [0, 1] as control points.
- ///
- CircleEaseOut,
-
- ///
- /// The circle in out easing, with [0.9, 0] and [0.1, 1] as control points.
- ///
- CircleEaseInOut
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Enums/EasingType.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/EasingType.cs
new file mode 100644
index 00000000000..1639ad76060
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Enums/EasingType.cs
@@ -0,0 +1,67 @@
+// 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.
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// Indicates how the animation interpolates between keyframes.
+ ///
+ public enum EasingType
+ {
+ ///
+ /// The default easing type, which is specified in AnimationExtensions.DefaultEasingType which is by default Cubic.
+ ///
+ Default,
+
+ ///
+ /// A linear acceleration and deceleration.
+ ///
+ Linear,
+
+ ///
+ /// An acceleration or deceleration using the formula f(t) = t3.
+ ///
+ Cubic,
+
+ ///
+ /// An animation that rectracts its motion slightly before it begins to animate in the path indicated.
+ ///
+ Back,
+
+ ///
+ /// A bouncing animation.
+ ///
+ Bounce,
+
+ ///
+ /// An animation that resembles a spring oscillating back and forth until it comes to rest.
+ ///
+ Elastic,
+
+ ///
+ /// An animation that accelerates or decelerates using a circular function.
+ ///
+ Circle,
+
+ ///
+ /// An animation that accelerates or decelerates using the formula f(t) = t^2.
+ ///
+ Quadratic,
+
+ ///
+ /// An animation that accelerates or decelerates using the formula f(t) = t^4.
+ ///
+ Quartic,
+
+ ///
+ /// An animation that accelerates or decelerates using the formula f(t) = t^5.
+ ///
+ Quintic,
+
+ ///
+ /// An animation that accelerates or decelerates using a sine formula.
+ ///
+ Sine
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Blur.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Blur.cs
deleted file mode 100644
index 879e7a2819d..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Blur.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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 Microsoft.Toolkit.Uwp.UI.Animations.Effects;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Gets the blur effect.
- ///
- ///
- /// The blur effect.
- ///
- public static Blur BlurEffect { get; } = new Blur();
-
- ///
- /// Animates the Gaussian blur of the UIElement.
- ///
- /// The associated object.
- /// The blur amount.
- /// The duration in milliseconds.
- /// The delay. (ignored if duration == 0)
- /// The easing function
- /// The easing mode
- ///
- /// An Animation Set.
- ///
- public static AnimationSet Blur(
- this FrameworkElement associatedObject,
- double value = 0d,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Blur(value, duration, delay, easingType, easingMode);
- }
-
- ///
- /// Animates the Gaussian blur of the UIElement.
- ///
- /// The animation set.
- /// The blur amount.
- /// The duration in milliseconds.
- /// The delay. (ignored if duration == 0)
- /// The easing function
- /// The easing mode
- ///
- /// An Animation Set.
- ///
- public static AnimationSet Blur(
- this AnimationSet animationSet,
- double value = 0d,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- return BlurEffect.EffectAnimation(animationSet, value, duration, delay, easingType, easingMode);
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Fade.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Fade.cs
deleted file mode 100644
index 24e7a65e631..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Fade.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-// 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 System;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Animates the opacity of the UIElement.
- ///
- /// The UI Element to change the opacity of.
- /// The fade value, between 0 and 1.
- /// The duration in milliseconds.
- /// The delay. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The easing mode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Fade(
- this UIElement associatedObject,
- float value = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Fade(value, duration, delay, easingType, easingMode);
- }
-
- ///
- /// Animates the opacity of the UIElement.
- ///
- /// The animation set.
- /// The fade value, between 0 and 1.
- /// The duration in milliseconds.
- /// The delay. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Fade(
- this AnimationSet animationSet,
- float value = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (animationSet == null)
- {
- return null;
- }
-
- if (!AnimationSet.UseComposition)
- {
- var animation = new DoubleAnimation
- {
- To = value,
- Duration = TimeSpan.FromMilliseconds(duration),
- BeginTime = TimeSpan.FromMilliseconds(delay),
- EasingFunction = GetEasingFunction(easingType, easingMode)
- };
-
- animationSet.AddStoryboardAnimation("Opacity", animation);
- }
- else
- {
- if (duration <= 0)
- {
- animationSet.AddCompositionDirectPropertyChange("Opacity", value);
- return animationSet;
- }
-
- var visual = animationSet.Visual;
-
- var compositor = visual?.Compositor;
-
- if (compositor == null)
- {
- return null;
- }
-
- var animation = compositor.CreateScalarKeyFrameAnimation();
- animation.Duration = TimeSpan.FromMilliseconds(duration);
- animation.DelayTime = TimeSpan.FromMilliseconds(delay);
- animation.InsertKeyFrame(1f, value, GetCompositionEasingFunction(easingType, compositor, easingMode));
-
- animationSet.AddCompositionAnimation("Opacity", animation);
- }
-
- return animationSet;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs
deleted file mode 100644
index c897d4cb206..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs
+++ /dev/null
@@ -1,193 +0,0 @@
-// 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 System;
-using System.Collections.Generic;
-using Microsoft.Graphics.Canvas;
-using Microsoft.Graphics.Canvas.Effects;
-using Microsoft.Toolkit.Uwp.Extensions;
-using Windows.UI;
-using Windows.UI.Composition;
-using Windows.UI.Composition.Effects;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Hosting;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// Provides an extension which allows lighting.
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Stores all the point lights along with the visuals that they are applied to.
- /// This is to stop multiplication of point lights on a single visual.
- ///
- private static Dictionary pointLights = new Dictionary();
-
- ///
- /// Animates a point light and it's distance.
- ///
- /// The associated object.
- /// The value.
- /// The duration.
- /// The delay.
- /// The color of the spotlight.
- /// The easing function
- /// The easing mode
- /// An animation set.
- [Obsolete("The Light effect will be removed in a future major release. Please use XamlLight instead")]
- public static AnimationSet Light(
- this FrameworkElement associatedObject,
- double distance = 0d,
- double duration = 500d,
- double delay = 0d,
- Color? color = null,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Light(distance, duration, delay, color, easingType, easingMode);
- }
-
- ///
- /// Animates a point light and it's distance.
- ///
- /// The animation set.
- /// The distance of the light.
- /// The duration in milliseconds.
- /// The delay. (ignored if duration == 0)
- /// The color of the spotlight.
- /// The easing function
- /// The easing mode
- ///
- /// An Animation Set.
- ///
- [Obsolete("The Light effect will be removed in a future major release. Please use XamlLight instead")]
- public static AnimationSet Light(
- this AnimationSet animationSet,
- double distance = 0d,
- double duration = 500d,
- double delay = 0d,
- Color? color = null,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (animationSet == null)
- {
- return null;
- }
-
- var visual = animationSet.Visual;
- var associatedObject = animationSet.Element as FrameworkElement;
-
- if (associatedObject == null)
- {
- return animationSet;
- }
-
- var compositor = visual?.Compositor;
- if (compositor == null)
- {
- return null;
- }
-
- var task = new AnimationTask();
- task.AnimationSet = animationSet;
-
- task.Task = visual.DispatcherQueue.EnqueueAsync(
- () =>
- {
- const string sceneName = "PointLightScene";
- PointLight pointLight;
- CompositionDrawingSurface normalMap = null;
-
- if (!pointLights.ContainsKey(visual))
- {
- SurfaceLoader.Initialize(compositor);
- normalMap = SurfaceLoader.LoadText(string.Empty, new Windows.Foundation.Size(512, 512), new Graphics.Canvas.Text.CanvasTextFormat(), Colors.Transparent, Colors.Transparent);
- }
-
- if (pointLights.ContainsKey(visual))
- {
- pointLight = pointLights[visual];
- }
- else
- {
- pointLight = compositor.CreatePointLight();
-
- var normalBrush = compositor.CreateSurfaceBrush(normalMap);
- normalBrush.Stretch = CompositionStretch.Fill;
-
- // check to see if the visual already has a point light applied.
- var spriteVisual = ElementCompositionPreview.GetElementChildVisual(associatedObject) as SpriteVisual;
- var normalsBrush = spriteVisual?.Brush as CompositionEffectBrush;
-
- if (normalsBrush == null || normalsBrush.Comment != sceneName)
- {
- var lightEffect = new CompositeEffect()
- {
- Mode = CanvasComposite.Add,
- Sources =
- {
- new CompositionEffectSourceParameter("ImageSource"),
- new SceneLightingEffect()
- {
- Name = sceneName,
- AmbientAmount = 0,
- DiffuseAmount = 0.5f,
- SpecularAmount = 0,
- NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
- }
- }
- };
-
- var effectFactory = compositor.CreateEffectFactory(lightEffect);
- var brush = effectFactory.CreateBrush();
- brush.SetSourceParameter("NormalMap", normalBrush);
-
- var sprite = compositor.CreateSpriteVisual();
- sprite.Size = visual.Size;
- sprite.Brush = brush;
- sprite.Comment = sceneName;
-
- ElementCompositionPreview.SetElementChildVisual(task.AnimationSet.Element, sprite);
-
- pointLight.CoordinateSpace = visual;
- pointLight.Targets.Add(visual);
- }
- }
-
- pointLight.Color = color ?? Colors.White;
- var delayTime = task.Delay != null ? task.Delay.Value : TimeSpan.FromMilliseconds(delay);
- var durationTime = task.Duration != null ? task.Duration.Value : TimeSpan.FromMilliseconds(duration);
-
- if (durationTime.TotalMilliseconds <= 0)
- {
- task.AnimationSet.AddEffectDirectPropertyChange(pointLight, (float)distance, nameof(pointLight.Offset));
- }
- else
- {
- var diffuseAnimation = compositor.CreateVector3KeyFrameAnimation();
- diffuseAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3(visual.Size.X / 2, visual.Size.Y / 2, (float)distance), GetCompositionEasingFunction(easingType, compositor, easingMode));
- diffuseAnimation.Duration = durationTime;
- diffuseAnimation.DelayTime = delayTime;
-
- task.AnimationSet.AddCompositionEffectAnimation(pointLight, diffuseAnimation, nameof(pointLight.Offset));
- }
-
- pointLights[visual] = pointLight;
- });
-
- animationSet.AddAnimationThroughTask(task);
- return animationSet;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Offset.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Offset.cs
deleted file mode 100644
index a967fefbd7e..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Offset.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-// 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 System;
-using System.Numerics;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Animates the offset of the UIElement.
- ///
- /// The specified UI Element.
- /// The offset on the x axis.
- /// The offset on the y axis.
- /// The duration in milliseconds.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Offset(
- this UIElement associatedObject,
- float offsetX = 0f,
- float offsetY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Offset(offsetX, offsetY, duration, delay, easingType, easingMode);
- }
-
- ///
- /// Animates the offset of the UIElement.
- ///
- /// The animation set.
- /// The offset on the x axis.
- /// The offset on the y axis.
- /// The duration in milliseconds.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Offset(
- this AnimationSet animationSet,
- float offsetX = 0f,
- float offsetY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (animationSet == null)
- {
- return null;
- }
-
- if (!AnimationSet.UseComposition)
- {
- var element = animationSet.Element;
- var transform = GetAttachedCompositeTransform(element);
-
- var animationX = new DoubleAnimation();
- var animationY = new DoubleAnimation();
-
- animationX.To = offsetX;
- animationY.To = offsetY;
-
- animationX.Duration = animationY.Duration = TimeSpan.FromMilliseconds(duration);
- animationX.BeginTime = animationY.BeginTime = TimeSpan.FromMilliseconds(delay);
- animationX.EasingFunction = animationY.EasingFunction = GetEasingFunction(easingType, easingMode);
-
- animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "TranslateX"), animationX);
- animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "TranslateY"), animationY);
- }
- else
- {
- var visual = animationSet.Visual;
- var offsetVector = new Vector3(offsetX, offsetY, 0);
-
- if (duration <= 0)
- {
- animationSet.AddCompositionDirectPropertyChange("Offset", offsetVector);
- return animationSet;
- }
-
- var compositor = visual?.Compositor;
-
- if (compositor == null)
- {
- return null;
- }
-
- var animation = compositor.CreateVector3KeyFrameAnimation();
- animation.Duration = TimeSpan.FromMilliseconds(duration);
- animation.DelayTime = TimeSpan.FromMilliseconds(delay);
- animation.InsertKeyFrame(1f, offsetVector, GetCompositionEasingFunction(easingType, compositor, easingMode));
-
- animationSet.AddCompositionAnimation("Offset", animation);
- }
-
- return animationSet;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Rotate.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Rotate.cs
deleted file mode 100644
index d288b07a453..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Rotate.cs
+++ /dev/null
@@ -1,126 +0,0 @@
-// 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 System;
-using System.Numerics;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Animates the rotation in degrees of the UIElement.
- ///
- /// The UI Element to rotate.
- /// The value in degrees to rotate.
- /// The center x in pixels.
- /// The center y in pixels.
- /// The duration in milliseconds.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// EasingMode used to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Rotate(
- this UIElement associatedObject,
- float value = 0f,
- float centerX = 0f,
- float centerY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Rotate(value, centerX, centerY, duration, delay, easingType);
- }
-
- ///
- /// Animates the rotation in degrees of the UIElement.
- ///
- /// The animation set.
- /// The value in degrees to rotate.
- /// The center x in pixels.
- /// The center y in pixels.
- /// The duration in milliseconds.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Rotate(
- this AnimationSet animationSet,
- float value = 0f,
- float centerX = 0f,
- float centerY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (animationSet == null)
- {
- return null;
- }
-
- if (!AnimationSet.UseComposition)
- {
- var element = animationSet.Element;
- var transform = GetAttachedCompositeTransform(element);
-
- transform.CenterX = centerX;
- transform.CenterY = centerY;
-
- var animation = new DoubleAnimation
- {
- To = value,
- Duration = TimeSpan.FromMilliseconds(duration),
- BeginTime = TimeSpan.FromMilliseconds(delay),
- EasingFunction = GetEasingFunction(easingType, easingMode)
- };
-
- animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "Rotation"), animation);
- }
- else
- {
- var visual = animationSet.Visual;
- visual.CenterPoint = new Vector3(centerX, centerY, 0);
-
- if (duration <= 0)
- {
- animationSet.AddCompositionDirectPropertyChange("RotationAngleInDegrees", value);
- return animationSet;
- }
-
- var compositor = visual.Compositor;
-
- if (compositor == null)
- {
- return null;
- }
-
- var animation = compositor.CreateScalarKeyFrameAnimation();
- animation.Duration = TimeSpan.FromMilliseconds(duration);
- animation.DelayTime = TimeSpan.FromMilliseconds(delay);
- animation.InsertKeyFrame(1f, value, GetCompositionEasingFunction(easingType, compositor, easingMode));
-
- animationSet.AddCompositionAnimation("RotationAngleInDegrees", animation);
- }
-
- return animationSet;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Saturation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Saturation.cs
deleted file mode 100644
index 9a7169b3515..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Saturation.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-// 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 Microsoft.Toolkit.Uwp.UI.Animations.Effects;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// A partial for the AnimationExtension which includes saturation.
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Gets the saturation effect.
- ///
- ///
- /// The saturation effect.
- ///
- public static Saturation SaturationEffect { get; } = new Saturation();
-
- ///
- /// Saturates the FrameworkElement.
- ///
- /// The associated object.
- /// The value, between 0 and 1. 0 is desaturated, 1 is saturated.
- /// The duration in milliseconds.
- /// The delay in milliseconds.
- /// The
- /// The
- /// An animation set with saturation effects incorporated.
- public static AnimationSet Saturation(
- this FrameworkElement associatedObject,
- double value = 0d,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Saturation(value, duration, delay, easingType, easingMode);
- }
-
- ///
- /// Saturates the visual within the animation set.
- ///
- /// The animation set.
- /// The value. 0 is desaturated, 1 is saturated.
- /// The duration in milliseconds.
- /// The delay in milliseconds.
- /// The
- /// The
- /// An animation set with saturation effects incorporated.
- public static AnimationSet Saturation(
- this AnimationSet animationSet,
- double value = 0d,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- return SaturationEffect.EffectAnimation(animationSet, value, duration, delay, easingType, easingMode);
- }
- }
-}
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Scale.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Scale.cs
deleted file mode 100644
index 5ee0d22feb2..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Scale.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-// 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 System;
-using System.Numerics;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
- ///
- /// Animates the scale of the specified UIElement.
- ///
- /// The associated UIElement.
- /// The scale on the x axis.
- /// The scale on the y axis.
- /// The center x in pixels.
- /// The center y in pixels.
- /// The duration in millisecond.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Scale(
- this UIElement associatedObject,
- float scaleX = 1f,
- float scaleY = 1f,
- float centerX = 0f,
- float centerY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (associatedObject == null)
- {
- return null;
- }
-
- var animationSet = new AnimationSet(associatedObject);
- return animationSet.Scale(scaleX, scaleY, centerX, centerY, duration, delay, easingType, easingMode);
- }
-
- ///
- /// Animates the scale of the specified UIElement.
- ///
- /// The animationSet object.
- /// The scale on the x axis.
- /// The scale on the y axis.
- /// The center x in pixels.
- /// The center y in pixels.
- /// The duration in milliseconds.
- /// The delay in milliseconds. (ignored if duration == 0)
- /// Used to describe how the animation interpolates between keyframes.
- /// The EasingMode to use to interpolate between keyframes.
- ///
- /// An AnimationSet.
- ///
- public static AnimationSet Scale(
- this AnimationSet animationSet,
- float scaleX = 1f,
- float scaleY = 1f,
- float centerX = 0f,
- float centerY = 0f,
- double duration = 500d,
- double delay = 0d,
- EasingType easingType = EasingType.Default,
- EasingMode easingMode = EasingMode.EaseOut)
- {
- if (animationSet == null)
- {
- return null;
- }
-
- if (!AnimationSet.UseComposition)
- {
- var element = animationSet.Element;
- var transform = GetAttachedCompositeTransform(element);
-
- transform.CenterX = centerX;
- transform.CenterY = centerY;
-
- var animationX = new DoubleAnimation();
- var animationY = new DoubleAnimation();
-
- animationX.To = scaleX;
- animationY.To = scaleY;
-
- animationX.Duration = animationY.Duration = TimeSpan.FromMilliseconds(duration);
- animationX.BeginTime = animationY.BeginTime = TimeSpan.FromMilliseconds(delay);
- animationX.EasingFunction = animationY.EasingFunction = GetEasingFunction(easingType, easingMode);
-
- animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "ScaleX"), animationX);
- animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "ScaleY"), animationY);
- }
- else
- {
- var visual = animationSet.Visual;
- visual.CenterPoint = new Vector3(centerX, centerY, 0);
- var scaleVector = new Vector3(scaleX, scaleY, 1.0f);
-
- if (duration <= 0)
- {
- animationSet.AddCompositionDirectPropertyChange("Scale", scaleVector);
- return animationSet;
- }
-
- var compositor = visual.Compositor;
-
- if (compositor == null)
- {
- return null;
- }
-
- var animation = compositor.CreateVector3KeyFrameAnimation();
- animation.Duration = TimeSpan.FromMilliseconds(duration);
- animation.DelayTime = TimeSpan.FromMilliseconds(delay);
- animation.InsertKeyFrame(1f, scaleVector, GetCompositionEasingFunction(easingType, compositor, easingMode));
-
- animationSet.AddCompositionAnimation("Scale", animation);
- }
-
- return animationSet;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
deleted file mode 100644
index 7692b9a3d0e..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
+++ /dev/null
@@ -1,282 +0,0 @@
-// 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 System;
-using System.Collections.Generic;
-using System.Numerics;
-using System.Threading.Tasks;
-using Windows.UI.Composition;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Media.Animation;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations
-{
- ///
- /// These extension methods perform animation on UIElements
- ///
- public static partial class AnimationExtensions
- {
-#pragma warning disable SA1008 // Opening parenthesis must be spaced correctly
-#pragma warning disable SA1009 // Closing parenthesis must be spaced correctly
- ///
- /// A cached dictionary mapping easings to b�zier control points
- ///
- private static readonly Dictionary<(string, EasingMode), (Vector2, Vector2)> _compositionEasingFunctions = new Dictionary<(string, EasingMode), (Vector2, Vector2)>();
-#pragma warning restore SA1009 // Closing parenthesis must be spaced correctly
-#pragma warning restore SA1008 // Opening parenthesis must be spaced correctly
-
- ///
- /// Gets or sets the default EasingType used for storyboard animations
- ///
- public static EasingType DefaultEasingType { get; set; } = EasingType.Cubic;
-
- ///
- /// Begins a Storyboard animation and returns a task that completes when the
- /// animation is complete
- ///
- /// The storyboard to be started
- /// Task that completes when the animation is complete
- public static Task BeginAsync(this Storyboard storyboard)
- {
- var taskSource = new TaskCompletionSource
/// The current instance used to create the animation.
+ /// The target property to animate.
/// The optional starting value for the animation.
/// The final value for the animation.
/// The animation duration.
@@ -96,6 +101,7 @@ public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
[Pure]
public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
this Compositor compositor,
+ string target,
Vector2? from,
Vector2 to,
TimeSpan duration,
@@ -118,6 +124,8 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
animation.InsertKeyFrame(0, from.Value);
}
+ animation.Target = target;
+
return animation;
}
@@ -125,6 +133,7 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
/// Creates a instance with the given parameters to on a target element.
///
/// The current instance used to create the animation.
+ /// The target property to animate.
/// The optional starting value for the animation.
/// The final value for the animation.
/// The animation duration.
@@ -134,6 +143,7 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
[Pure]
public static Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation(
this Compositor compositor,
+ string target,
Vector3? from,
Vector3 to,
TimeSpan duration,
@@ -156,6 +166,8 @@ public static Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation(
animation.InsertKeyFrame(0, from.Value);
}
+ animation.Target = target;
+
return animation;
}
}
From e77296f8aac49645d6e3fb31390538f91a277fee Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 13:21:13 +0100
Subject: [PATCH 014/171] Added Explicit class, enabled auto-binding to parent
---
.../AnimationBuilder.cs | 4 ++
.../Explicit.cs | 66 +++++++++++++++++++
.../Extensions/CompositionObjectExtensions.cs | 6 +-
.../Extensions/CompositorExtensions.cs | 12 ++--
.../Xaml/Abstract/Animation.cs | 36 ++++++++++
.../Xaml/Abstract/TypedAnimation{T}.cs | 31 +--------
.../Xaml/AnimationCollection2.cs | 61 +++++++++++++++++
.../Xaml/AnimationSet.cs | 33 ----------
.../Xaml/TranslationAnimation.cs | 19 +++---
9 files changed, 190 insertions(+), 78 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index 26d7f7a483e..fc6f965f062 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -286,6 +286,8 @@ public void Start(UIElement element)
{
if (this.compositionAnimationFactories.Count > 0)
{
+ ElementCompositionPreview.SetIsTranslationEnabled(element, true);
+
Visual visual = ElementCompositionPreview.GetElementVisual(element);
CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
@@ -323,6 +325,8 @@ public Task StartAsync(UIElement element)
if (this.compositionAnimationFactories.Count > 0)
{
+ ElementCompositionPreview.SetIsTranslationEnabled(element, true);
+
Visual visual = ElementCompositionPreview.GetElementVisual(element);
CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
CompositionScopedBatch batch = visual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
new file mode 100644
index 00000000000..a6cac52c220
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
@@ -0,0 +1,66 @@
+// 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.Xaml;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// Attached properties to support explicitly triggered animations for instances.
+ ///
+ public static class Explicit
+ {
+ ///
+ /// Identifies the Implicit.ShowAnimations XAML attached property.
+ ///
+ public static readonly DependencyProperty Animations = DependencyProperty.RegisterAttached(
+ "ShowAnimations",
+ typeof(AnimationCollection),
+ typeof(Implicit),
+ new PropertyMetadata(null, OnAnimationsChanged));
+
+ ///
+ /// Gets the value of the property.
+ ///
+ /// The to get the value for.
+ /// The retrieved item.
+ public static AnimationCollection2 GetAnimations(UIElement element)
+ {
+ if (element.GetValue(Animations) is AnimationCollection2 collection)
+ {
+ return collection;
+ }
+
+ collection = new AnimationCollection2();
+
+ element.SetValue(Animations, collection);
+
+ return collection;
+ }
+
+ ///
+ /// Sets the value of the property.
+ ///
+ /// The to set the value for.
+ /// The value to set.
+ public static void SetAnimations(UIElement element, AnimationCollection2 value)
+ {
+ element.SetValue(Animations, value);
+ }
+
+ ///
+ /// Callback to keep the attached parent in sync for animations linked to the property.
+ ///
+ /// The target object the property was changed for.
+ /// The instance for the current event.
+ private static void OnAnimationsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (e.NewValue is AnimationCollection2 animationCollection && d is UIElement element)
+ {
+ animationCollection.Parent = element;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
index 566bb9ded76..a90faae4361 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
@@ -32,7 +32,7 @@ public static void StartScalarAnimation(
TimeSpan? delay,
CompositionEasingFunction? ease = null)
{
- target.StartAnimation(propertyPath, target.Compositor.CreateScalarKeyFrameAnimation(from, to, duration, delay, ease));
+ target.StartAnimation(propertyPath, target.Compositor.CreateScalarKeyFrameAnimation(null, from, to, duration, delay, ease));
}
///
@@ -54,7 +54,7 @@ public static void StartVector2Animation(
TimeSpan? delay,
CompositionEasingFunction? ease = null)
{
- target.StartAnimation(propertyPath, target.Compositor.CreateVector2KeyFrameAnimation(from, to, duration, delay, ease));
+ target.StartAnimation(propertyPath, target.Compositor.CreateVector2KeyFrameAnimation(null, from, to, duration, delay, ease));
}
///
@@ -76,7 +76,7 @@ public static void StartVector3Animation(
TimeSpan? delay,
CompositionEasingFunction? ease = null)
{
- target.StartAnimation(propertyPath, target.Compositor.CreateVector3KeyFrameAnimation(from, to, duration, delay, ease));
+ target.StartAnimation(propertyPath, target.Compositor.CreateVector3KeyFrameAnimation(null, from, to, duration, delay, ease));
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
index 6f3bf2bac12..6a92d382c86 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
@@ -49,7 +49,7 @@ public static CubicBezierEasingFunction CreateCubicBezierEasingFunction(this Com
/// Creates a instance with the given parameters to on a target element.
///
/// The current instance used to create the animation.
- /// The target property to animate.
+ /// The optional target property to animate.
/// The optional starting value for the animation.
/// The final value for the animation.
/// The animation duration.
@@ -59,7 +59,7 @@ public static CubicBezierEasingFunction CreateCubicBezierEasingFunction(this Com
[Pure]
public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
this Compositor compositor,
- string target,
+ string? target,
float? from,
float to,
TimeSpan duration,
@@ -91,7 +91,7 @@ public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
/// Creates a instance with the given parameters to on a target element.
///
/// The current instance used to create the animation.
- /// The target property to animate.
+ /// The optional target property to animate.
/// The optional starting value for the animation.
/// The final value for the animation.
/// The animation duration.
@@ -101,7 +101,7 @@ public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
[Pure]
public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
this Compositor compositor,
- string target,
+ string? target,
Vector2? from,
Vector2 to,
TimeSpan duration,
@@ -133,7 +133,7 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
/// Creates a instance with the given parameters to on a target element.
///
/// The current instance used to create the animation.
- /// The target property to animate.
+ /// The optional target property to animate.
/// The optional starting value for the animation.
/// The final value for the animation.
/// The animation duration.
@@ -143,7 +143,7 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
[Pure]
public static Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation(
this Compositor compositor,
- string target,
+ string? target,
Vector3? from,
Vector3 to,
TimeSpan duration,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
new file mode 100644
index 00000000000..01ac07cc3ec
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
@@ -0,0 +1,36 @@
+// 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 System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A base model representing an animation that can be used in XAML.
+ ///
+ public abstract class Animation
+ {
+ ///
+ /// Gets or sets the optional initial delay for the animation.
+ ///
+ public TimeSpan? Delay { get; set; }
+
+ ///
+ /// Gets or sets the animation duration.
+ ///
+ public TimeSpan? Duration { get; set; }
+
+ ///
+ /// Gets or sets the optional easing function type for the animation.
+ ///
+ public EasingType EasingType { get; set; } = DefaultEasingType;
+
+ ///
+ /// Gets or sets the optional easing function mode for the animation.
+ ///
+ public EasingMode EasingMode { get; set; } = DefaultEasingMode;
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
index 6fa96463805..d6c95189b12 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
@@ -2,47 +2,22 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using Windows.UI.Xaml.Media.Animation;
-using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
-
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A base model representing a typed animation that can be used in XAML.
///
/// The type of values for the animation.
- public abstract class TypedAnimation
- where T : unmanaged
+ public abstract class TypedAnimation : Animation
{
///
/// Gets or sets the optional starting value for the animation.
///
- public double? From { get; set; }
+ public T? From { get; set; }
///
/// Gets or sets the final value for the animation.
///
- public double To { get; set; }
-
- ///
- /// Gets or sets the optional initial delay for the animation.
- ///
- public TimeSpan? Delay { get; set; }
-
- ///
- /// Gets or sets the animation duration.
- ///
- public TimeSpan? Duration { get; set; }
-
- ///
- /// Gets or sets the optional easing function type for the animation.
- ///
- public EasingType EasingType { get; set; } = DefaultEasingType;
-
- ///
- /// Gets or sets the optional easing function mode for the animation.
- ///
- public EasingMode EasingMode { get; set; } = DefaultEasingMode;
+ public T? To { get; set; }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
new file mode 100644
index 00000000000..91dc1ab8b5b
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -0,0 +1,61 @@
+// 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 System;
+using System.Collections.ObjectModel;
+using System.Threading.Tasks;
+using Windows.UI.Xaml;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A collection of animations that can be grouped together.
+ ///
+ public sealed class AnimationCollection2 : ObservableCollection, ITimeline
+ {
+ ///
+ /// The reference to the parent that owns the current animation collection.
+ ///
+ private WeakReference? parent;
+
+ ///
+ /// Gets or sets the parent for the current animation collection.
+ ///
+ internal UIElement? Parent
+ {
+ get
+ {
+ UIElement? element = null;
+
+ _ = this.parent?.TryGetTarget(out element);
+
+ return element;
+ }
+ set => parent = new(value!);
+ }
+
+ ///
+ public void Start()
+ {
+ ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).Start(Parent!);
+ }
+
+ ///
+ public Task StartAsync()
+ {
+ return ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).StartAsync(Parent!);
+ }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
+ {
+ foreach (ITimeline element in this)
+ {
+ builder = element.AppendToBuilder(builder, delayHint, durationHint);
+ }
+
+ return builder;
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs
deleted file mode 100644
index 6570a29e7a3..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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 System;
-using System.Collections.Generic;
-using Windows.UI.Xaml.Markup;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
-{
- ///
- /// A set of animations that can be grouped together.
- ///
- [ContentProperty(Name = nameof(Elements))]
- public class AnimationSet : ITimeline
- {
- ///
- /// Gets or sets the collection of items for the current set.
- ///
- public IList Elements { get; set; } = new List();
-
- ///
- AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
- {
- foreach (ITimeline element in Elements)
- {
- builder = element.AppendToBuilder(builder, delayHint, durationHint);
- }
-
- return builder;
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs
index f8c538b9e82..4dc26f8cc9b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs
@@ -3,19 +3,15 @@
// See the LICENSE file in the project root for more information.
using System;
+using Microsoft.Toolkit.Uwp.UI.Extensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
- /// A set of animations that can be grouped together.
+ /// A translation animation working on the composition or XAML layer.
///
- public class TranslationAnimation : TypedAnimation, ITimeline
+ public class TranslationAnimation : TypedAnimation, ITimeline
{
- ///
- /// Gets or sets the target translation axis to animate.
- ///
- public Axis Axis { get; set; }
-
///
/// Gets or sets the target framework layer to animate.
///
@@ -24,7 +20,14 @@ public class TranslationAnimation : TypedAnimation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
{
- return builder.Translation(Axis, From, To, Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode, Layer);
+ if (Layer == FrameworkLayer.Composition)
+ {
+ return builder.Translation(From?.ToVector3(), To!.ToVector3(), Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode);
+ }
+ else
+ {
+ return builder.Translation(From?.ToVector2(), To!.ToVector2(), Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode, FrameworkLayer.Xaml);
+ }
}
}
}
From 6afc1b0283af619271c109ebda6d306c05c5977a Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 13:46:19 +0100
Subject: [PATCH 015/171] Switched AnimationCollection2 to DependencyObject
---
.../Explicit.cs | 2 +-
.../Xaml/AnimationCollection2.cs | 128 +++++++++++++++++-
2 files changed, 125 insertions(+), 5 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
index a6cac52c220..c2d6220500c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
@@ -2,8 +2,8 @@
// 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.Xaml;
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 91dc1ab8b5b..f99e906176b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -3,7 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.ObjectModel;
+using System.Collections;
+using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.UI.Xaml;
@@ -12,8 +13,28 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
///
/// A collection of animations that can be grouped together.
///
- public sealed class AnimationCollection2 : ObservableCollection, ITimeline
+ public sealed class AnimationCollection2 : DependencyObject, IList, ITimeline
{
+ ///
+ /// Raised whenever the current animation is started.
+ ///
+ public event EventHandler? Started;
+
+ ///
+ /// Raised whenever the current animation ends.
+ ///
+ public event EventHandler? Ended;
+
+ ///
+ /// Raised whenever the current collection changes.
+ ///
+ public event EventHandler? CollectionChanged;
+
+ ///
+ /// The underlying list of animations.
+ ///
+ private readonly List list = new();
+
///
/// The reference to the parent that owns the current animation collection.
///
@@ -35,16 +56,115 @@ internal UIElement? Parent
set => parent = new(value!);
}
+ ///
+ public Animation this[int index]
+ {
+ get => this.list[index];
+ set
+ {
+ this.list[index] = value;
+
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ ///
+ public int Count => this.list.Count;
+
+ ///
+ public bool IsReadOnly => false;
+
+ ///
+ public void Add(Animation item)
+ {
+ this.list.Add(item);
+
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+
+ ///
+ public void Clear()
+ {
+ this.list.Clear();
+
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+
+ ///
+ public bool Contains(Animation item)
+ {
+ return this.list.Contains(item);
+ }
+
+ ///
+ public void CopyTo(Animation[] array, int arrayIndex)
+ {
+ this.list.CopyTo(array, arrayIndex);
+ }
+
+ ///
+ public IEnumerator GetEnumerator()
+ {
+ return this.list.GetEnumerator();
+ }
+
+ ///
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return this.list.GetEnumerator();
+ }
+
+ ///
+ public int IndexOf(Animation item)
+ {
+ return this.list.IndexOf(item);
+ }
+
+ ///
+ public void Insert(int index, Animation item)
+ {
+ this.list.Insert(index, item);
+
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+
+ ///
+ public bool Remove(Animation item)
+ {
+ bool removed = this.list.Remove(item);
+
+ if (removed)
+ {
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+
+ return removed;
+ }
+
+ ///
+ public void RemoveAt(int index)
+ {
+ this.list.RemoveAt(index);
+
+ CollectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+
///
public void Start()
{
- ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).Start(Parent!);
+ _ = StartAsync();
}
///
public Task StartAsync()
{
- return ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).StartAsync(Parent!);
+ Started?.Invoke(this, EventArgs.Empty);
+
+ return
+ ((ITimeline)this)
+ .AppendToBuilder(new AnimationBuilder())
+ .StartAsync(Parent!)
+ .ContinueWith(_ => Ended?.Invoke(this, EventArgs.Empty));
}
///
From f8a8457fa854ee9076cc3a44c6700dceea0b22c1 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 14:34:05 +0100
Subject: [PATCH 016/171] Added AnimationEndBehavior
---
.../Xaml/AnimationCollection2.cs | 20 ++++--
.../Animations/AnimationEndBehavior.cs | 66 +++++++++++++++++++
.../Animations/StartAnimationAction.cs | 17 ++---
.../Microsoft.Toolkit.Uwp.UI.Behaviors.csproj | 3 +-
4 files changed, 90 insertions(+), 16 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index f99e906176b..a3f31e28a07 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -157,14 +157,24 @@ public void Start()
///
public Task StartAsync()
+ {
+ return StartAsync(Parent!);
+ }
+
+ ///
+ public void Start(UIElement element)
+ {
+ _ = StartAsync(element);
+ }
+
+ ///
+ public async Task StartAsync(UIElement element)
{
Started?.Invoke(this, EventArgs.Empty);
- return
- ((ITimeline)this)
- .AppendToBuilder(new AnimationBuilder())
- .StartAsync(Parent!)
- .ContinueWith(_ => Ended?.Invoke(this, EventArgs.Empty));
+ await ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).StartAsync(element);
+
+ Ended?.Invoke(this, EventArgs.Empty);
}
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
new file mode 100644
index 00000000000..1afe9f24ae1
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
@@ -0,0 +1,66 @@
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+using Microsoft.Xaml.Interactivity;
+
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
+{
+ ///
+ /// An implementation that can trigger a target animation.
+ ///
+ public sealed class AnimationEndBehavior : Trigger
+ {
+ ///
+ /// The current instance in use.
+ ///
+ private AnimationCollection2? animationCollection;
+
+ ///
+ protected override void OnAttached()
+ {
+ base.OnAttached();
+
+ SetResolvedCollection(AssociatedObject);
+ }
+
+ ///
+ protected override void OnDetaching()
+ {
+ base.OnDetaching();
+
+ SetResolvedCollection(null);
+ }
+
+ ///
+ /// Sets the current instance in use.
+ ///
+ /// The instance in use.
+ private void SetResolvedCollection(AnimationCollection2? animationCollection)
+ {
+ if (this.animationCollection == animationCollection)
+ {
+ return;
+ }
+
+ if (this.animationCollection is not null)
+ {
+ this.animationCollection.Ended -= AnimationCollection_Ended;
+ }
+
+ this.animationCollection = animationCollection;
+
+ if (animationCollection is not null)
+ {
+ animationCollection.Ended += AnimationCollection_Ended;
+ }
+ }
+
+ ///
+ /// Invokes the current actions when the linked animations complete.
+ ///
+ /// The source instance.
+ /// The arguments for the event (unused).
+ private void AnimationCollection_Ended(object sender, System.EventArgs e)
+ {
+ Interaction.ExecuteActions(sender, Actions, e);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
index bb30e53cb65..f174dd727a9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
@@ -1,5 +1,4 @@
using Microsoft.Toolkit.Diagnostics;
-using Microsoft.Toolkit.Uwp.UI.Animations;
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
@@ -7,16 +6,16 @@
namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
{
///
- /// An implementation that can trigger a target animation.
+ /// An implementation that can trigger a target instance.
///
public sealed class StartAnimationAction : DependencyObject, IAction
{
///
- /// Gets or sets the linked animation to invoke.
+ /// Gets or sets the linked instance to invoke.
///
- public ITimeline Animation
+ public AnimationCollection2 Animation
{
- get => (ITimeline)GetValue(AnimationProperty);
+ get => (AnimationCollection2)GetValue(AnimationProperty);
set => SetValue(AnimationProperty, value);
}
@@ -25,20 +24,18 @@ public ITimeline Animation
///
public static readonly DependencyProperty AnimationProperty = DependencyProperty.Register(
"Animation",
- typeof(ITimeline),
+ typeof(AnimationCollection2),
typeof(StartAnimationAction),
new PropertyMetadata(null));
///
public object Execute(object sender, object parameter)
{
- Guard.IsNotNull(sender, nameof(sender));
- Guard.IsAssignableToType(sender, nameof(sender));
Guard.IsNotNull(Animation, nameof(Animation));
- Animation.AppendToBuilder(new AnimationBuilder()).Start((UIElement)sender);
+ Animation.Start();
- return null;
+ return null!;
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
index 045cbbc0cec..514ff0307e4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
@@ -2,7 +2,8 @@
uap10.0.17763
- 8.0
+ 9.0
+ enableWindows Community Toolkit UI Behaviors
This library provides UI behaviors built on the XAML behaviors SDK. It is part of the Windows Community Toolkit.
From a2eef1266515f993fc33fc939ed8e39eb727a81b Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 14:37:47 +0100
Subject: [PATCH 017/171] Added AnimationStartBehavior type
---
.../Animations/AnimationEndBehavior.cs | 4 +-
.../Animations/AnimationStartBehavior.cs | 66 +++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
index 1afe9f24ae1..807b1229c19 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
@@ -4,7 +4,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
{
///
- /// An implementation that can trigger a target animation.
+ /// A custom that fires whenever a linked ends.
///
public sealed class AnimationEndBehavior : Trigger
{
@@ -54,7 +54,7 @@ private void SetResolvedCollection(AnimationCollection2? animationCollection)
}
///
- /// Invokes the current actions when the linked animations complete.
+ /// Invokes the current actions when the linked animations completes.
///
/// The source instance.
/// The arguments for the event (unused).
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
new file mode 100644
index 00000000000..3dfdfc59926
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
@@ -0,0 +1,66 @@
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+using Microsoft.Xaml.Interactivity;
+
+namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
+{
+ ///
+ /// A custom that fires whenever a linked starts.
+ ///
+ public sealed class AnimationStartBehavior : Trigger
+ {
+ ///
+ /// The current instance in use.
+ ///
+ private AnimationCollection2? animationCollection;
+
+ ///
+ protected override void OnAttached()
+ {
+ base.OnAttached();
+
+ SetResolvedCollection(AssociatedObject);
+ }
+
+ ///
+ protected override void OnDetaching()
+ {
+ base.OnDetaching();
+
+ SetResolvedCollection(null);
+ }
+
+ ///
+ /// Sets the current instance in use.
+ ///
+ /// The instance in use.
+ private void SetResolvedCollection(AnimationCollection2? animationCollection)
+ {
+ if (this.animationCollection == animationCollection)
+ {
+ return;
+ }
+
+ if (this.animationCollection is not null)
+ {
+ this.animationCollection.Started -= AnimationCollection_Started;
+ }
+
+ this.animationCollection = animationCollection;
+
+ if (animationCollection is not null)
+ {
+ animationCollection.Started += AnimationCollection_Started;
+ }
+ }
+
+ ///
+ /// Invokes the current actions when the linked animations starts.
+ ///
+ /// The source instance.
+ /// The arguments for the event (unused).
+ private void AnimationCollection_Started(object sender, System.EventArgs e)
+ {
+ Interaction.ExecuteActions(sender, Actions, e);
+ }
+ }
+}
From 26aeba7a73a41c9f537fc02fd1c393c9ac0b41ff Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 16:40:01 +0100
Subject: [PATCH 018/171] Added extension to attach pipeline effects to
elements
---
.../Brushes/PipelineBrush.cs | 4 +-
.../Extensions/UIElementExtensions.cs | 51 +++++++++++++++++++
.../PipelineVisual.cs | 45 ++++++++++++++++
3 files changed, 98 insertions(+), 2 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
index cf8916b7da5..acb380a580a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
@@ -17,12 +17,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media
public sealed class PipelineBrush : XamlCompositionEffectBrushBase
{
///
- /// Gets or sets the source for the current pipeline (defaults to a with source).
+ /// Gets or sets the source for the current pipeline (defaults to a with source).
///
public PipelineBuilder Source { get; set; }
///
- /// Gets or sets the collection of effects to use in the current pipeline
+ /// Gets or sets the collection of effects to use in the current pipeline.
///
public IList Effects { get; set; } = new List();
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
new file mode 100644
index 00000000000..d8f78c798f2
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
@@ -0,0 +1,51 @@
+using Windows.UI.Xaml;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media
+{
+ ///
+ /// Attached properties to support attaching custom pipelines to UI elements.
+ ///
+ public static class UIElementExtensions
+ {
+ ///
+ /// Identifies the Visual XAML attached property.
+ ///
+ public static readonly DependencyProperty VisualProperty = DependencyProperty.RegisterAttached(
+ "Visual",
+ typeof(PipelineVisual),
+ typeof(UIElementExtensions),
+ new PropertyMetadata(null, OnVisualPropertyChanged));
+
+ ///
+ /// Gets the value of .
+ ///
+ /// The to get the value for.
+ /// The retrieved item.
+ public static PipelineVisual GetVisual(UIElement element)
+ {
+ return (PipelineVisual)element.GetValue(VisualProperty);
+ }
+
+ ///
+ /// Sets the value of .
+ ///
+ /// The to set the value for.
+ /// The value to set.
+ public static void SetVisual(UIElement element, PipelineVisual value)
+ {
+ element.SetValue(VisualProperty, value);
+ }
+
+ ///
+ /// Callback to apply the visual for .
+ ///
+ /// The target object the property was changed for.
+ /// The instance for the current event.
+ private static async void OnVisualPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var element = (UIElement)d;
+
+ await ((PipelineVisual)e.NewValue).GetPipeline().AttachAsync(element, element);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs b/Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs
new file mode 100644
index 00000000000..6a8278ff032
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs
@@ -0,0 +1,45 @@
+// 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 System.Collections.Generic;
+using Microsoft.Toolkit.Uwp.UI.Media.Effects;
+using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Xaml.Markup;
+using Windows.UI.Xaml.Media;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media
+{
+ ///
+ /// A builder type for instance to apply to UI elements.
+ ///
+ [ContentProperty(Name = nameof(Effects))]
+ public sealed class PipelineVisual
+ {
+ ///
+ /// Gets or sets the source for the current pipeline (defaults to a with source).
+ ///
+ public PipelineBuilder Source { get; set; }
+
+ ///
+ /// Gets or sets the collection of effects to use in the current pipeline.
+ ///
+ public IList Effects { get; set; } = new List();
+
+ ///
+ /// Gets the instance for the current effects tree.
+ ///
+ /// The instance for the current effects tree.
+ internal PipelineBuilder GetPipeline()
+ {
+ PipelineBuilder builder = Source ?? PipelineBuilder.FromBackdrop();
+
+ foreach (IPipelineEffect effect in Effects)
+ {
+ builder = effect.AppendToPipeline(builder);
+ }
+
+ return builder;
+ }
+ }
+}
From 3fe603c4f93de7f5a679a15e59a3c916aef36802 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 16:42:16 +0100
Subject: [PATCH 019/171] Minor code tweaks
---
.../Brushes/AcrylicBrush.cs | 2 +-
.../Brushes/BackdropBlurBrush.cs | 2 +-
.../Brushes/BackdropInvertBrush.cs | 2 +-
.../Brushes/BackdropSaturationBrush.cs | 2 +-
.../Brushes/BackdropSepiaBrush.cs | 2 +-
.../Base/XamlCompositionEffectBrushBase.cs | 47 ++++++++++---------
.../Brushes/PipelineBrush.cs | 2 +-
.../Brushes/TilesBrush.cs | 2 +-
.../Brushes/XamlCompositionBrush.cs | 2 +-
9 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
index 30c67aa3a37..7d4df4e20a0 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
@@ -197,7 +197,7 @@ private static void OnTextureUriPropertyChanged(DependencyObject d, DependencyPr
}
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
switch (BackgroundSource)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs
index 129fa289610..434eeada2b4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs
@@ -54,7 +54,7 @@ private static void OnAmountChanged(DependencyObject d, DependencyPropertyChange
}
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
return PipelineBuilder.FromBackdrop().Blur((float)Amount, out this.amountSetter);
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs
index c225fa42fad..7bf161d6551 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs
@@ -15,7 +15,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media
public class BackdropInvertBrush : XamlCompositionEffectBrushBase
{
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
return PipelineBuilder.FromBackdrop().Invert();
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs
index 699ebe04849..c055b20982a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs
@@ -64,7 +64,7 @@ private static void OnSaturationChanged(DependencyObject d, DependencyPropertyCh
}
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
return PipelineBuilder.FromBackdrop().Saturation((float)Saturation, out setter);
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs
index 965d34de9ee..b7a36dcd514 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs
@@ -64,7 +64,7 @@ private static void OnIntensityChanged(DependencyObject d, DependencyPropertyCha
}
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
return PipelineBuilder.FromBackdrop().Sepia((float)Intensity, out setter);
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
index d9a4396e794..6f685735285 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
@@ -10,30 +10,31 @@
namespace Microsoft.Toolkit.Uwp.UI.Media
{
///
- /// A custom that's ready to be used with a custom pipeline
+ /// A custom that's ready to be used with a custom pipeline.
///
public abstract class XamlCompositionEffectBrushBase : XamlCompositionBrushBase
{
///
- /// The initialization instance
+ /// The initialization instance.
///
private readonly AsyncMutex connectedMutex = new AsyncMutex();
///
/// A method that builds and returns the pipeline to use in the current instance.
- /// This method can also be used to store any needed or instances in local fields, for later use (they will need to be called upon ).
+ /// This method can also be used to store any needed or
+ /// instances in local fields, for later use (they will need to be called upon ).
///
- /// A instance to create the brush to display
- protected abstract PipelineBuilder OnBrushRequested();
+ /// A instance to create the brush to display.
+ protected abstract PipelineBuilder OnPipelineRequested();
- private bool _isEnabled = true;
+ private bool isEnabled = true;
///
- /// Gets or sets a value indicating whether the current brush is using the provided pipeline, or the fallback color
+ /// Gets or sets a value indicating whether the current brush is using the provided pipeline, or the fallback color.
///
public bool IsEnabled
{
- get => this._isEnabled;
+ get => this.isEnabled;
set => this.OnEnabledToggled(value);
}
@@ -42,7 +43,7 @@ protected override async void OnConnected()
{
using (await this.connectedMutex.LockAsync())
{
- if (this.CompositionBrush == null)
+ if (CompositionBrush == null)
{
// Abort if effects aren't supported
if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported())
@@ -50,13 +51,13 @@ protected override async void OnConnected()
return;
}
- if (this._isEnabled)
+ if (this.isEnabled)
{
- this.CompositionBrush = await this.OnBrushRequested().BuildAsync();
+ CompositionBrush = await OnPipelineRequested().BuildAsync();
}
else
{
- this.CompositionBrush = await PipelineBuilder.FromColor(this.FallbackColor).BuildAsync();
+ CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
}
}
@@ -69,10 +70,10 @@ protected override async void OnDisconnected()
{
using (await this.connectedMutex.LockAsync())
{
- if (this.CompositionBrush != null)
+ if (CompositionBrush != null)
{
- this.CompositionBrush.Dispose();
- this.CompositionBrush = null;
+ CompositionBrush.Dispose();
+ CompositionBrush = null;
}
}
@@ -80,21 +81,21 @@ protected override async void OnDisconnected()
}
///
- /// Updates the property depending on the input value
+ /// Updates the property depending on the input value.
///
- /// The new value being set to the property
+ /// The new value being set to the property.
protected async void OnEnabledToggled(bool value)
{
using (await this.connectedMutex.LockAsync())
{
- if (this._isEnabled == value)
+ if (this.isEnabled == value)
{
return;
}
- this._isEnabled = value;
+ this.isEnabled = value;
- if (this.CompositionBrush != null)
+ if (CompositionBrush != null)
{
// Abort if effects aren't supported
if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported())
@@ -102,13 +103,13 @@ protected async void OnEnabledToggled(bool value)
return;
}
- if (this._isEnabled)
+ if (this.isEnabled)
{
- this.CompositionBrush = await this.OnBrushRequested().BuildAsync();
+ CompositionBrush = await OnPipelineRequested().BuildAsync();
}
else
{
- this.CompositionBrush = await PipelineBuilder.FromColor(this.FallbackColor).BuildAsync();
+ CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
index acb380a580a..caa1460239c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
@@ -27,7 +27,7 @@ public sealed class PipelineBrush : XamlCompositionEffectBrushBase
public IList Effects { get; set; } = new List();
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
PipelineBuilder builder = Source ?? PipelineBuilder.FromBackdrop();
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs
index 3d75b4f3c53..50d96d3cac6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs
@@ -65,7 +65,7 @@ private static void OnDependencyPropertyChanged(DependencyObject d, DependencyPr
}
///
- protected override PipelineBuilder OnBrushRequested()
+ protected override PipelineBuilder OnPipelineRequested()
{
if (TextureUri is Uri uri)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs
index 44f1b527f23..220a0261b77 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs
@@ -76,7 +76,7 @@ public XamlCompositionBrush Bind(EffectAnimation animation, out XamlEffect
}
///
- protected override PipelineBuilder OnBrushRequested() => this.Pipeline;
+ protected override PipelineBuilder OnPipelineRequested() => this.Pipeline;
///
/// Clones the current instance by rebuilding the source . Use this method to reuse the same effects pipeline on a different
From f971a94b3225fe76c68e4bba72d7c237e45a6e21 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 17:03:00 +0100
Subject: [PATCH 020/171] Added extensibility to attached visuals
---
.../Extensions/UIElementExtensions.cs | 39 +++++++++++--------
.../Pipelines/PipelineBuilder.cs | 2 +-
.../Visuals/AttachedVisualFactoryBase.cs | 23 +++++++++++
.../PipelineVisualFactory.cs} | 9 ++---
.../Visuals/PipelineVisualFactoryBase.cs | 34 ++++++++++++++++
5 files changed, 83 insertions(+), 24 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Visuals/AttachedVisualFactoryBase.cs
rename Microsoft.Toolkit.Uwp.UI.Media/{PipelineVisual.cs => Visuals/PipelineVisualFactory.cs} (81%)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactoryBase.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
index d8f78c798f2..82eb8742e37 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
@@ -1,4 +1,6 @@
-using Windows.UI.Xaml;
+using Microsoft.Toolkit.Uwp.UI.Media.Extensions;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Hosting;
namespace Microsoft.Toolkit.Uwp.UI.Media
{
@@ -8,44 +10,47 @@ namespace Microsoft.Toolkit.Uwp.UI.Media
public static class UIElementExtensions
{
///
- /// Identifies the Visual XAML attached property.
+ /// Identifies the VisualFactory XAML attached property.
///
- public static readonly DependencyProperty VisualProperty = DependencyProperty.RegisterAttached(
- "Visual",
- typeof(PipelineVisual),
+ public static readonly DependencyProperty VisualFactoryProperty = DependencyProperty.RegisterAttached(
+ "VisualFactory",
+ typeof(AttachedVisualFactoryBase),
typeof(UIElementExtensions),
- new PropertyMetadata(null, OnVisualPropertyChanged));
+ new PropertyMetadata(null, OnVisualFactoryPropertyChanged));
///
- /// Gets the value of .
+ /// Gets the value of .
///
/// The to get the value for.
- /// The retrieved item.
- public static PipelineVisual GetVisual(UIElement element)
+ /// The retrieved item.
+ public static AttachedVisualFactoryBase GetVisualFactory(UIElement element)
{
- return (PipelineVisual)element.GetValue(VisualProperty);
+ return (AttachedVisualFactoryBase)element.GetValue(VisualFactoryProperty);
}
///
- /// Sets the value of .
+ /// Sets the value of .
///
/// The to set the value for.
- /// The value to set.
- public static void SetVisual(UIElement element, PipelineVisual value)
+ /// The value to set.
+ public static void SetVisualFactory(UIElement element, AttachedVisualFactoryBase value)
{
- element.SetValue(VisualProperty, value);
+ element.SetValue(VisualFactoryProperty, value);
}
///
- /// Callback to apply the visual for .
+ /// Callback to apply the visual for .
///
/// The target object the property was changed for.
/// The instance for the current event.
- private static async void OnVisualPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ private static async void OnVisualFactoryPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var element = (UIElement)d;
+ var attachedVisual = await ((AttachedVisualFactoryBase)e.NewValue).GetAttachedVisualAsync(element);
- await ((PipelineVisual)e.NewValue).GetPipeline().AttachAsync(element, element);
+ attachedVisual.BindSize(element);
+
+ ElementCompositionPreview.SetElementChildVisual(element, attachedVisual);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs
index e6568aeee26..8f65d10a7f5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs
@@ -190,7 +190,7 @@ public async Task AttachAsync(UIElement target, UIElement referenc
{
var visual = Window.Current.Compositor.CreateSpriteVisual();
- visual.Brush = await this.BuildAsync();
+ visual.Brush = await BuildAsync();
ElementCompositionPreview.SetElementChildVisual(target, visual);
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Visuals/AttachedVisualFactoryBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/AttachedVisualFactoryBase.cs
new file mode 100644
index 00000000000..d6ce1661ef3
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/AttachedVisualFactoryBase.cs
@@ -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 System.Threading.Tasks;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media
+{
+ ///
+ /// A type responsible for creating instances to attach to target elements.
+ ///
+ public abstract class AttachedVisualFactoryBase
+ {
+ ///
+ /// Creates a to attach to the target element.
+ ///
+ /// The target the visual will be attached to.
+ /// A instance that the caller will attach to the target element.
+ public abstract ValueTask GetAttachedVisualAsync(UIElement element);
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
similarity index 81%
rename from Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs
rename to Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
index 6a8278ff032..9caff911f89 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/PipelineVisual.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
@@ -14,7 +14,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media
/// A builder type for instance to apply to UI elements.
///
[ContentProperty(Name = nameof(Effects))]
- public sealed class PipelineVisual
+ public sealed class PipelineVisualFactory : PipelineVisualFactoryBase
{
///
/// Gets or sets the source for the current pipeline (defaults to a with source).
@@ -26,11 +26,8 @@ public sealed class PipelineVisual
///
public IList Effects { get; set; } = new List();
- ///
- /// Gets the instance for the current effects tree.
- ///
- /// The instance for the current effects tree.
- internal PipelineBuilder GetPipeline()
+ ///
+ protected override PipelineBuilder OnPipelineRequested()
{
PipelineBuilder builder = Source ?? PipelineBuilder.FromBackdrop();
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactoryBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactoryBase.cs
new file mode 100644
index 00000000000..472167d5f63
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactoryBase.cs
@@ -0,0 +1,34 @@
+// 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 System.Threading.Tasks;
+using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Hosting;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media
+{
+ ///
+ /// A base class that extends by leveraging the APIs.
+ ///
+ public abstract class PipelineVisualFactoryBase : AttachedVisualFactoryBase
+ {
+ ///
+ public override async ValueTask GetAttachedVisualAsync(UIElement element)
+ {
+ var visual = ElementCompositionPreview.GetElementVisual(element).Compositor.CreateSpriteVisual();
+
+ visual.Brush = await OnPipelineRequested().BuildAsync();
+
+ return visual;
+ }
+
+ ///
+ /// A method that builds and returns the pipeline to use in the current instance.
+ ///
+ /// A instance to create the to display.
+ protected abstract PipelineBuilder OnPipelineRequested();
+ }
+}
From 5ec8ab3f735fb08bdf3d765a0a69fcdf772b0575 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 17:39:07 +0100
Subject: [PATCH 021/171] Enabled notification for brush in use to effects
---
.../Base/XamlCompositionEffectBrushBase.cs | 13 +++++
.../Brushes/PipelineBrush.cs | 9 ++++
.../Effects/BlendEffect.cs | 12 ++++-
.../Effects/BlurEffect.cs | 28 ++++++++++-
.../Effects/CrossFadeEffect.cs | 12 ++++-
.../Effects/ExposureEffect.cs | 6 +++
.../Effects/GrayscaleEffect.cs | 6 +++
.../Effects/HueRotationEffect.cs | 6 +++
.../Effects/Interfaces/IPipelineEffect.cs | 7 +++
.../Effects/InvertEffect.cs | 6 +++
.../Effects/LuminanceToAlphaEffect.cs | 6 +++
.../Effects/OpacityEffect.cs | 6 +++
.../Effects/SaturationEffect.cs | 6 +++
.../Effects/SepiaEffect.cs | 6 +++
.../Effects/ShadeEffect.cs | 6 +++
.../Effects/TemperatureAndTintEffect.cs | 6 +++
.../Effects/TintEffect.cs | 6 +++
.../PipelineBuilder.Effects.Internals.cs | 48 +++++++++++++++++++
.../Visuals/PipelineVisualFactory.cs | 18 ++++++-
19 files changed, 209 insertions(+), 4 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
index 6f685735285..f92d3d16c6e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs
@@ -59,6 +59,8 @@ protected override async void OnConnected()
{
CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
+
+ OnCompositionBrushUpdated();
}
}
@@ -74,6 +76,8 @@ protected override async void OnDisconnected()
{
CompositionBrush.Dispose();
CompositionBrush = null;
+
+ OnCompositionBrushUpdated();
}
}
@@ -111,8 +115,17 @@ protected async void OnEnabledToggled(bool value)
{
CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
+
+ OnCompositionBrushUpdated();
}
}
}
+
+ ///
+ /// Invoked whenever the property is updated.
+ ///
+ protected virtual void OnCompositionBrushUpdated()
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
index caa1460239c..70e695c1600 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs
@@ -38,5 +38,14 @@ protected override PipelineBuilder OnPipelineRequested()
return builder;
}
+
+ ///
+ protected override void OnCompositionBrushUpdated()
+ {
+ foreach (IPipelineEffect effect in Effects)
+ {
+ effect.NotifyCompositionBrushInUse(CompositionBrush);
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
index ce282c29ced..5853df4cfb5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -41,12 +42,21 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
PipelineBuilder inputBuilder = Source ?? PipelineBuilder.FromBackdrop();
- foreach (IPipelineEffect effect in this.Effects)
+ foreach (IPipelineEffect effect in Effects)
{
inputBuilder = effect.AppendToPipeline(inputBuilder);
}
return builder.Blend(inputBuilder, (BlendEffectMode)Mode, Placement);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ foreach (IPipelineEffect effect in Effects)
+ {
+ effect.NotifyCompositionBrushInUse(brush);
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
index b1e6c9437c2..247039bf1ca 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -13,6 +14,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class BlurEffect : IPipelineEffect
{
+ ///
+ /// The unique id for the effect, if is set.
+ ///
+ private string id;
+
+ ///
+ /// The in use, if any.
+ ///
+ private CompositionBrush brush;
+
+ ///
+ /// Gets or sets a value indicating whether the effect can be animated.
+ ///
+ public bool IsAnimatable { get; set; }
+
private double amount;
///
@@ -27,7 +43,17 @@ public double Amount
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
- return builder.Blur((float)Amount);
+ return IsAnimatable switch
+ {
+ true => builder.Blur((float)Amount, out this.id),
+ false => builder.Blur((float)Amount)
+ };
+ }
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ this.brush = brush;
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs
index 8bd4d183f55..e3b0e117060 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -42,12 +43,21 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
PipelineBuilder inputBuilder = Source ?? PipelineBuilder.FromBackdrop();
- foreach (IPipelineEffect effect in this.Effects)
+ foreach (IPipelineEffect effect in Effects)
{
inputBuilder = effect.AppendToPipeline(inputBuilder);
}
return builder.CrossFade(inputBuilder, (float)Factor);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ foreach (IPipelineEffect effect in Effects)
+ {
+ effect.NotifyCompositionBrushInUse(brush);
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
index eeb6a708f8c..edd134cc7f3 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -29,5 +30,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Exposure((float)Amount);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs
index 5e2070d148b..7369416e21a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -17,5 +18,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Grayscale();
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs
index bf76744f3b4..f92b27ec9b5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -22,5 +23,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.HueRotation((float)Angle);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs
index 24a867442c3..5430b753371 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -17,5 +18,11 @@ public interface IPipelineEffect
/// The source instance to add the effect to.
/// A new with the new effects added to it.
PipelineBuilder AppendToPipeline(PipelineBuilder builder);
+
+ ///
+ /// Notifies that a given is now in use.
+ ///
+ /// The in use.
+ internal void NotifyCompositionBrushInUse(CompositionBrush brush);
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs
index 04c0fcd9bb8..6d8b433a4a9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -17,5 +18,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Invert();
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs
index 527b55840e0..76842e9ad27 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -17,5 +18,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.LuminanceToAlpha();
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
index 82b8ea33c56..4546aaef767 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -29,5 +30,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Opacity((float)Value);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
index cce6eee390f..8cb9291b8fe 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -29,5 +30,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Saturation((float)Value);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
index 8e3039d0980..60790a9f691 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -29,5 +30,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Sepia((float)Intensity);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
index 4b6e0debe2d..552d3b03c37 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
@@ -5,6 +5,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
using Windows.UI;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -34,5 +35,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Shade(Color, (float)Intensity);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
index 2c31cbe1c65..ec68ff9d6d3 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -40,5 +41,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.TemperatureAndTint((float)Temperature, (float)Tint);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs
index 11994b21182..6438d693c43 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs
@@ -4,6 +4,7 @@
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
using Windows.UI;
+using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -23,5 +24,10 @@ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
return builder.Tint(Color);
}
+
+ ///
+ void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
+ {
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
new file mode 100644
index 00000000000..aa948d4fbd0
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
@@ -0,0 +1,48 @@
+// 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 System;
+using System.Diagnostics.Contracts;
+using System.Threading.Tasks;
+using Microsoft.Graphics.Canvas.Effects;
+using Microsoft.Toolkit.Uwp.UI.Media.Extensions;
+using Windows.Graphics.Effects;
+using Windows.UI.Composition;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media.Pipelines
+{
+ ///
+ /// A that allows to build custom effects pipelines and create instances from them
+ ///
+ public sealed partial class PipelineBuilder
+ {
+ ///
+ /// Adds a new to the current pipeline
+ ///
+ /// The blur amount to apply
+ /// The assigned id for the created effect, to support animations.
+ /// The parameter for the effect, defaults to
+ /// The parameter to use, defaults to
+ /// A new instance to use to keep adding new effects
+ [Pure]
+ internal PipelineBuilder Blur(
+ float blur,
+ out string id,
+ EffectBorderMode mode = EffectBorderMode.Hard,
+ EffectOptimization optimization = EffectOptimization.Balanced)
+ {
+ id = Guid.NewGuid().ToUppercaseAsciiLetters();
+
+ async ValueTask Factory() => new GaussianBlurEffect
+ {
+ BlurAmount = blur,
+ BorderMode = mode,
+ Optimization = optimization,
+ Source = await this.sourceProducer()
+ };
+
+ return new PipelineBuilder(this, Factory, new[] { $"{id}.{nameof(GaussianBlurEffect.BlurAmount)}" });
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
index 9caff911f89..1788c0df71e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Visuals/PipelineVisualFactory.cs
@@ -3,15 +3,18 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.UI.Media.Effects;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
namespace Microsoft.Toolkit.Uwp.UI.Media
{
///
- /// A builder type for instance to apply to UI elements.
+ /// A builder type for instance to apply to UI elements.
///
[ContentProperty(Name = nameof(Effects))]
public sealed class PipelineVisualFactory : PipelineVisualFactoryBase
@@ -26,6 +29,19 @@ public sealed class PipelineVisualFactory : PipelineVisualFactoryBase
///
public IList Effects { get; set; } = new List();
+ ///
+ public override async ValueTask GetAttachedVisualAsync(UIElement element)
+ {
+ var visual = (SpriteVisual)await base.GetAttachedVisualAsync(element);
+
+ foreach (IPipelineEffect effect in Effects)
+ {
+ effect.NotifyCompositionBrushInUse(visual.Brush);
+ }
+
+ return visual;
+ }
+
///
protected override PipelineBuilder OnPipelineRequested()
{
From e88a6ac349c1bf520bd191e6633f344607e3d8bc Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Fri, 18 Dec 2020 19:45:01 +0100
Subject: [PATCH 022/171] Initial draft support for animating effects
---
.../AnimationBuilder.Models.cs | 35 +++++++++++
.../AnimationBuilder.Setup.cs | 5 ++
.../AnimationBuilder.cs | 60 +++++++++++++++++--
.../Animations/EffectDoubleAnimation.cs | 36 +++++++++++
.../Effects/BlurEffect.cs | 4 +-
.../Microsoft.Toolkit.Uwp.UI.Media.csproj | 4 ++
.../PipelineBuilder.Effects.Internals.cs | 7 ++-
7 files changed, 142 insertions(+), 9 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
index cc2f3f4db58..949e177dc86 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
@@ -15,6 +15,30 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// A model representing a specified composition double animation.
+ ///
+ private sealed record CompositionDoubleAnimation(
+ CompositionObject Target,
+ string Property,
+ float? From,
+ float To,
+ TimeSpan? Delay,
+ TimeSpan Duration,
+ EasingType EasingType,
+ EasingMode EasingMode)
+ : ICompositionAnimation
+ {
+ ///
+ public void StartAnimation()
+ {
+ CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+
+ Target.StartAnimation(Property, animation);
+ }
+ }
+
///
/// A model representing a specified composition scalar animation.
///
@@ -129,5 +153,16 @@ private interface ICompositionAnimationFactory
/// A instance with the specified animation.
CompositionAnimation GetAnimation(Visual visual);
}
+
+ ///
+ /// An interface for custom external composition animations.
+ ///
+ private interface ICompositionAnimation
+ {
+ ///
+ /// Starts a with some embedded parameters.
+ ///
+ void StartAnimation();
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
index d15811cf930..f0245d3cfbd 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
@@ -14,6 +14,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// The list of instances representing animations to run.
+ ///
+ private readonly List compositionAnimations = new();
+
///
/// The list of instances representing factories for composition animations to run.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index fc6f965f062..9821a479537 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -19,6 +19,43 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// Adds a new custom double animation targeting an arbitrary composition object.
+ ///
+ /// The target to animate.
+ /// The target property to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ public AnimationBuilder DoubleAnimation(
+ CompositionObject target,
+ string property,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ CompositionDoubleAnimation animation = new(
+ target,
+ property,
+ (float?)from,
+ (float)to,
+ delay,
+ duration,
+ easingType,
+ easingMode);
+
+ this.compositionAnimations.Add(animation);
+
+ return this;
+ }
+
///
/// Adds a new opacity animation to the current schedule.
///
@@ -284,6 +321,14 @@ public AnimationBuilder Scale(
/// The target to animate.
public void Start(UIElement element)
{
+ if (this.compositionAnimations.Count > 0)
+ {
+ foreach (var animation in this.compositionAnimations)
+ {
+ animation.StartAnimation();
+ }
+ }
+
if (this.compositionAnimationFactories.Count > 0)
{
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
@@ -323,17 +368,24 @@ public Task StartAsync(UIElement element)
compositionTask = Task.CompletedTask,
xamlTask = Task.CompletedTask;
- if (this.compositionAnimationFactories.Count > 0)
+ if (this.compositionAnimationFactories.Count > 0 ||
+ this.compositionAnimations.Count > 0)
{
- ElementCompositionPreview.SetIsTranslationEnabled(element, true);
-
Visual visual = ElementCompositionPreview.GetElementVisual(element);
- CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
CompositionScopedBatch batch = visual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
TaskCompletionSource taskCompletionSource = new();
batch.Completed += (_, _) => taskCompletionSource.SetResult(null);
+ foreach (var animation in this.compositionAnimations)
+ {
+ animation.StartAnimation();
+ }
+
+ ElementCompositionPreview.SetIsTranslationEnabled(element, true);
+
+ CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
+
foreach (var factory in this.compositionAnimationFactories)
{
group.Add(factory.GetAnimation(visual));
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
new file mode 100644
index 00000000000..13655fe87fa
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -0,0 +1,36 @@
+// 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 System;
+using Microsoft.Graphics.Canvas.Effects;
+using Microsoft.Toolkit.Uwp.UI.Animations;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+using Microsoft.Toolkit.Uwp.UI.Media.Effects;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media.Animations
+{
+ ///
+ /// A set of animations that can be grouped together.
+ ///
+ public class EffectDoubleAnimation : TypedAnimation, ITimeline
+ {
+ public IPipelineEffect Target { get; set; }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
+ {
+ BlurEffect effect = (BlurEffect)Target;
+
+ return builder.DoubleAnimation(
+ effect.brush,
+ $"{effect.id}.{nameof(GaussianBlurEffect.BlurAmount)}",
+ From,
+ To,
+ Delay ?? delayHint,
+ Duration ?? durationHint.GetValueOrDefault(),
+ EasingType,
+ EasingMode);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
index 247039bf1ca..7b864291d47 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
@@ -17,12 +17,12 @@ public sealed class BlurEffect : IPipelineEffect
///
/// The unique id for the effect, if is set.
///
- private string id;
+ internal string id;
///
/// The in use, if any.
///
- private CompositionBrush brush;
+ internal CompositionBrush brush;
///
/// Gets or sets a value indicating whether the effect can be animated.
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Microsoft.Toolkit.Uwp.UI.Media.csproj b/Microsoft.Toolkit.Uwp.UI.Media/Microsoft.Toolkit.Uwp.UI.Media.csproj
index d7ba95d0111..68007be8c43 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Microsoft.Toolkit.Uwp.UI.Media.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Microsoft.Toolkit.Uwp.UI.Media.csproj
@@ -43,4 +43,8 @@
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
index aa948d4fbd0..3e901830224 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.Internals.cs
@@ -32,17 +32,18 @@ internal PipelineBuilder Blur(
EffectBorderMode mode = EffectBorderMode.Hard,
EffectOptimization optimization = EffectOptimization.Balanced)
{
- id = Guid.NewGuid().ToUppercaseAsciiLetters();
+ string name = id = Guid.NewGuid().ToUppercaseAsciiLetters();
async ValueTask Factory() => new GaussianBlurEffect
{
BlurAmount = blur,
BorderMode = mode,
Optimization = optimization,
- Source = await this.sourceProducer()
+ Source = await this.sourceProducer(),
+ Name = name
};
- return new PipelineBuilder(this, Factory, new[] { $"{id}.{nameof(GaussianBlurEffect.BlurAmount)}" });
+ return new PipelineBuilder(this, Factory, new[] { $"{name}.{nameof(GaussianBlurEffect.BlurAmount)}" });
}
}
}
From 9c0a50a7d2b1ee13c36152887323c65d547cd113 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 00:32:11 +0100
Subject: [PATCH 023/171] Added missing file headers
---
.../Animations/AnimationEndBehavior.cs | 6 +++++-
.../Animations/AnimationStartBehavior.cs | 6 +++++-
.../Animations/StartAnimationAction.cs | 6 +++++-
.../Extensions/UIElementExtensions.cs | 6 +++++-
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
index 807b1229c19..a041e864d9f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
@@ -1,4 +1,8 @@
-using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+// 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 Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
index 3dfdfc59926..1d5ab45946a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
@@ -1,4 +1,8 @@
-using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+// 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 Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
namespace Microsoft.Toolkit.Uwp.UI.Behaviors.Animations
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
index f174dd727a9..41608115529 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/StartAnimationAction.cs
@@ -1,4 +1,8 @@
-using Microsoft.Toolkit.Diagnostics;
+// 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 Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
index 82eb8742e37..bd0c7bc9a35 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs
@@ -1,4 +1,8 @@
-using Microsoft.Toolkit.Uwp.UI.Media.Extensions;
+// 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 Microsoft.Toolkit.Uwp.UI.Media.Extensions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
From ddb66d293bf3502a5be93d6857840e56282fe6f5 Mon Sep 17 00:00:00 2001
From: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Date: Fri, 18 Dec 2020 16:19:41 -0800
Subject: [PATCH 024/171] Add new Behaviors project to Smoke Tests
Also refactored list to make it easier to read.
---
.../MainPage.xaml | 35 +++++++++++
.../MainPage.xaml.cs | 60 +++++++++++++++++++
.../Microsoft.Toolkit.Uwp.UI/MainPage.xaml | 30 +++-------
.../Microsoft.Toolkit.Uwp.UI/MainPage.xaml.cs | 39 +-----------
SmokeTests/SmokeTests.proj | 22 ++++++-
5 files changed, 127 insertions(+), 59 deletions(-)
create mode 100644 SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml
create mode 100644 SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml.cs
diff --git a/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml b/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml
new file mode 100644
index 00000000000..cef24c59c88
--- /dev/null
+++ b/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml.cs b/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml.cs
new file mode 100644
index 00000000000..d1fe446c34f
--- /dev/null
+++ b/SmokeTests/Microsoft.Toolkit.Uwp.UI.Behaviors/MainPage.xaml.cs
@@ -0,0 +1,60 @@
+// 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 System;
+using System.Diagnostics;
+using System.Linq;
+using Microsoft.Toolkit.Uwp.UI.Behaviors;
+using Microsoft.Xaml.Interactivity;
+using Windows.UI.Xaml.Media.Imaging;
+
+namespace SmokeTest
+{
+ public sealed partial class MainPage
+ {
+ public MainPage()
+ {
+ InitializeComponent();
+
+ Loaded += this.MainPage_Loaded;
+ }
+
+ private void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
+ {
+ var behaviors = Interaction.GetBehaviors(EffectElementHost);
+ var viewportBehavior = behaviors.OfType().FirstOrDefault();
+ if (viewportBehavior != null)
+ {
+ viewportBehavior.EnteredViewport += EffectElementHost_EnteredViewport;
+ viewportBehavior.EnteringViewport += EffectElementHost_EnteringViewport;
+ viewportBehavior.ExitedViewport += EffectElementHost_ExitedViewport;
+ viewportBehavior.ExitingViewport += EffectElementHost_ExitingViewport;
+ }
+ }
+
+ private void EffectElementHost_EnteredViewport(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Entered viewport");
+ }
+
+ private void EffectElementHost_EnteringViewport(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Entering viewport");
+
+ EffectElement.Source = new BitmapImage(new Uri("ms-appx:///Assets/ToolkitLogo.png"));
+ }
+
+ private void EffectElementHost_ExitedViewport(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Exited viewport");
+
+ EffectElement.Source = null;
+ }
+
+ private void EffectElementHost_ExitingViewport(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Exiting viewport");
+ }
+ }
+}
diff --git a/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml b/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml
index cef24c59c88..f6361b121cc 100644
--- a/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml
+++ b/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml
@@ -3,33 +3,19 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SmokeTest"
- xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
- xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
+ xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml.cs b/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml.cs
index d1fe446c34f..8acca918716 100644
--- a/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml.cs
+++ b/SmokeTests/Microsoft.Toolkit.Uwp.UI/MainPage.xaml.cs
@@ -5,9 +5,8 @@
using System;
using System.Diagnostics;
using System.Linq;
-using Microsoft.Toolkit.Uwp.UI.Behaviors;
-using Microsoft.Xaml.Interactivity;
-using Windows.UI.Xaml.Media.Imaging;
+using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Xaml.Controls;
namespace SmokeTest
{
@@ -22,39 +21,7 @@ public MainPage()
private void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- var behaviors = Interaction.GetBehaviors(EffectElementHost);
- var viewportBehavior = behaviors.OfType().FirstOrDefault();
- if (viewportBehavior != null)
- {
- viewportBehavior.EnteredViewport += EffectElementHost_EnteredViewport;
- viewportBehavior.EnteringViewport += EffectElementHost_EnteringViewport;
- viewportBehavior.ExitedViewport += EffectElementHost_ExitedViewport;
- viewportBehavior.ExitingViewport += EffectElementHost_ExitingViewport;
- }
- }
-
- private void EffectElementHost_EnteredViewport(object sender, EventArgs e)
- {
- Debug.WriteLine("Entered viewport");
- }
-
- private void EffectElementHost_EnteringViewport(object sender, EventArgs e)
- {
- Debug.WriteLine("Entering viewport");
-
- EffectElement.Source = new BitmapImage(new Uri("ms-appx:///Assets/ToolkitLogo.png"));
- }
-
- private void EffectElementHost_ExitedViewport(object sender, EventArgs e)
- {
- Debug.WriteLine("Exited viewport");
-
- EffectElement.Source = null;
- }
-
- private void EffectElementHost_ExitingViewport(object sender, EventArgs e)
- {
- Debug.WriteLine("Exiting viewport");
+ var border = this.FindDescendant();
}
}
}
diff --git a/SmokeTests/SmokeTests.proj b/SmokeTests/SmokeTests.proj
index 18b9aee3a8b..ae2228c01c2 100644
--- a/SmokeTests/SmokeTests.proj
+++ b/SmokeTests/SmokeTests.proj
@@ -4,7 +4,27 @@
x86Release
- UWPBaseline;Microsoft.Toolkit;Microsoft.Toolkit.HighPerformance;Microsoft.Toolkit.Parsers;Microsoft.Toolkit.Mvvm;Microsoft.Toolkit.Services;Microsoft.Toolkit.Uwp;Microsoft.Toolkit.Uwp.Connectivity;Microsoft.Toolkit.Uwp.DeveloperTools;Microsoft.Toolkit.Uwp.Input.GazeInteraction;Microsoft.Toolkit.Uwp.Notifications;Microsoft.Toolkit.Uwp.UI;Microsoft.Toolkit.Uwp.UI.Animations;Microsoft.Toolkit.Uwp.UI.Controls;Microsoft.Toolkit.Uwp.UI.Controls.DataGrid;Microsoft.Toolkit.Uwp.UI.Controls.Layout;Microsoft.Toolkit.Uwp.UI.Media;Microsoft.Toolkit.Uwp.UI.Controls.Markdown
+
+ UWPBaseline;
+ Microsoft.Toolkit;
+ Microsoft.Toolkit.HighPerformance;
+ Microsoft.Toolkit.Mvvm;
+ Microsoft.Toolkit.Parsers;
+ Microsoft.Toolkit.Services;
+ Microsoft.Toolkit.Uwp;
+ Microsoft.Toolkit.Uwp.Connectivity;
+ Microsoft.Toolkit.Uwp.DeveloperTools;
+ Microsoft.Toolkit.Uwp.Input.GazeInteraction;
+ Microsoft.Toolkit.Uwp.Notifications;
+ Microsoft.Toolkit.Uwp.UI;
+ Microsoft.Toolkit.Uwp.UI.Animations;
+ Microsoft.Toolkit.Uwp.UI.Behaviors;
+ Microsoft.Toolkit.Uwp.UI.Controls;
+ Microsoft.Toolkit.Uwp.UI.Controls.DataGrid;
+ Microsoft.Toolkit.Uwp.UI.Controls.Layout;
+ Microsoft.Toolkit.Uwp.UI.Controls.Markdown;
+ Microsoft.Toolkit.Uwp.UI.Media;
+
Date: Sat, 19 Dec 2020 13:02:29 +0100
Subject: [PATCH 025/171] Minor code tweaks
---
.../AnimationBuilder.Models.cs | 18 +++++-----
.../AnimationBuilder.Setup.cs | 20 +++++------
.../AnimationBuilder.cs | 34 +++++++++----------
3 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
index 949e177dc86..10a2b876c16 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
@@ -16,7 +16,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
public sealed partial class AnimationBuilder
{
///
- /// A model representing a specified composition double animation.
+ /// A model representing a specified composition double animation for a target .
///
private sealed record CompositionDoubleAnimation(
CompositionObject Target,
@@ -40,9 +40,9 @@ public void StartAnimation()
}
///
- /// A model representing a specified composition scalar animation.
+ /// A model representing a specified composition scalar animation factory.
///
- private sealed record CompositionScalarAnimation(
+ private sealed record CompositionScalarAnimationFactory(
string Property,
float? From,
float To,
@@ -63,9 +63,9 @@ public CompositionAnimation GetAnimation(Visual visual)
}
///
- /// A model representing a specified composition animation.
+ /// A model representing a specified composition animation factory.
///
- private sealed record CompositionVector3Animation(
+ private sealed record CompositionVector3AnimationFactory(
string Property,
Vector3? From,
Vector3 To,
@@ -86,9 +86,9 @@ public CompositionAnimation GetAnimation(Visual visual)
}
///
- /// A model representing a specified XAML animation.
+ /// A model representing a specified XAML animation factory.
///
- private sealed record XamlDoubleAnimation(
+ private sealed record XamlDoubleAnimationFactory(
string Property,
double? From,
double To,
@@ -107,9 +107,9 @@ public Timeline GetAnimation(UIElement element)
}
///
- /// A model representing a specified XAML animation targeting a transform.
+ /// A model representing a specified XAML animation factory targeting a transform.
///
- private sealed record XamlTransformDoubleAnimation(
+ private sealed record XamlTransformDoubleAnimationFactory(
string Property,
double? From,
double To,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
index f0245d3cfbd..a7f8a2b5d83 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
@@ -40,7 +40,7 @@ public sealed partial class AnimationBuilder
/// The easing function for the animation.
/// The easing mode for the animation.
/// The current instance.
- private AnimationBuilder OnCompositionScalarAnimation(
+ private AnimationBuilder AddCompositionScalarAnimationFactory(
string property,
float? from,
float to,
@@ -49,7 +49,7 @@ private AnimationBuilder OnCompositionScalarAnimation(
EasingType easingType,
EasingMode easingMode)
{
- CompositionScalarAnimation animation = new(property, from, to, delay, duration, easingType, easingMode);
+ CompositionScalarAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
this.compositionAnimationFactories.Add(animation);
@@ -68,7 +68,7 @@ private AnimationBuilder OnCompositionScalarAnimation(
/// The easing mode for the animation.
/// The current instance.
/// This will use a animation with a zero Z axis.
- private AnimationBuilder OnCompositionVector2Animation(
+ private AnimationBuilder AddCompositionVector2AnimationFactory(
string property,
Vector2? from,
Vector2 to,
@@ -79,7 +79,7 @@ private AnimationBuilder OnCompositionVector2Animation(
{
Vector3? from3 = from is null ? null : new(from.Value, 0);
Vector3 to3 = new(to, 0);
- CompositionVector3Animation animation = new(property, from3, to3, delay, duration, easingType, easingMode);
+ CompositionVector3AnimationFactory animation = new(property, from3, to3, delay, duration, easingType, easingMode);
this.compositionAnimationFactories.Add(animation);
@@ -97,7 +97,7 @@ private AnimationBuilder OnCompositionVector2Animation(
/// The easing function for the animation.
/// The easing mode for the animation.
/// The current instance.
- private AnimationBuilder OnCompositionVector3Animation(
+ private AnimationBuilder AddCompositionVector3AnimationFactory(
string property,
Vector3? from,
Vector3 to,
@@ -106,7 +106,7 @@ private AnimationBuilder OnCompositionVector3Animation(
EasingType easingType,
EasingMode easingMode)
{
- CompositionVector3Animation animation = new(property, from, to, delay, duration, easingType, easingMode);
+ CompositionVector3AnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
this.compositionAnimationFactories.Add(animation);
@@ -125,7 +125,7 @@ private AnimationBuilder OnCompositionVector3Animation(
/// The easing mode for the animation.
/// Whether to set .
/// The current instance.
- private AnimationBuilder OnXamlDoubleAnimation(
+ private AnimationBuilder AddXamlDoubleAnimationFactory(
string property,
double? from,
double to,
@@ -135,7 +135,7 @@ private AnimationBuilder OnXamlDoubleAnimation(
EasingMode easingMode,
bool enableDependentAnimation)
{
- XamlDoubleAnimation animation = new(property, from, to, delay, duration, easingType, easingMode, enableDependentAnimation);
+ XamlDoubleAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode, enableDependentAnimation);
this.xamlAnimationFactories.Add(animation);
@@ -153,7 +153,7 @@ private AnimationBuilder OnXamlDoubleAnimation(
/// The easing function for the animation.
/// The easing mode for the animation.
/// The current instance.
- private AnimationBuilder OnXamlTransformDoubleAnimation(
+ private AnimationBuilder AddXamlTransformDoubleAnimationFactory(
string property,
double? from,
double to,
@@ -162,7 +162,7 @@ private AnimationBuilder OnXamlTransformDoubleAnimation(
EasingType easingType,
EasingMode easingMode)
{
- XamlTransformDoubleAnimation animation = new(property, from, to, delay, duration, easingType, easingMode);
+ XamlTransformDoubleAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
this.xamlAnimationFactories.Add(animation);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index 9821a479537..4f79188cf26 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -78,11 +78,11 @@ public AnimationBuilder Opacity(
{
if (layer == FrameworkLayer.Composition)
{
- return OnCompositionScalarAnimation(nameof(Visual.Opacity), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float?)from, (float)to, delay, duration, easingType, easingMode);
}
else
{
- return OnXamlDoubleAnimation(nameof(UIElement.Opacity), from, to, delay, duration, easingType, easingMode, false);
+ return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), from, to, delay, duration, easingType, easingMode, false);
}
}
@@ -110,11 +110,11 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return OnCompositionScalarAnimation($"Translation.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
}
else
{
- return OnXamlDoubleAnimation($"Translate{axis}", from, to, delay, duration, easingType, easingMode, false);
+ return AddXamlDoubleAnimationFactory($"Translate{axis}", from, to, delay, duration, easingType, easingMode, false);
}
}
@@ -140,12 +140,12 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return OnCompositionVector2Animation("Translation", from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector2AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
}
else
{
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
return this;
}
@@ -170,7 +170,7 @@ public AnimationBuilder Translation(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return OnCompositionVector3Animation("Translation", from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
}
///
@@ -194,7 +194,7 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return OnCompositionScalarAnimation($"{nameof(Visual.Offset)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
}
///
@@ -216,7 +216,7 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return OnCompositionVector2Animation(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
}
///
@@ -238,7 +238,7 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return OnCompositionVector3Animation(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
}
///
@@ -266,12 +266,12 @@ public AnimationBuilder Scale(
Vector2? from2 = from is null ? null : new((float)(double)from);
Vector2 to2 = new((float)to);
- return OnCompositionVector2Animation(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
}
else
{
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
return this;
}
@@ -304,12 +304,12 @@ public AnimationBuilder Scale(
Vector2? from2 = from is null ? null : new((float)(double)from);
Vector2 to2 = new((float)to);
- return OnCompositionVector2Animation(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
}
else
{
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
- OnXamlTransformDoubleAnimation(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
return this;
}
From ce10ef3dc99644f1871cfbe6814b9861d37c9312 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 13:06:37 +0100
Subject: [PATCH 026/171] Fixed some StyleCop warnings
---
.../AnimationBuilder.cs | 2 ++
.../Extensions/CompositionObjectExtensions.cs | 2 ++
.../Extensions/CompositorExtensions.cs | 2 ++
.../Extensions/DependencyObjectExtensions.cs | 2 ++
.../Extensions/EasingTypeExtensions.cs | 2 ++
.../Extensions/StoryboardAnimations.cs | 2 ++
...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 1 -
.../Xaml/Abstract/TypedAnimation{T}.cs | 2 ++
.../Xaml/AnimationCollection2.cs | 36 ++++++++++---------
.../Animations/AnimationEndBehavior.cs | 2 ++
.../Animations/AnimationStartBehavior.cs | 2 ++
.../Microsoft.Toolkit.Uwp.UI.Behaviors.csproj | 1 -
12 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index 4f79188cf26..0014519b4b2 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System;
using System.Numerics;
using System.Threading.Tasks;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
index a90faae4361..d12081f4d9e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System;
using System.Numerics;
using Windows.UI.Composition;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
index 6a92d382c86..c610ef4b866 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System;
using System.Diagnostics.Contracts;
using System.Numerics;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
index 51f7ae5be96..4306f0310f7 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System;
using System.Diagnostics.Contracts;
using Windows.UI.Xaml;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/EasingTypeExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/EasingTypeExtensions.cs
index 5dff3dfe6a2..57fb05749b5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/EasingTypeExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/EasingTypeExtensions.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System.Diagnostics.Contracts;
using Microsoft.Toolkit.Diagnostics;
using Windows.UI.Xaml.Media.Animation;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/StoryboardAnimations.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/StoryboardAnimations.cs
index 771fbc376d7..7e6651718f5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/StoryboardAnimations.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/StoryboardAnimations.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System.Threading.Tasks;
using Windows.UI.Xaml.Media.Animation;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
index 57f66ccdcb9..e49f7af1cd7 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
@@ -16,7 +16,6 @@
UWP Toolkit Windows Animations Composition Connected Implicit XAML9.0
- enable
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
index d6c95189b12..abdd6d15e1c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index a3f31e28a07..100a7dba77f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using System;
using System.Collections;
using System.Collections.Generic;
@@ -16,29 +18,29 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
public sealed class AnimationCollection2 : DependencyObject, IList, ITimeline
{
///
- /// Raised whenever the current animation is started.
+ /// The underlying list of animations.
///
- public event EventHandler? Started;
+ private readonly List list = new();
///
- /// Raised whenever the current animation ends.
+ /// The reference to the parent that owns the current animation collection.
///
- public event EventHandler? Ended;
+ private WeakReference? parent;
///
- /// Raised whenever the current collection changes.
+ /// Raised whenever the current animation is started.
///
- public event EventHandler? CollectionChanged;
+ public event EventHandler? Started;
///
- /// The underlying list of animations.
+ /// Raised whenever the current animation ends.
///
- private readonly List list = new();
+ public event EventHandler? Ended;
///
- /// The reference to the parent that owns the current animation collection.
+ /// Raised whenever the current collection changes.
///
- private WeakReference? parent;
+ public event EventHandler? CollectionChanged;
///
/// Gets or sets the parent for the current animation collection.
@@ -53,9 +55,15 @@ internal UIElement? Parent
return element;
}
- set => parent = new(value!);
+ set => this.parent = new(value!);
}
+ ///
+ public int Count => this.list.Count;
+
+ ///
+ public bool IsReadOnly => false;
+
///
public Animation this[int index]
{
@@ -68,12 +76,6 @@ public Animation this[int index]
}
}
- ///
- public int Count => this.list.Count;
-
- ///
- public bool IsReadOnly => false;
-
///
public void Add(Animation item)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
index a041e864d9f..3f96634f6a4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
index 1d5ab45946a..fd49c019068 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Xaml.Interactivity;
diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
index 514ff0307e4..6ed65c4d436 100644
--- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Microsoft.Toolkit.Uwp.UI.Behaviors.csproj
@@ -3,7 +3,6 @@
uap10.0.177639.0
- enableWindows Community Toolkit UI Behaviors
This library provides UI behaviors built on the XAML behaviors SDK. It is part of the Windows Community Toolkit.
From 789e26176102951355347fb0746fc33582647178 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 13:40:23 +0100
Subject: [PATCH 027/171] Added AnimationDictionary type, code tweaks
---
.../Explicit.cs | 48 +++---
.../Xaml/AnimationCollection2.cs | 113 ++-----------
.../Xaml/AnimationDictionary.cs | 149 ++++++++++++++++++
3 files changed, 189 insertions(+), 121 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
index c2d6220500c..863e5c4fa2c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Explicit.cs
@@ -13,41 +13,41 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
public static class Explicit
{
///
- /// Identifies the Implicit.ShowAnimations XAML attached property.
+ /// Identifies the property for the attached instance.
///
- public static readonly DependencyProperty Animations = DependencyProperty.RegisterAttached(
- "ShowAnimations",
- typeof(AnimationCollection),
- typeof(Implicit),
- new PropertyMetadata(null, OnAnimationsChanged));
+ public static readonly DependencyProperty AnimationsProperty = DependencyProperty.RegisterAttached(
+ "Animations",
+ typeof(AnimationDictionary),
+ typeof(Explicit),
+ new PropertyMetadata(null, OnAnimationsPropertyChanged));
///
- /// Gets the value of the property.
+ /// Gets the value of the property.
///
/// The to get the value for.
- /// The retrieved item.
- public static AnimationCollection2 GetAnimations(UIElement element)
+ /// The retrieved item.
+ public static AnimationDictionary GetAnimations(UIElement element)
{
- if (element.GetValue(Animations) is AnimationCollection2 collection)
+ if (element.GetValue(AnimationsProperty) is AnimationDictionary collection)
{
return collection;
}
- collection = new AnimationCollection2();
+ collection = new AnimationDictionary();
- element.SetValue(Animations, collection);
+ element.SetValue(AnimationsProperty, collection);
return collection;
}
///
- /// Sets the value of the property.
+ /// Sets the value of the property.
///
/// The to set the value for.
- /// The value to set.
- public static void SetAnimations(UIElement element, AnimationCollection2 value)
+ /// The value to set.
+ public static void SetAnimations(UIElement element, AnimationDictionary value)
{
- element.SetValue(Animations, value);
+ element.SetValue(AnimationsProperty, value);
}
///
@@ -55,11 +55,21 @@ public static void SetAnimations(UIElement element, AnimationCollection2 value)
///
/// The target object the property was changed for.
/// The instance for the current event.
- private static void OnAnimationsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ private static void OnAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- if (e.NewValue is AnimationCollection2 animationCollection && d is UIElement element)
+ if (d is not UIElement element)
{
- animationCollection.Parent = element;
+ return;
+ }
+
+ if (e.OldValue is AnimationDictionary oldDictionary)
+ {
+ oldDictionary.Parent = null;
+ }
+
+ if (e.NewValue is AnimationDictionary newDictionary)
+ {
+ newDictionary.Parent = element;
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 100a7dba77f..0b963cbd5c9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -5,23 +5,20 @@
#nullable enable
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.UI.Xaml;
+using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
- /// A collection of animations that can be grouped together.
+ /// A collection of animations that can be grouped together. This type represents a composite animation
+ /// (such as ) that can be executed on a given element.
///
- public sealed class AnimationCollection2 : DependencyObject, IList, ITimeline
+ [ContentProperty(Name = nameof(Animations))]
+ public sealed class AnimationCollection2 : DependencyObject, ITimeline
{
- ///
- /// The underlying list of animations.
- ///
- private readonly List list = new();
-
///
/// The reference to the parent that owns the current animation collection.
///
@@ -42,6 +39,11 @@ public sealed class AnimationCollection2 : DependencyObject, IList, I
///
public event EventHandler? CollectionChanged;
+ ///
+ /// Gets or sets the list of animations in the current collection.
+ ///
+ public IList Animations { get; set; } = new List();
+
///
/// Gets or sets the parent for the current animation collection.
///
@@ -58,99 +60,6 @@ internal UIElement? Parent
set => this.parent = new(value!);
}
- ///
- public int Count => this.list.Count;
-
- ///
- public bool IsReadOnly => false;
-
- ///
- public Animation this[int index]
- {
- get => this.list[index];
- set
- {
- this.list[index] = value;
-
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
- }
-
- ///
- public void Add(Animation item)
- {
- this.list.Add(item);
-
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
-
- ///
- public void Clear()
- {
- this.list.Clear();
-
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
-
- ///
- public bool Contains(Animation item)
- {
- return this.list.Contains(item);
- }
-
- ///
- public void CopyTo(Animation[] array, int arrayIndex)
- {
- this.list.CopyTo(array, arrayIndex);
- }
-
- ///
- public IEnumerator GetEnumerator()
- {
- return this.list.GetEnumerator();
- }
-
- ///
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.list.GetEnumerator();
- }
-
- ///
- public int IndexOf(Animation item)
- {
- return this.list.IndexOf(item);
- }
-
- ///
- public void Insert(int index, Animation item)
- {
- this.list.Insert(index, item);
-
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
-
- ///
- public bool Remove(Animation item)
- {
- bool removed = this.list.Remove(item);
-
- if (removed)
- {
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
-
- return removed;
- }
-
- ///
- public void RemoveAt(int index)
- {
- this.list.RemoveAt(index);
-
- CollectionChanged?.Invoke(this, EventArgs.Empty);
- }
-
///
public void Start()
{
@@ -182,7 +91,7 @@ public async Task StartAsync(UIElement element)
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
{
- foreach (ITimeline element in this)
+ foreach (ITimeline element in Animations)
{
builder = element.AppendToBuilder(builder, delayHint, durationHint);
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
new file mode 100644
index 00000000000..48448eef17e
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
@@ -0,0 +1,149 @@
+// 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.
+
+#nullable enable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Windows.UI.Xaml;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A collection of animations that can be defined from XAML.
+ ///
+ public sealed class AnimationDictionary : DependencyObject, IList
+ {
+ ///
+ /// The underlying list of animations.
+ ///
+ private readonly List list = new();
+
+ ///
+ /// The reference to the parent that owns the current animation dictionary.
+ ///
+ private WeakReference? parent;
+
+ ///
+ /// Gets or sets the parent for the current animation dictionary.
+ ///
+ internal UIElement? Parent
+ {
+ get
+ {
+ UIElement? element = null;
+
+ _ = this.parent?.TryGetTarget(out element);
+
+ return element;
+ }
+ set
+ {
+ this.parent = new(value!);
+
+ foreach (var item in this.list)
+ {
+ item.Parent = value;
+ }
+ }
+ }
+
+ ///
+ public int Count => this.list.Count;
+
+ ///
+ public bool IsReadOnly => false;
+
+ ///
+ public AnimationCollection2 this[int index]
+ {
+ get => this.list[index];
+ set
+ {
+ this.list[index].Parent = null;
+ this.list[index] = value;
+
+ value.Parent = Parent;
+ }
+ }
+
+ ///
+ public void Add(AnimationCollection2 item)
+ {
+ this.list.Add(item);
+
+ item.Parent = Parent;
+ }
+
+ ///
+ public void Clear()
+ {
+ foreach (var item in this.list)
+ {
+ item.Parent = null;
+ }
+
+ this.list.Clear();
+ }
+
+ ///
+ public bool Contains(AnimationCollection2 item)
+ {
+ return this.list.Contains(item);
+ }
+
+ ///
+ public void CopyTo(AnimationCollection2[] array, int arrayIndex)
+ {
+ this.list.CopyTo(array, arrayIndex);
+ }
+
+ ///
+ public IEnumerator GetEnumerator()
+ {
+ return this.list.GetEnumerator();
+ }
+
+ ///
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return this.list.GetEnumerator();
+ }
+
+ ///
+ public int IndexOf(AnimationCollection2 item)
+ {
+ return this.list.IndexOf(item);
+ }
+
+ ///
+ public void Insert(int index, AnimationCollection2 item)
+ {
+ this.list.Insert(index, item);
+
+ item.Parent = Parent;
+ }
+
+ ///
+ public bool Remove(AnimationCollection2 item)
+ {
+ bool removed = this.list.Remove(item);
+
+ if (removed)
+ {
+ item.Parent = null;
+ }
+
+ return removed;
+ }
+
+ ///
+ public void RemoveAt(int index)
+ {
+ this.list[index].Parent = null;
+ this.list.RemoveAt(index);
+ }
+ }
+}
From 65c2c584c6933d9672797b04b704650295ce6f34 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 13:48:16 +0100
Subject: [PATCH 028/171] Optimized reuse of weak parent references
---
.../Xaml/AnimationCollection2.cs | 33 +++++--------------
.../Xaml/AnimationDictionary.cs | 28 ++++++----------
2 files changed, 19 insertions(+), 42 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 0b963cbd5c9..9bd5fc7badf 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using Microsoft.Toolkit.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
@@ -19,11 +20,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
[ContentProperty(Name = nameof(Animations))]
public sealed class AnimationCollection2 : DependencyObject, ITimeline
{
- ///
- /// The reference to the parent that owns the current animation collection.
- ///
- private WeakReference? parent;
-
///
/// Raised whenever the current animation is started.
///
@@ -34,31 +30,15 @@ public sealed class AnimationCollection2 : DependencyObject, ITimeline
///
public event EventHandler? Ended;
- ///
- /// Raised whenever the current collection changes.
- ///
- public event EventHandler? CollectionChanged;
-
///
/// Gets or sets the list of animations in the current collection.
///
public IList Animations { get; set; } = new List();
///
- /// Gets or sets the parent for the current animation collection.
+ /// Gets or sets the weak reference to the parent that owns the current animation collection.
///
- internal UIElement? Parent
- {
- get
- {
- UIElement? element = null;
-
- _ = this.parent?.TryGetTarget(out element);
-
- return element;
- }
- set => this.parent = new(value!);
- }
+ internal WeakReference? ParentReference { get; set; }
///
public void Start()
@@ -69,7 +49,12 @@ public void Start()
///
public Task StartAsync()
{
- return StartAsync(Parent!);
+ if (!ParentReference.TryGetTarget(out UIElement? parent))
+ {
+ ThrowHelper.ThrowInvalidOperationException("The current animation collection isn't bound to a parent UIElement instance.");
+ }
+
+ return StartAsync(parent);
}
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
index 48448eef17e..58135c86021 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationDictionary.cs
@@ -27,25 +27,17 @@ public sealed class AnimationDictionary : DependencyObject, IList? parent;
///
- /// Gets or sets the parent for the current animation dictionary.
+ /// Sets the parent for the current animation dictionary.
///
internal UIElement? Parent
{
- get
- {
- UIElement? element = null;
-
- _ = this.parent?.TryGetTarget(out element);
-
- return element;
- }
set
{
- this.parent = new(value!);
+ WeakReference parent = this.parent = new(value!);
foreach (var item in this.list)
{
- item.Parent = value;
+ item.ParentReference = parent;
}
}
}
@@ -62,10 +54,10 @@ public AnimationCollection2 this[int index]
get => this.list[index];
set
{
- this.list[index].Parent = null;
+ this.list[index].ParentReference = null;
this.list[index] = value;
- value.Parent = Parent;
+ value.ParentReference = this.parent;
}
}
@@ -74,7 +66,7 @@ public void Add(AnimationCollection2 item)
{
this.list.Add(item);
- item.Parent = Parent;
+ item.ParentReference = this.parent;
}
///
@@ -82,7 +74,7 @@ public void Clear()
{
foreach (var item in this.list)
{
- item.Parent = null;
+ item.ParentReference = this.parent;
}
this.list.Clear();
@@ -123,7 +115,7 @@ public void Insert(int index, AnimationCollection2 item)
{
this.list.Insert(index, item);
- item.Parent = Parent;
+ item.ParentReference = this.parent;
}
///
@@ -133,7 +125,7 @@ public bool Remove(AnimationCollection2 item)
if (removed)
{
- item.Parent = null;
+ item.ParentReference = null;
}
return removed;
@@ -142,7 +134,7 @@ public bool Remove(AnimationCollection2 item)
///
public void RemoveAt(int index)
{
- this.list[index].Parent = null;
+ this.list[index].ParentReference = null;
this.list.RemoveAt(index);
}
}
From b30190ed9bf95e1c029ee031fbb72a951acacf8d Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 14:34:27 +0100
Subject: [PATCH 029/171] Ported remaining animation types
---
.../AnimationBuilder.Models.cs | 24 ++
.../AnimationBuilder.cs | 222 +++++++++++++++++-
2 files changed, 241 insertions(+), 5 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
index 10a2b876c16..0d1e6af48b3 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
@@ -85,6 +85,30 @@ public CompositionAnimation GetAnimation(Visual visual)
}
}
+ ///
+ /// A model representing a specified composition scalar animation factory targeting a clip.
+ ///
+ private sealed record CompositionClipScalarAnimation(
+ string Property,
+ float? From,
+ float To,
+ TimeSpan? Delay,
+ TimeSpan Duration,
+ EasingType EasingType,
+ EasingMode EasingMode)
+ : ICompositionAnimationFactory
+ {
+ ///
+ public CompositionAnimation GetAnimation(Visual visual)
+ {
+ InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip());
+ CompositionEasingFunction easingFunction = clip.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+
+ return animation;
+ }
+ }
+
///
/// A model representing a specified XAML animation factory.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index 0014519b4b2..d6e6e36993e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -7,6 +7,7 @@
using System;
using System.Numerics;
using System.Threading.Tasks;
+using Microsoft.Toolkit.Diagnostics;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
@@ -289,9 +290,164 @@ public AnimationBuilder Scale(
/// The animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the XAML layer.
+ public AnimationBuilder Scale(
+ Axis axis,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new scale animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Scale(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from?.X, to.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new scale animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Scale(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new rotation animation to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Rotate(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), from, to, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new clip animation to the current schedule.
+ ///
+ /// The clip size to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Clip(
+ Side side,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ string property = side switch
+ {
+ Side.Top => nameof(InsetClip.TopInset),
+ Side.Bottom => nameof(InsetClip.BottomInset),
+ Side.Right => nameof(InsetClip.RightInset),
+ Side.Left => nameof(InsetClip.LeftInset),
+ _ => ThrowHelper.ThrowArgumentException("Invalid clip size")
+ };
+
+ CompositionClipScalarAnimation animation = new(
+ property,
+ (float?)from,
+ (float)to,
+ delay,
+ duration,
+ easingType,
+ easingMode);
+
+ this.compositionAnimationFactories.Add(animation);
+
+ return this;
+ }
+
+ ///
+ /// Adds a new size animation for a single axis to the current schedule.
+ ///
+ /// The target size axis to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Size(
Axis axis,
double? from,
double to,
@@ -303,20 +459,76 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- Vector2? from2 = from is null ? null : new((float)(double)from);
- Vector2 to2 = new((float)to);
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ string property = axis switch
+ {
+ Axis.X => nameof(FrameworkElement.Width),
+ Axis.Y => nameof(FrameworkElement.Height),
+ _ => ThrowHelper.ThrowArgumentException("Invalid size axis")
+ };
- return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
+ return AddXamlDoubleAnimationFactory(property, from, to, delay, duration, easingType, easingMode, true);
+ }
+ }
+
+ ///
+ /// Adds a new size animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Size(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
}
else
{
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), from?.X, to.X, delay, duration, easingType, easingMode, true);
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), from?.Y, to.Y, delay, duration, easingType, easingMode, true);
return this;
}
}
+ ///
+ /// Adds a new composition size translation animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Size(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
+ }
+
///
/// Starts the animations present in the current instance.
///
From 4fdcae713fba90a4710b244bbb12fb4a9500bdfe Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 14:38:28 +0100
Subject: [PATCH 030/171] Added RotateInDegrees builder API
---
.../AnimationBuilder.cs | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index d6e6e36993e..6de23016d20 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -378,6 +378,41 @@ public AnimationBuilder Rotate(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ double? fromDegrees = from * Math.PI / 180;
+ double toDegrees = to * Math.PI / 180;
+
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), fromDegrees, toDegrees, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new rotation animation in degrees to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder RotateInDegrees(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
{
if (layer == FrameworkLayer.Composition)
{
From df597c475c291bf7bffcd2cf211854010b4a817c Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 16:48:04 +0100
Subject: [PATCH 031/171] Code refactoring
---
.../AnimationBuilder.Default.cs | 526 ++++++++++++++++++
.../AnimationBuilder.cs | 508 -----------------
2 files changed, 526 insertions(+), 508 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs
new file mode 100644
index 00000000000..c2cee2cfb53
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs
@@ -0,0 +1,526 @@
+// 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.
+
+#nullable enable
+
+using System;
+using System.Numerics;
+using Microsoft.Toolkit.Diagnostics;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ public sealed partial class AnimationBuilder
+ {
+ ///
+ /// Adds a new opacity animation to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Opacity(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), from, to, delay, duration, easingType, easingMode, false);
+ }
+ }
+
+ ///
+ /// Adds a new translation animation for a single axis to the current schedule.
+ ///
+ /// The target translation axis to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Translation(
+ Axis axis,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ return AddXamlDoubleAnimationFactory($"Translate{axis}", from, to, delay, duration, easingType, easingMode, false);
+ }
+ }
+
+ ///
+ /// Adds a new translation animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Translation(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionVector2AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new composition translation animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Translation(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new composition offset animation for a single axis to the current schedule.
+ ///
+ /// The target translation axis to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Offset(
+ Axis axis,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new composition offset animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Offset(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new composition offset translation animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Offset(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new uniform scale animation on the X and Y axes to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Scale(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ Vector2? from2 = from is null ? null : new((float)(double)from);
+ Vector2 to2 = new((float)to);
+
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new scale animation on a specified axis to the current schedule.
+ ///
+ /// The target scale axis to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the XAML layer.
+ public AnimationBuilder Scale(
+ Axis axis,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new scale animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Scale(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from?.X, to.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new scale animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Scale(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new rotation animation to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Rotate(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ double? fromDegrees = from * Math.PI / 180;
+ double toDegrees = to * Math.PI / 180;
+
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), fromDegrees, toDegrees, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new rotation animation in degrees to the current schedule.
+ ///
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder RotateInDegrees(
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), from, to, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new clip animation to the current schedule.
+ ///
+ /// The clip size to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Clip(
+ Side side,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ string property = side switch
+ {
+ Side.Top => nameof(InsetClip.TopInset),
+ Side.Bottom => nameof(InsetClip.BottomInset),
+ Side.Right => nameof(InsetClip.RightInset),
+ Side.Left => nameof(InsetClip.LeftInset),
+ _ => ThrowHelper.ThrowArgumentException("Invalid clip size")
+ };
+
+ CompositionClipScalarAnimation animation = new(
+ property,
+ (float?)from,
+ (float)to,
+ delay,
+ duration,
+ easingType,
+ easingMode);
+
+ this.compositionAnimationFactories.Add(animation);
+
+ return this;
+ }
+
+ ///
+ /// Adds a new size animation for a single axis to the current schedule.
+ ///
+ /// The target size axis to animate.
+ /// The optional starting value for the animation.
+ /// The final value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Size(
+ Axis axis,
+ double? from,
+ double to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ string property = axis switch
+ {
+ Axis.X => nameof(FrameworkElement.Width),
+ Axis.Y => nameof(FrameworkElement.Height),
+ _ => ThrowHelper.ThrowArgumentException("Invalid size axis")
+ };
+
+ return AddXamlDoubleAnimationFactory(property, from, to, delay, duration, easingType, easingMode, true);
+ }
+ }
+
+ ///
+ /// Adds a new size animation for the X and Y axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder Size(
+ Vector2? from,
+ Vector2 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionVector2AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), from?.X, to.X, delay, duration, easingType, easingMode, true);
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), from?.Y, to.Y, delay, duration, easingType, easingMode, true);
+
+ return this;
+ }
+ }
+
+ ///
+ /// Adds a new composition size translation animation for all axes to the current schedule.
+ ///
+ /// The optional starting point for the animation.
+ /// The final point for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Size(
+ Vector3? from,
+ Vector3 to,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index 6de23016d20..ac574228674 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -5,13 +5,10 @@
#nullable enable
using System;
-using System.Numerics;
using System.Threading.Tasks;
-using Microsoft.Toolkit.Diagnostics;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
-using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -59,511 +56,6 @@ public AnimationBuilder DoubleAnimation(
return this;
}
- ///
- /// Adds a new opacity animation to the current schedule.
- ///
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Opacity(
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
- else
- {
- return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), from, to, delay, duration, easingType, easingMode, false);
- }
- }
-
- ///
- /// Adds a new translation animation for a single axis to the current schedule.
- ///
- /// The target translation axis to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Translation(
- Axis axis,
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
- else
- {
- return AddXamlDoubleAnimationFactory($"Translate{axis}", from, to, delay, duration, easingType, easingMode, false);
- }
- }
-
- ///
- /// Adds a new translation animation for the X and Y axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Translation(
- Vector2? from,
- Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionVector2AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
- }
- else
- {
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
-
- return this;
- }
- }
-
- ///
- /// Adds a new composition translation animation for all axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Translation(
- Vector3? from,
- Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionVector3AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new composition offset animation for a single axis to the current schedule.
- ///
- /// The target translation axis to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Offset(
- Axis axis,
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new composition offset animation for the X and Y axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Offset(
- Vector2? from,
- Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionVector2AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new composition offset translation animation for all axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Offset(
- Vector3? from,
- Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new uniform scale animation on the X and Y axes to the current schedule.
- ///
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Scale(
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- Vector2? from2 = from is null ? null : new((float)(double)from);
- Vector2 to2 = new((float)to);
-
- return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
- }
- else
- {
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
-
- return this;
- }
- }
-
- ///
- /// Adds a new scale animation on a specified axis to the current schedule.
- ///
- /// The target scale axis to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the XAML layer.
- public AnimationBuilder Scale(
- Axis axis,
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new scale animation for the X and Y axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Scale(
- Vector2? from,
- Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
- }
- else
- {
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from?.X, to.X, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from?.Y, to.Y, delay, duration, easingType, easingMode);
-
- return this;
- }
- }
-
- ///
- /// Adds a new scale animation for all axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Scale(
- Vector3? from,
- Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
- }
-
- ///
- /// Adds a new rotation animation to the current schedule.
- ///
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Rotate(
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
- else
- {
- double? fromDegrees = from * Math.PI / 180;
- double toDegrees = to * Math.PI / 180;
-
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), fromDegrees, toDegrees, delay, duration, easingType, easingMode);
-
- return this;
- }
- }
-
- ///
- /// Adds a new rotation animation in degrees to the current schedule.
- ///
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder RotateInDegrees(
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
- else
- {
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), from, to, delay, duration, easingType, easingMode);
-
- return this;
- }
- }
-
- ///
- /// Adds a new clip animation to the current schedule.
- ///
- /// The clip size to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Clip(
- Side side,
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- string property = side switch
- {
- Side.Top => nameof(InsetClip.TopInset),
- Side.Bottom => nameof(InsetClip.BottomInset),
- Side.Right => nameof(InsetClip.RightInset),
- Side.Left => nameof(InsetClip.LeftInset),
- _ => ThrowHelper.ThrowArgumentException("Invalid clip size")
- };
-
- CompositionClipScalarAnimation animation = new(
- property,
- (float?)from,
- (float)to,
- delay,
- duration,
- easingType,
- easingMode);
-
- this.compositionAnimationFactories.Add(animation);
-
- return this;
- }
-
- ///
- /// Adds a new size animation for a single axis to the current schedule.
- ///
- /// The target size axis to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Size(
- Axis axis,
- double? from,
- double to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
- }
- else
- {
- string property = axis switch
- {
- Axis.X => nameof(FrameworkElement.Width),
- Axis.Y => nameof(FrameworkElement.Height),
- _ => ThrowHelper.ThrowArgumentException("Invalid size axis")
- };
-
- return AddXamlDoubleAnimationFactory(property, from, to, delay, duration, easingType, easingMode, true);
- }
- }
-
- ///
- /// Adds a new size animation for the X and Y axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The target framework layer to animate.
- /// The current instance.
- public AnimationBuilder Size(
- Vector2? from,
- Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode,
- FrameworkLayer layer = FrameworkLayer.Composition)
- {
- if (layer == FrameworkLayer.Composition)
- {
- return AddCompositionVector2AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
- }
- else
- {
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), from?.X, to.X, delay, duration, easingType, easingMode, true);
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), from?.Y, to.Y, delay, duration, easingType, easingMode, true);
-
- return this;
- }
- }
-
- ///
- /// Adds a new composition size translation animation for all axes to the current schedule.
- ///
- /// The optional starting point for the animation.
- /// The final point for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- /// This animation is only available on the composition layer.
- public AnimationBuilder Size(
- Vector3? from,
- Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- return AddCompositionVector3AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
- }
-
///
/// Starts the animations present in the current instance.
///
From 0db9c1399f7daf3d29cf90702f4f88a3835fc635 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 16:57:44 +0100
Subject: [PATCH 032/171] Added AnimationBuilder.New() and XML docs
---
.../AnimationBuilder.cs | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
index ac574228674..b0e7f2a109a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
@@ -5,6 +5,7 @@
#nullable enable
using System;
+using System.Diagnostics.Contracts;
using System.Threading.Tasks;
using Windows.UI.Composition;
using Windows.UI.Xaml;
@@ -19,6 +20,36 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ ///
+ /// A static constructor for the type.
+ /// This can be used as the entry point to construct a custom animation sequence.
+ ///
+ /// For instance:
+ ///
+ /// AnimationBuilder.New()
+ /// .Opacity(from: 0, to: 1, duration: 400)
+ /// .Translation(Axis.X, from: -40, to: 0, duration: 400)
+ /// .Start(MyButton);
+ ///
+ ///
+ /// Configured instances are also reusable, meaning that the same
+ /// one can be used to start an animation sequence on multiple elements as well.
+ ///
+ /// For instance:
+ ///
+ /// var animation = AnimationBuilder.New().Opacity(0, 1, duration: 400).Size(1.2, 1, duration: 400);
+ ///
+ /// animation.Start(MyButton);
+ /// animation.Start(MyGrid);
+ ///
+ /// Alternatively, the type can be used to configure animations directly
+ /// from XAML. The same APIs will still be used behind the scenes to handle animations.
+ ///
+ /// An empty instance to use to construct an animation sequence.
+ [Pure]
+ public static AnimationBuilder New() => new();
+
///
/// Adds a new custom double animation targeting an arbitrary composition object.
///
From a881c9fdf2bac1ba064c7b2d9b8bb0c024426b71 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 17:32:19 +0100
Subject: [PATCH 033/171] Minor code tweaks
---
.../Xaml/AnimationCollection2.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 9bd5fc7badf..695c18ae10c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -49,12 +49,14 @@ public void Start()
///
public Task StartAsync()
{
- if (!ParentReference.TryGetTarget(out UIElement? parent))
+ UIElement? parent = null;
+
+ if (ParentReference?.TryGetTarget(out parent) != true)
{
ThrowHelper.ThrowInvalidOperationException("The current animation collection isn't bound to a parent UIElement instance.");
}
- return StartAsync(parent);
+ return StartAsync(parent!);
}
///
From 867354b0704abc6fd499e72b8d80ff4c11231471 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 18:15:49 +0100
Subject: [PATCH 034/171] Added AnimationScope type, inherited easing type/mode
---
.../Xaml/Abstract/Animation.cs | 5 +--
.../Xaml/AnimationCollection2.cs | 20 ++++------
.../Xaml/AnimationScope.cs | 37 +++++++++++++++++++
.../Xaml/{ => Default}/OpacityAnimation.cs | 14 ++++++-
.../{ => Default}/TranslationAnimation.cs | 14 +++++--
.../Xaml/Interfaces/ITimeline.cs | 10 ++++-
.../Animations/EffectDoubleAnimation.cs | 8 ++--
7 files changed, 84 insertions(+), 24 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationScope.cs
rename Microsoft.Toolkit.Uwp.UI.Animations/Xaml/{ => Default}/OpacityAnimation.cs (50%)
rename Microsoft.Toolkit.Uwp.UI.Animations/Xaml/{ => Default}/TranslationAnimation.cs (55%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
index 01ac07cc3ec..2c572c5e2f9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs
@@ -4,7 +4,6 @@
using System;
using Windows.UI.Xaml.Media.Animation;
-using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
@@ -26,11 +25,11 @@ public abstract class Animation
///
/// Gets or sets the optional easing function type for the animation.
///
- public EasingType EasingType { get; set; } = DefaultEasingType;
+ public EasingType? EasingType { get; set; }
///
/// Gets or sets the optional easing function mode for the animation.
///
- public EasingMode EasingMode { get; set; } = DefaultEasingMode;
+ public EasingMode? EasingMode { get; set; }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 695c18ae10c..7c93b238586 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -18,7 +18,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
/// (such as ) that can be executed on a given element.
///
[ContentProperty(Name = nameof(Animations))]
- public sealed class AnimationCollection2 : DependencyObject, ITimeline
+ public sealed class AnimationCollection2 : DependencyObject
{
///
/// Raised whenever the current animation is started.
@@ -33,7 +33,7 @@ public sealed class AnimationCollection2 : DependencyObject, ITimeline
///
/// Gets or sets the list of animations in the current collection.
///
- public IList Animations { get; set; } = new List();
+ public IList Animations { get; set; } = new List();
///
/// Gets or sets the weak reference to the parent that owns the current animation collection.
@@ -70,20 +70,16 @@ public async Task StartAsync(UIElement element)
{
Started?.Invoke(this, EventArgs.Empty);
- await ((ITimeline)this).AppendToBuilder(new AnimationBuilder()).StartAsync(element);
+ var builder = AnimationBuilder.New();
- Ended?.Invoke(this, EventArgs.Empty);
- }
-
- ///
- AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
- {
- foreach (ITimeline element in Animations)
+ foreach (ITimeline animation in Animations)
{
- builder = element.AppendToBuilder(builder, delayHint, durationHint);
+ builder = animation.AppendToBuilder(builder);
}
- return builder;
+ await builder.StartAsync(element);
+
+ Ended?.Invoke(this, EventArgs.Empty);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationScope.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationScope.cs
new file mode 100644
index 00000000000..31dc2ba0aaf
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationScope.cs
@@ -0,0 +1,37 @@
+// 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.
+
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using Windows.UI.Xaml.Markup;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A container of elements that can be used to conceptually group animations
+ /// together and to assign shared properties to be applied to all the contained items automatically.
+ ///
+ [ContentProperty(Name = nameof(Animations))]
+ public sealed class AnimationScope : Animation, ITimeline
+ {
+ ///
+ /// Gets or sets the list of animations in the current scope.
+ ///
+ public IList Animations { get; set; } = new List();
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ foreach (ITimeline element in Animations)
+ {
+ builder = element.AppendToBuilder(builder, Delay ?? delayHint, Duration ?? durationHint, EasingType ?? easingTypeHint, EasingMode ?? easingModeHint);
+ }
+
+ return builder;
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
similarity index 50%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Xaml/OpacityAnimation.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index 1c00f55bcab..69360dea80b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -3,11 +3,14 @@
// See the LICENSE file in the project root for more information.
using System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A set of animations that can be grouped together.
+ /// This animation maps to .
///
public class OpacityAnimation : TypedAnimation, ITimeline
{
@@ -17,9 +20,16 @@ public class OpacityAnimation : TypedAnimation, ITimeline
public FrameworkLayer Layer { get; set; }
///
- AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
- return builder.Opacity(From, To, Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode, Layer);
+ return builder.Opacity(
+ From,
+ To,
+ Delay ?? delayHint,
+ Duration ?? durationHint.GetValueOrDefault(),
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode,
+ Layer);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
similarity index 55%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 4dc26f8cc9b..996701e2a61 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -4,11 +4,14 @@
using System;
using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A translation animation working on the composition or XAML layer.
+ /// This animation maps to .
///
public class TranslationAnimation : TypedAnimation, ITimeline
{
@@ -18,15 +21,20 @@ public class TranslationAnimation : TypedAnimation, ITimeline
public FrameworkLayer Layer { get; set; }
///
- AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
+ TimeSpan? delay = Delay ?? delayHint;
+ TimeSpan duration = Duration ?? durationHint.GetValueOrDefault();
+ EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
+ EasingMode easingMode = EasingMode ?? easingModeHint ?? DefaultEasingMode;
+
if (Layer == FrameworkLayer.Composition)
{
- return builder.Translation(From?.ToVector3(), To!.ToVector3(), Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode);
+ return builder.Translation(From?.ToVector3(), To!.ToVector3(), delay, duration, easingType, easingMode);
}
else
{
- return builder.Translation(From?.ToVector2(), To!.ToVector2(), Delay ?? delayHint, Duration ?? durationHint.GetValueOrDefault(), EasingType, EasingMode, FrameworkLayer.Xaml);
+ return builder.Translation(From?.ToVector2(), To!.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs
index 23e5c5094de..24d15209d0f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using Windows.UI.Xaml.Media.Animation;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
@@ -17,7 +18,14 @@ public interface ITimeline
/// The target instance to schedule the animation on.
/// A hint for the animation delay, if present.
/// A hint for the animation duration, if present.
+ /// A hint for the easing type, if present.
+ /// A hint for the easing mode, if present.
/// The same instance as .
- AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint = null, TimeSpan? durationHint = null);
+ AnimationBuilder AppendToBuilder(
+ AnimationBuilder builder,
+ TimeSpan? delayHint = null,
+ TimeSpan? durationHint = null,
+ EasingType? easingTypeHint = null,
+ EasingMode? easingModeHint = null);
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index 13655fe87fa..a686e1173b6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -7,6 +7,8 @@
using Microsoft.Toolkit.Uwp.UI.Animations;
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Toolkit.Uwp.UI.Media.Effects;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Media.Animations
{
@@ -18,7 +20,7 @@ public class EffectDoubleAnimation : TypedAnimation, ITimeline
public IPipelineEffect Target { get; set; }
///
- AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint)
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
BlurEffect effect = (BlurEffect)Target;
@@ -29,8 +31,8 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
To,
Delay ?? delayHint,
Duration ?? durationHint.GetValueOrDefault(),
- EasingType,
- EasingMode);
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode);
}
}
}
From 738f2b68e7ceafce45e9929839b55661c404c0f5 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 18:46:01 +0100
Subject: [PATCH 035/171] Added ScaleAnimation type
---
.../Xaml/Default/OpacityAnimation.cs | 2 +-
.../Xaml/Default/ScaleAnimation.cs | 41 +++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index 69360dea80b..9c5b4669840 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
- /// A set of animations that can be grouped together.
+ /// An opacity animation working on the composition or XAML layer.
/// This animation maps to .
///
public class OpacityAnimation : TypedAnimation, ITimeline
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
new file mode 100644
index 00000000000..0e4b2fe41dc
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -0,0 +1,41 @@
+// 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 System;
+using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A scale animation working on the composition or XAML layer.
+ /// This animation maps to .
+ ///
+ public class ScaleAnimation : TypedAnimation, ITimeline
+ {
+ ///
+ /// Gets or sets the target framework layer to animate.
+ ///
+ public FrameworkLayer Layer { get; set; }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ TimeSpan? delay = Delay ?? delayHint;
+ TimeSpan duration = Duration ?? durationHint.GetValueOrDefault();
+ EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
+ EasingMode easingMode = EasingMode ?? easingModeHint ?? DefaultEasingMode;
+
+ if (Layer == FrameworkLayer.Composition)
+ {
+ return builder.Scale(From?.ToVector3(), To!.ToVector3(), delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ return builder.Scale(From?.ToVector2(), To!.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ }
+ }
+ }
+}
From 79a2ae436a9d4ec4cddc449ea4c7a2e52c170d52 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sat, 19 Dec 2020 18:48:56 +0100
Subject: [PATCH 036/171] Fixed AnimationCollection2 exceptions being
unobserved
---
.../Xaml/AnimationCollection2.cs | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index 7c93b238586..fd7841b7f1f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -41,9 +41,14 @@ public sealed class AnimationCollection2 : DependencyObject
internal WeakReference? ParentReference { get; set; }
///
- public void Start()
+ public async void Start()
{
- _ = StartAsync();
+ // Here we're using an async void method on purpose, in order to be able to await
+ // the completion of the animation and rethrow exceptions. We can't just use the
+ // synchronous AnimationBuilder.Start method here, as we also need to await for the
+ // animation to complete in either case in order to raise the Ended event when that
+ // happens. So we add an async state machine here to work around this.
+ await StartAsync();
}
///
@@ -60,9 +65,9 @@ public Task StartAsync()
}
///
- public void Start(UIElement element)
+ public async void Start(UIElement element)
{
- _ = StartAsync(element);
+ await StartAsync(element);
}
///
From 9b2d3f6d7a30f92dcc93d9d7e4a9be697b5ccc87 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 00:12:31 +0100
Subject: [PATCH 037/171] Minor code refactoring
---
.../{ => Builders}/AnimationBuilder.Default.cs | 0
.../{ => Builders}/AnimationBuilder.Models.cs | 0
.../{ => Builders}/AnimationBuilder.Setup.cs | 0
.../{ => Builders}/AnimationBuilder.cs | 0
4 files changed, 0 insertions(+), 0 deletions(-)
rename Microsoft.Toolkit.Uwp.UI.Animations/{ => Builders}/AnimationBuilder.Default.cs (100%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{ => Builders}/AnimationBuilder.Models.cs (100%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{ => Builders}/AnimationBuilder.Setup.cs (100%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{ => Builders}/AnimationBuilder.cs (100%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Default.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Models.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.Setup.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI.Animations/AnimationBuilder.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
From 50b0c218c08598769f5e9d71d068af50687b807d Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 00:13:15 +0100
Subject: [PATCH 038/171] Added NormalizedKeyFrameAnimationBuilder types
---
.../Builders/AnimationBuilder.Models.cs | 6 +-
.../INormalizedKeyFrameAnimationBuilder{T}.cs | 31 ++++
...KeyFrameAnimationBuilder{T}.Composition.cs | 151 ++++++++++++++++++
...malizedKeyFrameAnimationBuilder{T}.Xaml.cs | 101 ++++++++++++
.../NormalizedKeyFrameAnimationBuilder{T}.cs | 122 ++++++++++++++
...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 1 +
6 files changed, 409 insertions(+), 3 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index 0d1e6af48b3..e4cf322ae69 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -155,7 +155,7 @@ public Timeline GetAnimation(UIElement element)
///
/// An interface for factories of XAML animations.
///
- private interface IXamlAnimationFactory
+ internal interface IXamlAnimationFactory
{
///
/// Gets a instance representing the animation to start.
@@ -168,7 +168,7 @@ private interface IXamlAnimationFactory
///
/// An interface for factories of composition animations.
///
- private interface ICompositionAnimationFactory
+ internal interface ICompositionAnimationFactory
{
///
/// Gets a instance representing the animation to start.
@@ -181,7 +181,7 @@ private interface ICompositionAnimationFactory
///
/// An interface for custom external composition animations.
///
- private interface ICompositionAnimation
+ internal interface ICompositionAnimation
{
///
/// Starts a with some embedded parameters.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
new file mode 100644
index 00000000000..39ec594fa92
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
@@ -0,0 +1,31 @@
+// 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.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// An interface for an animation builder using normalized keyframes.
+ ///
+ /// The type of values being set by the animation being constructed.
+ public interface INormalizedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// Adds a new normalized keyframe to the builder in use.
+ ///
+ /// The normalized progress for the keyframe (must be in the [0, 1] range).
+ /// The value for the new keyframe to add.
+ /// The easing type to use to reach the new keyframe.
+ /// The easing mode to use to reach the new keyframe.
+ /// The same instance that the method was invoked upon.
+ public INormalizedKeyFrameAnimationBuilder KeyFrame(
+ double progress,
+ T value,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode);
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
new file mode 100644
index 00000000000..bcaa4163831
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -0,0 +1,151 @@
+// 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 System;
+using System.Numerics;
+using Microsoft.Toolkit.Diagnostics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
+using Windows.UI;
+using Windows.UI.Composition;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ internal abstract partial class NormalizedKeyFrameAnimationBuilder
+ {
+ ///
+ /// A custom class targeting the composition layer.
+ ///
+ public sealed class Composition : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Composition(string property, TimeSpan? delay, TimeSpan? duration)
+ : base(property, delay, duration)
+ {
+ }
+
+ ///
+ public unsafe CompositionAnimation GetAnimation(Visual visual)
+ {
+ KeyFrameAnimation animation;
+
+ if (typeof(T) == typeof(bool))
+ {
+ BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ boolAnimation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(bool*)&keyFrame.Value);
+ }
+
+ animation = boolAnimation;
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ scalarAnimation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(float*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = scalarAnimation;
+ }
+ else if (typeof(T) == typeof(Vector2))
+ {
+ Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector2Animation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(Vector2*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector2Animation;
+ }
+ else if (typeof(T) == typeof(Vector3))
+ {
+ Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector3Animation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(Vector3*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector3Animation;
+ }
+ else if (typeof(T) == typeof(Vector4))
+ {
+ Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector4Animation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(Vector4*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector4Animation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ colorAnimation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(Color*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = colorAnimation;
+ }
+ else if (typeof(T) == typeof(Quaternion))
+ {
+ QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ quaternionAnimation.InsertKeyFrame(
+ (float)keyFrame.Progress,
+ *(Quaternion*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = quaternionAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.Duration = this.duration.GetValueOrDefault();
+
+ if (this.delay.HasValue)
+ {
+ animation.DelayTime = this.delay!.Value;
+ }
+
+ animation.Target = this.property;
+
+ return animation;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
new file mode 100644
index 00000000000..6198dc543af
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -0,0 +1,101 @@
+// 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 System;
+using Microsoft.Toolkit.Diagnostics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
+using Windows.Foundation;
+using Windows.UI;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormalizedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// A custom class targeting the XAML layer.
+ ///
+ public sealed class Xaml : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Xaml(string property, TimeSpan? delay, TimeSpan? duration)
+ : base(property, delay, duration)
+ {
+ }
+
+ ///
+ public unsafe Timeline GetAnimation(UIElement element)
+ {
+ Timeline animation;
+
+ if (typeof(T) == typeof(double))
+ {
+ DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
+ {
+ KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ Value = *(double*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = doubleAnimation;
+ }
+ else if (typeof(T) == typeof(Point))
+ {
+ PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
+ {
+ KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ Value = *(Point*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = pointAnimation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorAnimationUsingKeyFrames colorAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
+ {
+ KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ Value = *(Color*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = colorAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.BeginTime = this.delay;
+ animation.Duration = this.duration.GetValueOrDefault();
+
+ Storyboard.SetTarget(animation, element);
+ Storyboard.SetTargetProperty(animation, this.property);
+
+ return animation;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
new file mode 100644
index 00000000000..fb2b98f43c3
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -0,0 +1,122 @@
+// 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 System;
+using System.Collections.Generic;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// A generic keyframe animation builder.
+ ///
+ /// The type of values being set by the animation being constructed.
+ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormalizedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// The target property to animate.
+ ///
+ private readonly string property;
+
+ ///
+ /// The target delay for the animation, if any.
+ ///
+ private readonly TimeSpan? delay;
+
+ ///
+ /// The target duration for the animation.
+ ///
+ private readonly TimeSpan? duration;
+
+ ///
+ /// The list of keyframes to use.
+ ///
+ private readonly List keyFrames = new();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The target property to animate.
+ /// The target delay for the animation, if any.
+ /// The target duration for the animation.
+ protected NormalizedKeyFrameAnimationBuilder(string property, TimeSpan? delay, TimeSpan? duration)
+ {
+ this.property = property;
+ this.delay = delay;
+ this.duration = duration;
+ }
+
+ ///
+ public INormalizedKeyFrameAnimationBuilder KeyFrame(
+ double progress,
+ T value,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ this.keyFrames.Add(new(progress, value, easingType, easingMode));
+
+ return this;
+ }
+
+ ///
+ /// The abstracted info for a normalized animation keyframe.
+ ///
+ protected readonly struct KeyFrameInfo
+ {
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The normalized progress for the keyframe.
+ /// The value for the new keyframe to add.
+ /// The easing type to use to reach the new keyframe.
+ /// The easing mode to use to reach the new keyframe.
+ public KeyFrameInfo(
+ double progress,
+ T value,
+ EasingType easingType,
+ EasingMode easingMode)
+ {
+ Progress = progress;
+ Value = value;
+ EasingType = easingType;
+ EasingMode = easingMode;
+ }
+
+ ///
+ /// The normalized progress for the keyframe.
+ ///
+ public readonly double Progress;
+
+ ///
+ /// The value for the new keyframe to add.
+ ///
+ public readonly T Value;
+
+ ///
+ /// The easing type to use to reach the new keyframe.
+ ///
+ public readonly EasingType EasingType;
+
+ ///
+ /// The easing mode to use to reach the new keyframe.
+ ///
+ public readonly EasingMode EasingMode;
+
+ ///
+ /// Gets a for the current instance, relative to a value.
+ ///
+ /// The target value to use.
+ /// A normalized value relative to .
+ public KeyTime GetKeyTime(TimeSpan duration)
+ {
+ long ticks = duration.Ticks;
+ TimeSpan step = TimeSpan.FromTicks((long)(ticks * Progress));
+
+ return KeyTime.FromTimeSpan(step);
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
index e49f7af1cd7..f385ff525c9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
@@ -16,6 +16,7 @@
UWP Toolkit Windows Animations Composition Connected Implicit XAML9.0
+ true
From 87ce48358150df70a3401b64bc931d42e53d1676 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 00:44:30 +0100
Subject: [PATCH 039/171] Added AnimationBuilder.NormalizedKeyFrames
---
.../Builders/AnimationBuilder.Custom.cs | 53 +++++++++++++++++++
...KeyFrameAnimationBuilder{T}.Composition.cs | 4 +-
...malizedKeyFrameAnimationBuilder{T}.Xaml.cs | 10 ++--
.../NormalizedKeyFrameAnimationBuilder{T}.cs | 6 +--
.../Extensions/AnimationExtensions.cs | 6 +++
5 files changed, 69 insertions(+), 10 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
new file mode 100644
index 00000000000..e73ff159d47
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
@@ -0,0 +1,53 @@
+// 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.
+
+#nullable enable
+
+using System;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ public sealed partial class AnimationBuilder
+ {
+ ///
+ /// Adds a custom animation based on normalized keyframes ot the current schedule.
+ ///
+ /// The type of values to animate.
+ /// The target property to animate.
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder NormalizedKeyFrames(
+ string property,
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ where T : unmanaged
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ NormalizedKeyFrameAnimationBuilder.Composition builder = new(property, delay, duration ?? DefaultDuration);
+
+ build(builder);
+
+ this.compositionAnimationFactories.Add(builder);
+ }
+ else
+ {
+ NormalizedKeyFrameAnimationBuilder.Xaml builder = new(property, delay, duration ?? DefaultDuration);
+
+ build(builder);
+
+ this.xamlAnimationFactories.Add(builder);
+ }
+
+ return this;
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index bcaa4163831..968e5999126 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -23,7 +23,7 @@ public sealed class Composition : NormalizedKeyFrameAnimationBuilder, Animati
/// Initializes a new instance of the class.
///
///
- public Composition(string property, TimeSpan? delay, TimeSpan? duration)
+ public Composition(string property, TimeSpan? delay, TimeSpan duration)
: base(property, delay, duration)
{
}
@@ -135,7 +135,7 @@ public unsafe CompositionAnimation GetAnimation(Visual visual)
return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
}
- animation.Duration = this.duration.GetValueOrDefault();
+ animation.Duration = this.duration;
if (this.delay.HasValue)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
index 6198dc543af..cfa3a3b609e 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -25,7 +25,7 @@ public sealed class Xaml : NormalizedKeyFrameAnimationBuilder, AnimationBuild
/// Initializes a new instance of the class.
///
///
- public Xaml(string property, TimeSpan? delay, TimeSpan? duration)
+ public Xaml(string property, TimeSpan? delay, TimeSpan duration)
: base(property, delay, duration)
{
}
@@ -43,7 +43,7 @@ public unsafe Timeline GetAnimation(UIElement element)
{
doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
{
- KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ KeyTime = keyFrame.GetKeyTime(this.duration),
Value = *(double*)&keyFrame.Value,
EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
});
@@ -59,7 +59,7 @@ public unsafe Timeline GetAnimation(UIElement element)
{
pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
{
- KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ KeyTime = keyFrame.GetKeyTime(this.duration),
Value = *(Point*)&keyFrame.Value,
EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
});
@@ -75,7 +75,7 @@ public unsafe Timeline GetAnimation(UIElement element)
{
colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
{
- KeyTime = keyFrame.GetKeyTime(this.duration.GetValueOrDefault()),
+ KeyTime = keyFrame.GetKeyTime(this.duration),
Value = *(Color*)&keyFrame.Value,
EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
});
@@ -89,7 +89,7 @@ public unsafe Timeline GetAnimation(UIElement element)
}
animation.BeginTime = this.delay;
- animation.Duration = this.duration.GetValueOrDefault();
+ animation.Duration = this.duration;
Storyboard.SetTarget(animation, element);
Storyboard.SetTargetProperty(animation, this.property);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
index fb2b98f43c3..14245e8e8c5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -29,7 +29,7 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormali
///
/// The target duration for the animation.
///
- private readonly TimeSpan? duration;
+ private readonly TimeSpan duration;
///
/// The list of keyframes to use.
@@ -40,9 +40,9 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormali
/// Initializes a new instance of the class.
///
/// The target property to animate.
- /// The target delay for the animation, if any.
+ /// The target delay for the animation.
/// The target duration for the animation.
- protected NormalizedKeyFrameAnimationBuilder(string property, TimeSpan? delay, TimeSpan? duration)
+ protected NormalizedKeyFrameAnimationBuilder(string property, TimeSpan? delay, TimeSpan duration)
{
this.property = property;
this.delay = delay;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
index 6ce859556d2..8195d4893dc 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using System.Collections.Generic;
using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
@@ -13,6 +14,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
///
public static partial class AnimationExtensions
{
+ ///
+ /// Gets the default duration of animations.
+ ///
+ public static TimeSpan DefaultDuration => TimeSpan.FromMilliseconds(400);
+
///
/// The default value used for animations.
///
From 80164f1a4087f15e4959e2c3082df1ae8477c484 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 16:08:26 +0100
Subject: [PATCH 040/171] Added AnimationBuilder.TimedKeyFrames
---
.../Builders/AnimationBuilder.Custom.cs | 36 ++++
.../ITimedKeyFrameAnimationBuilder{T}.cs | 32 ++++
...KeyFrameAnimationBuilder{T}.Composition.cs | 156 ++++++++++++++++++
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 100 +++++++++++
.../TimedKeyFrameAnimationBuilder{T}.cs | 112 +++++++++++++
5 files changed, 436 insertions(+)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
index e73ff159d47..4456a8575a4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
@@ -49,5 +49,41 @@ public AnimationBuilder NormalizedKeyFrames(
return this;
}
+
+ ///
+ /// Adds a custom animation based on timed keyframes ot the current schedule.
+ ///
+ /// The type of values to animate.
+ /// The target property to animate.
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder TimedKeyFrames(
+ string property,
+ Action> build,
+ TimeSpan? delay = null,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ where T : unmanaged
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay);
+
+ build(builder);
+
+ this.compositionAnimationFactories.Add(builder);
+ }
+ else
+ {
+ TimedKeyFrameAnimationBuilder.Xaml builder = new(property, delay);
+
+ build(builder);
+
+ this.xamlAnimationFactories.Add(builder);
+ }
+
+ return this;
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
new file mode 100644
index 00000000000..e9db4ad89f4
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
@@ -0,0 +1,32 @@
+// 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 System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// An interface for an animation builder using timed keyframes.
+ ///
+ /// The type of values being set by the animation being constructed.
+ public interface ITimedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// Adds a new timed keyframe to the builder in use.
+ ///
+ /// The timed progress for the keyframe, relative to the start of the animation.
+ /// The value for the new keyframe to add.
+ /// The easing type to use to reach the new keyframe.
+ /// The easing mode to use to reach the new keyframe.
+ /// The same instance that the method was invoked upon.
+ public ITimedKeyFrameAnimationBuilder KeyFrame(
+ TimeSpan progress,
+ T value,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode);
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
new file mode 100644
index 00000000000..6676ab7fa16
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -0,0 +1,156 @@
+// 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 System;
+using System.Numerics;
+using Microsoft.Toolkit.Diagnostics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
+using Windows.UI;
+using Windows.UI.Composition;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// A custom class targeting the composition layer.
+ ///
+ public class Composition : TimedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Composition(string property, TimeSpan? delay)
+ : base(property, delay)
+ {
+ }
+
+ ///
+ public unsafe CompositionAnimation GetAnimation(Visual visual)
+ {
+ KeyFrameAnimation animation;
+
+ // 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.
+ TimeSpan duration = this.keyFrames[this.keyFrames.Count - 1].Progress;
+
+ if (typeof(T) == typeof(bool))
+ {
+ BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ boolAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(bool*)&keyFrame.Value);
+ }
+
+ animation = boolAnimation;
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ scalarAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(float*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = scalarAnimation;
+ }
+ else if (typeof(T) == typeof(Vector2))
+ {
+ Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector2Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(Vector2*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector2Animation;
+ }
+ else if (typeof(T) == typeof(Vector3))
+ {
+ Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector3Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(Vector3*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector3Animation;
+ }
+ else if (typeof(T) == typeof(Vector4))
+ {
+ Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ vector4Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(Vector4*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = vector4Animation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ colorAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(Color*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = colorAnimation;
+ }
+ else if (typeof(T) == typeof(Quaternion))
+ {
+ QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ quaternionAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ *(Quaternion*)&keyFrame.Value,
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = quaternionAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.Duration = duration;
+
+ if (this.delay.HasValue)
+ {
+ animation.DelayTime = this.delay!.Value;
+ }
+
+ animation.Target = this.property;
+
+ return animation;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
new file mode 100644
index 00000000000..69ecaeb9cc2
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -0,0 +1,100 @@
+// 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 System;
+using Microsoft.Toolkit.Diagnostics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
+using Windows.Foundation;
+using Windows.UI;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// A custom class targeting the XAML layer.
+ ///
+ public class Xaml : TimedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Xaml(string property, TimeSpan? delay)
+ : base(property, delay)
+ {
+ }
+
+ ///
+ public virtual unsafe Timeline GetAnimation(UIElement element)
+ {
+ Timeline animation;
+
+ if (typeof(T) == typeof(double))
+ {
+ DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
+ {
+ KeyTime = keyFrame.Progress,
+ Value = *(double*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = doubleAnimation;
+ }
+ else if (typeof(T) == typeof(Point))
+ {
+ PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
+ {
+ KeyTime = keyFrame.Progress,
+ Value = *(Point*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = pointAnimation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorAnimationUsingKeyFrames colorAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in this.keyFrames)
+ {
+ colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
+ {
+ KeyTime = keyFrame.Progress,
+ Value = *(Color*)&keyFrame.Value,
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = colorAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.BeginTime = this.delay;
+
+ Storyboard.SetTarget(animation, element);
+ Storyboard.SetTargetProperty(animation, this.property);
+
+ return animation;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
new file mode 100644
index 00000000000..5ca3f536a3a
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
@@ -0,0 +1,112 @@
+// 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 System;
+using System.Collections.Generic;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// A generic keyframe animation builder.
+ ///
+ /// The type of values being set by the animation being constructed.
+ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFrameAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// The target property to animate.
+ ///
+ private readonly string property;
+
+ ///
+ /// The target delay for the animation, if any.
+ ///
+ private readonly TimeSpan? delay;
+
+ ///
+ /// The list of keyframes to use.
+ ///
+ private readonly List keyFrames = new();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The target property to animate.
+ /// The target delay for the animation.
+ protected TimedKeyFrameAnimationBuilder(string property, TimeSpan? delay)
+ {
+ this.property = property;
+ this.delay = delay;
+ }
+
+ ///
+ public ITimedKeyFrameAnimationBuilder KeyFrame(
+ TimeSpan progress,
+ T value,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ this.keyFrames.Add(new(progress, value, easingType, easingMode));
+
+ return this;
+ }
+
+ ///
+ /// The abstracted info for a timed animation keyframe.
+ ///
+ protected readonly struct KeyFrameInfo
+ {
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The progress for the keyframe.
+ /// The value for the new keyframe to add.
+ /// The easing type to use to reach the new keyframe.
+ /// The easing mode to use to reach the new keyframe.
+ public KeyFrameInfo(
+ TimeSpan progress,
+ T value,
+ EasingType easingType,
+ EasingMode easingMode)
+ {
+ Progress = progress;
+ Value = value;
+ EasingType = easingType;
+ EasingMode = easingMode;
+ }
+
+ ///
+ /// The progress for the keyframe.
+ ///
+ public readonly TimeSpan Progress;
+
+ ///
+ /// The value for the new keyframe to add.
+ ///
+ public readonly T Value;
+
+ ///
+ /// The easing type to use to reach the new keyframe.
+ ///
+ public readonly EasingType EasingType;
+
+ ///
+ /// The easing mode to use to reach the new keyframe.
+ ///
+ public readonly EasingMode EasingMode;
+
+ ///
+ /// Gets a normalized duration for the current instance, relative to a value.
+ ///
+ /// The target value to use.
+ /// A normalized value relative to .
+ public double GetNormalizedProgress(TimeSpan duration)
+ {
+ return Math.Clamp(Progress.TotalMilliseconds * 100 / duration.TotalMilliseconds, 0, 1);
+ }
+ }
+ }
+}
From 57a8456e5bb15ef9c5ec0fe96de0105c8fac09d4 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 16:11:54 +0100
Subject: [PATCH 041/171] Suppressed XML docs warning
Not sure why the cref was being marked as ambiguous, since it was still resolved properly. Using a pragma disable for now as a workaround, the functionality is still working correctly from IntelliSense anyway.
---
.../Builders/NormalizedKeyFrameAnimationBuilder{T}.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
index 14245e8e8c5..45e9cb2365a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -7,6 +7,8 @@
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+#pragma warning disable CS0419
+
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
From 9a301794b6272ab6c31f43fa280fe5f41f70784d Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 16:21:43 +0100
Subject: [PATCH 042/171] Added ITimedKeyFrameAnimationBuilderExtensions
---
...TimedKeyFrameAnimationBuilderExtensions.cs | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/ITimedKeyFrameAnimationBuilderExtensions.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/ITimedKeyFrameAnimationBuilderExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/ITimedKeyFrameAnimationBuilderExtensions.cs
new file mode 100644
index 00000000000..fb342988aef
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/ITimedKeyFrameAnimationBuilderExtensions.cs
@@ -0,0 +1,39 @@
+// 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.
+
+#nullable enable
+
+using System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
+{
+ ///
+ /// An extension for the type.
+ ///
+ public static class ITimedKeyFrameAnimationBuilderExtensions
+ {
+ ///
+ /// Adds a new timed keyframe to the builder in use.
+ ///
+ /// The type of values being set by the animation being constructed.
+ /// The target instance in use.
+ /// The timed progress for the keyframe (in milliseconds), relative to the start of the animation.
+ /// The value for the new keyframe to add.
+ /// The easing type to use to reach the new keyframe.
+ /// The easing mode to use to reach the new keyframe.
+ /// The same instance that the method was invoked upon.
+ public static ITimedKeyFrameAnimationBuilder KeyFrame(
+ this ITimedKeyFrameAnimationBuilder builder,
+ int progress,
+ T value,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ where T : unmanaged
+ {
+ return builder.KeyFrame(TimeSpan.FromMilliseconds(progress), value, easingType, easingMode);
+ }
+ }
+}
From 2c2b96a02865a03d9b465364a361e4ab3dc64279 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 16:50:12 +0100
Subject: [PATCH 043/171] Fixed StyleCop warnings
---
.../Animations/EffectDoubleAnimation.cs | 7 ++--
.../Effects/BlurEffect.cs | 35 +++++++++++--------
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index a686e1173b6..88c2083b992 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -17,6 +17,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Animations
///
public class EffectDoubleAnimation : TypedAnimation, ITimeline
{
+ ///
+ /// Gets or sets the linked instance to animate.
+ ///
public IPipelineEffect Target { get; set; }
///
@@ -25,8 +28,8 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
BlurEffect effect = (BlurEffect)Target;
return builder.DoubleAnimation(
- effect.brush,
- $"{effect.id}.{nameof(GaussianBlurEffect.BlurAmount)}",
+ effect.Brush,
+ $"{effect.Id}.{nameof(GaussianBlurEffect.BlurAmount)}",
From,
To,
Delay ?? delayHint,
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
index 7b864291d47..9c6714df5ba 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
@@ -14,16 +14,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class BlurEffect : IPipelineEffect
{
- ///
- /// The unique id for the effect, if is set.
- ///
- internal string id;
-
- ///
- /// The in use, if any.
- ///
- internal CompositionBrush brush;
-
///
/// Gets or sets a value indicating whether the effect can be animated.
///
@@ -40,20 +30,35 @@ public double Amount
set => this.amount = Math.Max(value, 0);
}
+ ///
+ /// Gets the unique id for the effect, if is set.
+ ///
+ internal string Id { get; private set; }
+
+ ///
+ /// Gets in use, if any.
+ ///
+ internal CompositionBrush Brush { get; private set; }
+
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
{
- return IsAnimatable switch
+ if (IsAnimatable)
{
- true => builder.Blur((float)Amount, out this.id),
- false => builder.Blur((float)Amount)
- };
+ builder = builder.Blur((float)Amount, out string id);
+
+ Id = id;
+
+ return builder;
+ }
+
+ return builder.Blur((float)Amount);
}
///
void IPipelineEffect.NotifyCompositionBrushInUse(CompositionBrush brush)
{
- this.brush = brush;
+ Brush = brush;
}
}
}
From 916915f80b704b0befcc46ab19ef001c6ffa040f Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 17:48:44 +0100
Subject: [PATCH 044/171] Code refactoring to keyframe animation builders
---
.../Builders/Interfaces/IKeyFrameInfo.cs | 51 ++++
...KeyFrameAnimationBuilder{T}.Composition.cs | 227 ++++++++++--------
...malizedKeyFrameAnimationBuilder{T}.Xaml.cs | 74 +-----
.../NormalizedKeyFrameAnimationBuilder{T}.cs | 67 +++---
...KeyFrameAnimationBuilder{T}.Composition.cs | 132 +---------
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 145 ++++++-----
.../TimedKeyFrameAnimationBuilder{T}.cs | 62 +++--
...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 1 -
8 files changed, 353 insertions(+), 406 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
new file mode 100644
index 00000000000..63764ea2299
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
@@ -0,0 +1,51 @@
+// 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 System;
+using System.Diagnostics.Contracts;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// An interface representing a generic model containing info for an abstract keyframe.
+ ///
+ internal interface IKeyFrameInfo
+ {
+ ///
+ /// Gets the easing type to use to reach the new keyframe.
+ ///
+ EasingType EasingType { get; }
+
+ ///
+ /// Gets the easing mode to use to reach the new keyframe.
+ ///
+ EasingMode EasingMode { get; }
+
+ ///
+ /// Gets the value for the new keyframe to add.
+ ///
+ /// The type of values being set by the animation being constructed.
+ /// The value for the current keyframe.
+ [Pure]
+ T GetValueAs()
+ where T : unmanaged;
+
+ ///
+ /// Gets the normalized progress for the current keyframe.
+ ///
+ /// The total duration for the full animation.
+ /// The normalized progress for the current keyframe.
+ [Pure]
+ double GetNormalizedProgress(TimeSpan duration);
+
+ ///
+ /// Gets the timed progress for the current keyframe.
+ ///
+ /// The total duration for the full animation.
+ /// The timed progress for the current keyframe.
+ [Pure]
+ TimeSpan GetTimedProgress(TimeSpan duration);
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index 968e5999126..68fb3e8ef32 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections.Generic;
using System.Numerics;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
@@ -15,136 +16,162 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
internal abstract partial class NormalizedKeyFrameAnimationBuilder
{
///
- /// A custom class targeting the composition layer.
+ /// Gets a instance representing the animation to start.
///
- public sealed class Composition : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
+ /// The type of keyframes being used to define the animation.
+ /// The target instance to animate.
+ /// The target property to animate.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The list of keyframes to use to build the animation.
+ /// A instance with the specified animation.
+ public static CompositionAnimation GetAnimation(
+ Visual visual,
+ string property,
+ TimeSpan? delay,
+ TimeSpan duration,
+ List keyFrames)
+ where TKeyFrame : struct, IKeyFrameInfo
{
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- public Composition(string property, TimeSpan? delay, TimeSpan duration)
- : base(property, delay, duration)
- {
- }
+ KeyFrameAnimation animation;
- ///
- public unsafe CompositionAnimation GetAnimation(Visual visual)
+ if (typeof(T) == typeof(bool))
{
- KeyFrameAnimation animation;
+ BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
- if (typeof(T) == typeof(bool))
+ foreach (var keyFrame in keyFrames)
{
- BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- boolAnimation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(bool*)&keyFrame.Value);
- }
-
- animation = boolAnimation;
+ boolAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs());
}
- else if (typeof(T) == typeof(float))
- {
- ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
- foreach (var keyFrame in this.keyFrames)
- {
- scalarAnimation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(float*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
+ animation = boolAnimation;
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
- animation = scalarAnimation;
- }
- else if (typeof(T) == typeof(Vector2))
+ foreach (var keyFrame in keyFrames)
{
- Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- vector2Animation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(Vector2*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = vector2Animation;
+ scalarAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
- else if (typeof(T) == typeof(Vector3))
- {
- Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
- foreach (var keyFrame in this.keyFrames)
- {
- vector3Animation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(Vector3*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
+ animation = scalarAnimation;
+ }
+ else if (typeof(T) == typeof(Vector2))
+ {
+ Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
- animation = vector3Animation;
- }
- else if (typeof(T) == typeof(Vector4))
+ foreach (var keyFrame in keyFrames)
{
- Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
+ vector2Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
- foreach (var keyFrame in this.keyFrames)
- {
- vector4Animation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(Vector4*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
+ animation = vector2Animation;
+ }
+ else if (typeof(T) == typeof(Vector3))
+ {
+ Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
- animation = vector4Animation;
- }
- else if (typeof(T) == typeof(Color))
+ foreach (var keyFrame in keyFrames)
{
- ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
+ vector3Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
- foreach (var keyFrame in this.keyFrames)
- {
- colorAnimation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(Color*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
+ animation = vector3Animation;
+ }
+ else if (typeof(T) == typeof(Vector4))
+ {
+ Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
- animation = colorAnimation;
- }
- else if (typeof(T) == typeof(Quaternion))
+ foreach (var keyFrame in keyFrames)
{
- QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
+ vector4Animation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
- foreach (var keyFrame in this.keyFrames)
- {
- quaternionAnimation.InsertKeyFrame(
- (float)keyFrame.Progress,
- *(Quaternion*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
+ animation = vector4Animation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
- animation = quaternionAnimation;
- }
- else
+ foreach (var keyFrame in keyFrames)
{
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ colorAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
- animation.Duration = this.duration;
+ animation = colorAnimation;
+ }
+ else if (typeof(T) == typeof(Quaternion))
+ {
+ QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
- if (this.delay.HasValue)
+ foreach (var keyFrame in keyFrames)
{
- animation.DelayTime = this.delay!.Value;
+ quaternionAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
- animation.Target = this.property;
+ animation = quaternionAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.Duration = duration;
+
+ if (delay.HasValue)
+ {
+ animation.DelayTime = delay!.Value;
+ }
+
+ animation.Target = property;
+
+ return animation;
+ }
- return animation;
+ ///
+ /// A custom class targeting the composition layer.
+ ///
+ public sealed class Composition : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Composition(string property, TimeSpan? delay, TimeSpan duration)
+ : base(property, delay, duration)
+ {
+ }
+
+ ///
+ public CompositionAnimation GetAnimation(Visual visual)
+ {
+ return GetAnimation(
+ visual,
+ this.property,
+ this.delay,
+ this.duration,
+ this.keyFrames);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
index cfa3a3b609e..e4ca796c97b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -3,10 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Toolkit.Diagnostics;
-using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
-using Windows.Foundation;
-using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;
@@ -31,70 +27,14 @@ public Xaml(string property, TimeSpan? delay, TimeSpan duration)
}
///
- public unsafe Timeline GetAnimation(UIElement element)
+ public Timeline GetAnimation(UIElement element)
{
- Timeline animation;
-
- if (typeof(T) == typeof(double))
- {
- DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in this.keyFrames)
- {
- doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
- {
- KeyTime = keyFrame.GetKeyTime(this.duration),
- Value = *(double*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = doubleAnimation;
- }
- else if (typeof(T) == typeof(Point))
- {
- PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in this.keyFrames)
- {
- pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
- {
- KeyTime = keyFrame.GetKeyTime(this.duration),
- Value = *(Point*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = pointAnimation;
- }
- else if (typeof(T) == typeof(Color))
- {
- ColorAnimationUsingKeyFrames colorAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in this.keyFrames)
- {
- colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
- {
- KeyTime = keyFrame.GetKeyTime(this.duration),
- Value = *(Color*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = colorAnimation;
- }
- else
- {
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
- }
-
- animation.BeginTime = this.delay;
- animation.Duration = this.duration;
-
- Storyboard.SetTarget(animation, element);
- Storyboard.SetTargetProperty(animation, this.property);
-
- return animation;
+ return TimedKeyFrameAnimationBuilder.GetAnimation(
+ element,
+ this.property,
+ this.delay,
+ this.duration,
+ this.keyFrames);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
index 45e9cb2365a..85e2d11cb0c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -4,11 +4,10 @@
using System;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
-#pragma warning disable CS0419
-
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
@@ -66,8 +65,18 @@ public INormalizedKeyFrameAnimationBuilder KeyFrame(
///
/// The abstracted info for a normalized animation keyframe.
///
- protected readonly struct KeyFrameInfo
+ protected readonly struct KeyFrameInfo : IKeyFrameInfo
{
+ ///
+ /// The normalized progress for the keyframe.
+ ///
+ private readonly double progress;
+
+ ///
+ /// The value for the current keyframe.
+ ///
+ private readonly T value;
+
///
/// Initializes a new instance of the struct.
///
@@ -81,43 +90,39 @@ public KeyFrameInfo(
EasingType easingType,
EasingMode easingMode)
{
- Progress = progress;
- Value = value;
+ this.progress = progress;
+ this.value = value;
+
EasingType = easingType;
EasingMode = easingMode;
}
- ///
- /// The normalized progress for the keyframe.
- ///
- public readonly double Progress;
+ ///
+ public EasingType EasingType { get; }
- ///
- /// The value for the new keyframe to add.
- ///
- public readonly T Value;
-
- ///
- /// The easing type to use to reach the new keyframe.
- ///
- public readonly EasingType EasingType;
+ ///
+ public EasingMode EasingMode { get; }
- ///
- /// The easing mode to use to reach the new keyframe.
- ///
- public readonly EasingMode EasingMode;
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public TValue GetValueAs()
+ where TValue : unmanaged
+ {
+ return Unsafe.As(ref Unsafe.AsRef(in this.value));
+ }
- ///
- /// Gets a for the current instance, relative to a value.
- ///
- /// The target value to use.
- /// A normalized value relative to .
- public KeyTime GetKeyTime(TimeSpan duration)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public double GetNormalizedProgress(TimeSpan duration)
{
- long ticks = duration.Ticks;
- TimeSpan step = TimeSpan.FromTicks((long)(ticks * Progress));
+ return this.progress;
+ }
- return KeyTime.FromTimeSpan(step);
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public TimeSpan GetTimedProgress(TimeSpan duration)
+ {
+ return TimeSpan.FromMilliseconds(duration.TotalMilliseconds * this.progress);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
index 6676ab7fa16..6c01782e47f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -3,10 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Numerics;
-using Microsoft.Toolkit.Diagnostics;
-using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
-using Windows.UI;
using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Animations
@@ -18,7 +14,7 @@ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFram
///
/// A custom class targeting the composition layer.
///
- public class Composition : TimedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
+ public sealed class Composition : TimedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
{
///
/// Initializes a new instance of the class.
@@ -30,126 +26,18 @@ public Composition(string property, TimeSpan? delay)
}
///
- public unsafe CompositionAnimation GetAnimation(Visual visual)
+ public CompositionAnimation GetAnimation(Visual visual)
{
- KeyFrameAnimation animation;
-
// 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.
- TimeSpan duration = this.keyFrames[this.keyFrames.Count - 1].Progress;
-
- if (typeof(T) == typeof(bool))
- {
- BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- boolAnimation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(bool*)&keyFrame.Value);
- }
-
- animation = boolAnimation;
- }
- else if (typeof(T) == typeof(float))
- {
- ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- scalarAnimation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(float*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = scalarAnimation;
- }
- else if (typeof(T) == typeof(Vector2))
- {
- Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- vector2Animation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(Vector2*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = vector2Animation;
- }
- else if (typeof(T) == typeof(Vector3))
- {
- Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- vector3Animation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(Vector3*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = vector3Animation;
- }
- else if (typeof(T) == typeof(Vector4))
- {
- Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- vector4Animation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(Vector4*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = vector4Animation;
- }
- else if (typeof(T) == typeof(Color))
- {
- ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- colorAnimation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(Color*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = colorAnimation;
- }
- else if (typeof(T) == typeof(Quaternion))
- {
- QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
-
- foreach (var keyFrame in this.keyFrames)
- {
- quaternionAnimation.InsertKeyFrame(
- (float)keyFrame.GetNormalizedProgress(duration),
- *(Quaternion*)&keyFrame.Value,
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
- }
-
- animation = quaternionAnimation;
- }
- else
- {
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
- }
-
- animation.Duration = duration;
-
- if (this.delay.HasValue)
- {
- animation.DelayTime = this.delay!.Value;
- }
-
- animation.Target = this.property;
-
- return animation;
+ TimeSpan duration = this.keyFrames[this.keyFrames.Count - 1].GetTimedProgress(default);
+
+ return NormalizedKeyFrameAnimationBuilder.GetAnimation(
+ visual,
+ this.property,
+ this.delay,
+ duration,
+ this.keyFrames);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 69ecaeb9cc2..15b37bfe0ad 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections.Generic;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
using Windows.Foundation;
@@ -17,83 +18,109 @@ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFram
where T : unmanaged
{
///
- /// A custom class targeting the XAML layer.
+ /// Gets a instance representing the animation to start.
///
- public class Xaml : TimedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
+ /// The type of keyframes being used to define the animation.
+ /// The target instance to animate.
+ /// The target property to animate.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The list of keyframes to use to build the animation.
+ /// A instance with the specified animation.
+ public static Timeline GetAnimation(
+ UIElement element,
+ string property,
+ TimeSpan? delay,
+ TimeSpan duration,
+ List keyFrames)
+ where TKeyFrame : struct, IKeyFrameInfo
{
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- public Xaml(string property, TimeSpan? delay)
- : base(property, delay)
- {
- }
+ Timeline animation;
- ///
- public virtual unsafe Timeline GetAnimation(UIElement element)
+ if (typeof(T) == typeof(double))
{
- Timeline animation;
+ DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
- if (typeof(T) == typeof(double))
+ foreach (var keyFrame in keyFrames)
{
- DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in this.keyFrames)
+ doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
{
- doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
- {
- KeyTime = keyFrame.Progress,
- Value = *(double*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = doubleAnimation;
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = keyFrame.GetValueAs(),
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
}
- else if (typeof(T) == typeof(Point))
- {
- PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
- foreach (var keyFrame in this.keyFrames)
- {
- pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
- {
- KeyTime = keyFrame.Progress,
- Value = *(Point*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
+ animation = doubleAnimation;
+ }
+ else if (typeof(T) == typeof(Point))
+ {
+ PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
- animation = pointAnimation;
- }
- else if (typeof(T) == typeof(Color))
+ foreach (var keyFrame in keyFrames)
{
- ColorAnimationUsingKeyFrames colorAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in this.keyFrames)
+ pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
{
- colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
- {
- KeyTime = keyFrame.Progress,
- Value = *(Color*)&keyFrame.Value,
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = colorAnimation;
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = keyFrame.GetValueAs(),
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
}
- else
+
+ animation = pointAnimation;
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ ColorAnimationUsingKeyFrames colorAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in keyFrames)
{
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ colorAnimation.KeyFrames.Add(new EasingColorKeyFrame()
+ {
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = keyFrame.GetValueAs(),
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
}
- animation.BeginTime = this.delay;
+ animation = colorAnimation;
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+
+ animation.BeginTime = delay;
+
+ Storyboard.SetTarget(animation, element);
+ Storyboard.SetTargetProperty(animation, property);
- Storyboard.SetTarget(animation, element);
- Storyboard.SetTargetProperty(animation, this.property);
+ return animation;
+ }
+
+ ///
+ /// A custom class targeting the XAML layer.
+ ///
+ public sealed class Xaml : TimedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public Xaml(string property, TimeSpan? delay)
+ : base(property, delay)
+ {
+ }
- return animation;
+ ///
+ public Timeline GetAnimation(UIElement element)
+ {
+ return GetAnimation(
+ element,
+ this.property,
+ this.delay,
+ default,
+ this.keyFrames);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
index 5ca3f536a3a..6ad0400c2f3 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -57,8 +58,18 @@ public ITimedKeyFrameAnimationBuilder KeyFrame(
///
/// The abstracted info for a timed animation keyframe.
///
- protected readonly struct KeyFrameInfo
+ protected readonly struct KeyFrameInfo : IKeyFrameInfo
{
+ ///
+ /// The progress for the keyframe.
+ ///
+ private readonly TimeSpan progress;
+
+ ///
+ /// The value for the current keyframe.
+ ///
+ private readonly T value;
+
///
/// Initializes a new instance of the struct.
///
@@ -72,40 +83,39 @@ public KeyFrameInfo(
EasingType easingType,
EasingMode easingMode)
{
- Progress = progress;
- Value = value;
+ this.progress = progress;
+ this.value = value;
+
EasingType = easingType;
EasingMode = easingMode;
}
- ///
- /// The progress for the keyframe.
- ///
- public readonly TimeSpan Progress;
+ ///
+ public EasingType EasingType { get; }
- ///
- /// The value for the new keyframe to add.
- ///
- public readonly T Value;
+ ///
+ public EasingMode EasingMode { get; }
- ///
- /// The easing type to use to reach the new keyframe.
- ///
- public readonly EasingType EasingType;
-
- ///
- /// The easing mode to use to reach the new keyframe.
- ///
- public readonly EasingMode EasingMode;
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public TValue GetValueAs()
+ where TValue : unmanaged
+ {
+ return Unsafe.As(ref Unsafe.AsRef(in this.value));
+ }
- ///
- /// Gets a normalized duration for the current instance, relative to a value.
- ///
- /// The target value to use.
- /// A normalized value relative to .
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public double GetNormalizedProgress(TimeSpan duration)
{
- return Math.Clamp(Progress.TotalMilliseconds * 100 / duration.TotalMilliseconds, 0, 1);
+ return Math.Clamp(this.progress.TotalMilliseconds * 100 / duration.TotalMilliseconds, 0, 1);
+ }
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public TimeSpan GetTimedProgress(TimeSpan duration)
+ {
+ return this.progress;
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
index f385ff525c9..e49f7af1cd7 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj
@@ -16,7 +16,6 @@
UWP Toolkit Windows Animations Composition Connected Implicit XAML9.0
- true
From c3d139b11ca11a4ea3f355675a47ff38801e975d Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 18:31:46 +0100
Subject: [PATCH 045/171] Uniformed type support for keyframed animations
---
...KeyFrameAnimationBuilder{T}.Composition.cs | 14 +++++++
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 37 ++++++++++++++++++-
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index 68fb3e8ef32..015dc487541 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -62,6 +62,20 @@ public static CompositionAnimation GetAnimation(
animation = scalarAnimation;
}
+ else if (typeof(T) == typeof(double))
+ {
+ ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
+
+ foreach (var keyFrame in keyFrames)
+ {
+ scalarAnimation.InsertKeyFrame(
+ (float)keyFrame.GetNormalizedProgress(duration),
+ (float)keyFrame.GetValueAs(),
+ visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ }
+
+ animation = scalarAnimation;
+ }
else if (typeof(T) == typeof(Vector2))
{
Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 15b37bfe0ad..43e7dff65f8 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Numerics;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
using Windows.Foundation;
@@ -37,7 +38,23 @@ public static Timeline GetAnimation(
{
Timeline animation;
- if (typeof(T) == typeof(double))
+ if (typeof(T) == typeof(float))
+ {
+ DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in keyFrames)
+ {
+ doubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
+ {
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = keyFrame.GetValueAs(),
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = doubleAnimation;
+ }
+ else if (typeof(T) == typeof(double))
{
DoubleAnimationUsingKeyFrames doubleAnimation = new() { EnableDependentAnimation = true };
@@ -53,6 +70,24 @@ public static Timeline GetAnimation(
animation = doubleAnimation;
}
+ else if (typeof(T) == typeof(Vector2))
+ {
+ PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in keyFrames)
+ {
+ Vector2 vector = keyFrame.GetValueAs();
+
+ pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
+ {
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = new Point(vector.X, vector.Y),
+ EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
+ });
+ }
+
+ animation = pointAnimation;
+ }
else if (typeof(T) == typeof(Point))
{
PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
From 01e2cb334592aa85544ed64c3962de6dbee39d10 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 18:46:18 +0100
Subject: [PATCH 046/171] Minor tweaks to the default animations
---
.../Builders/AnimationBuilder.Default.cs | 48 ++++++++++++-------
.../Builders/AnimationBuilder.Setup.cs | 30 ------------
2 files changed, 31 insertions(+), 47 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index c2cee2cfb53..5ce5a087c7f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -102,15 +102,16 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionVector2AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory("Translation.X", from?.X, to.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory("Translation.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
}
else
{
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
-
- return this;
}
+
+ return this;
}
///
@@ -178,7 +179,10 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector2AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
+
+ return this;
}
///
@@ -204,7 +208,7 @@ public AnimationBuilder Offset(
}
///
- /// Adds a new uniform scale animation on the X and Y axes to the current schedule.
+ /// Adds a new uniform scale animation for all axes to the current schedule.
///
/// The optional starting value for the animation.
/// The final value for the animation.
@@ -225,10 +229,10 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- Vector2? from2 = from is null ? null : new((float)(double)from);
- Vector2 to2 = new((float)to);
+ Vector3? from3 = from is null ? null : new((float)(double)from);
+ Vector3 to3 = new((float)to);
- return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from2, to2, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from3, to3, delay, duration, easingType, easingMode);
}
else
{
@@ -249,8 +253,8 @@ public AnimationBuilder Scale(
/// The animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
/// The current instance.
- /// This animation is only available on the XAML layer.
public AnimationBuilder Scale(
Axis axis,
double? from,
@@ -258,9 +262,17 @@ public AnimationBuilder Scale(
TimeSpan? delay,
TimeSpan duration,
EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
{
- return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
+ if (layer == FrameworkLayer.Composition)
+ {
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
+ }
}
///
@@ -285,15 +297,16 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionVector2AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
}
else
{
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from?.X, to.X, delay, duration, easingType, easingMode);
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from?.Y, to.Y, delay, duration, easingType, easingMode);
-
- return this;
}
+
+ return this;
}
///
@@ -490,15 +503,16 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionVector2AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
}
else
{
AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), from?.X, to.X, delay, duration, easingType, easingMode, true);
AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), from?.Y, to.Y, delay, duration, easingType, easingMode, true);
-
- return this;
}
+
+ return this;
}
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
index a7f8a2b5d83..16fbc6a622a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
@@ -56,36 +56,6 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
return this;
}
- ///
- /// Adds a new composition animation to the current schedule.
- ///
- /// The target property to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The easing function for the animation.
- /// The easing mode for the animation.
- /// The current instance.
- /// This will use a animation with a zero Z axis.
- private AnimationBuilder AddCompositionVector2AnimationFactory(
- string property,
- Vector2? from,
- Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
- EasingType easingType,
- EasingMode easingMode)
- {
- Vector3? from3 = from is null ? null : new(from.Value, 0);
- Vector3 to3 = new(to, 0);
- CompositionVector3AnimationFactory animation = new(property, from3, to3, delay, duration, easingType, easingMode);
-
- this.compositionAnimationFactories.Add(animation);
-
- return this;
- }
-
///
/// Adds a new composition animation to the current schedule.
///
From e3dab22a53037352089a07a51a24abe1e8fa0940 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 19:53:49 +0100
Subject: [PATCH 047/171] Changed animation duration to be nullable
---
.../Builders/AnimationBuilder.Default.cs | 106 +++++++++---------
.../Builders/AnimationBuilder.Models.cs | 12 +-
.../Builders/AnimationBuilder.Setup.cs | 46 ++++++--
.../Builders/AnimationBuilder.cs | 6 +-
.../Extensions/AnimationExtensions.cs | 5 +
5 files changed, 105 insertions(+), 70 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 5ce5a087c7f..32ebc2c1f17 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -24,7 +24,7 @@ public sealed partial class AnimationBuilder
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -32,8 +32,8 @@ public sealed partial class AnimationBuilder
public AnimationBuilder Opacity(
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -55,7 +55,7 @@ public AnimationBuilder Opacity(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -64,8 +64,8 @@ public AnimationBuilder Translation(
Axis axis,
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -86,7 +86,7 @@ public AnimationBuilder Translation(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -94,8 +94,8 @@ public AnimationBuilder Translation(
public AnimationBuilder Translation(
Vector2? from,
Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -120,7 +120,7 @@ public AnimationBuilder Translation(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -128,8 +128,8 @@ public AnimationBuilder Translation(
public AnimationBuilder Translation(
Vector3? from,
Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -143,7 +143,7 @@ public AnimationBuilder Translation(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -152,8 +152,8 @@ public AnimationBuilder Offset(
Axis axis,
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -166,7 +166,7 @@ public AnimationBuilder Offset(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -174,8 +174,8 @@ public AnimationBuilder Offset(
public AnimationBuilder Offset(
Vector2? from,
Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -191,7 +191,7 @@ public AnimationBuilder Offset(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -199,8 +199,8 @@ public AnimationBuilder Offset(
public AnimationBuilder Offset(
Vector3? from,
Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -213,7 +213,7 @@ public AnimationBuilder Offset(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -221,8 +221,8 @@ public AnimationBuilder Offset(
public AnimationBuilder Scale(
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -250,7 +250,7 @@ public AnimationBuilder Scale(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -259,8 +259,8 @@ public AnimationBuilder Scale(
Axis axis,
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -281,7 +281,7 @@ public AnimationBuilder Scale(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -289,8 +289,8 @@ public AnimationBuilder Scale(
public AnimationBuilder Scale(
Vector2? from,
Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -315,7 +315,7 @@ public AnimationBuilder Scale(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -323,8 +323,8 @@ public AnimationBuilder Scale(
public AnimationBuilder Scale(
Vector3? from,
Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -337,7 +337,7 @@ public AnimationBuilder Scale(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -345,8 +345,8 @@ public AnimationBuilder Scale(
public AnimationBuilder Rotate(
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -372,7 +372,7 @@ public AnimationBuilder Rotate(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -380,8 +380,8 @@ public AnimationBuilder Rotate(
public AnimationBuilder RotateInDegrees(
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -405,7 +405,7 @@ public AnimationBuilder RotateInDegrees(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -414,8 +414,8 @@ public AnimationBuilder Clip(
Side side,
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -432,8 +432,8 @@ public AnimationBuilder Clip(
property,
(float?)from,
(float)to,
- delay,
- duration,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
easingType,
easingMode);
@@ -449,7 +449,7 @@ public AnimationBuilder Clip(
/// The optional starting value for the animation.
/// The final value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -458,8 +458,8 @@ public AnimationBuilder Size(
Axis axis,
double? from,
double to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -487,7 +487,7 @@ public AnimationBuilder Size(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
@@ -495,8 +495,8 @@ public AnimationBuilder Size(
public AnimationBuilder Size(
Vector2? from,
Vector2 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode,
FrameworkLayer layer = FrameworkLayer.Composition)
@@ -521,7 +521,7 @@ public AnimationBuilder Size(
/// The optional starting point for the animation.
/// The final point for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
@@ -529,8 +529,8 @@ public AnimationBuilder Size(
public AnimationBuilder Size(
Vector3? from,
Vector3 to,
- TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index e4cf322ae69..5f747c58205 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -23,7 +23,7 @@ private sealed record CompositionDoubleAnimation(
string Property,
float? From,
float To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
@@ -46,7 +46,7 @@ private sealed record CompositionScalarAnimationFactory(
string Property,
float? From,
float To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
@@ -69,7 +69,7 @@ private sealed record CompositionVector3AnimationFactory(
string Property,
Vector3? From,
Vector3 To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
@@ -92,7 +92,7 @@ private sealed record CompositionClipScalarAnimation(
string Property,
float? From,
float To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
@@ -116,7 +116,7 @@ private sealed record XamlDoubleAnimationFactory(
string Property,
double? From,
double To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode,
@@ -137,7 +137,7 @@ private sealed record XamlTransformDoubleAnimationFactory(
string Property,
double? From,
double To,
- TimeSpan? Delay,
+ TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
index 16fbc6a622a..76747c0a46c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
@@ -45,11 +46,18 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
float? from,
float to,
TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? duration,
EasingType easingType,
EasingMode easingMode)
{
- CompositionScalarAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
+ CompositionScalarAnimationFactory animation = new(
+ property,
+ from,
+ to,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode);
this.compositionAnimationFactories.Add(animation);
@@ -72,11 +80,18 @@ private AnimationBuilder AddCompositionVector3AnimationFactory(
Vector3? from,
Vector3 to,
TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? duration,
EasingType easingType,
EasingMode easingMode)
{
- CompositionVector3AnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
+ CompositionVector3AnimationFactory animation = new(
+ property,
+ from,
+ to,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode);
this.compositionAnimationFactories.Add(animation);
@@ -100,12 +115,20 @@ private AnimationBuilder AddXamlDoubleAnimationFactory(
double? from,
double to,
TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? duration,
EasingType easingType,
EasingMode easingMode,
bool enableDependentAnimation)
{
- XamlDoubleAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode, enableDependentAnimation);
+ XamlDoubleAnimationFactory animation = new(
+ property,
+ from,
+ to,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode,
+ enableDependentAnimation);
this.xamlAnimationFactories.Add(animation);
@@ -128,11 +151,18 @@ private AnimationBuilder AddXamlTransformDoubleAnimationFactory(
double? from,
double to,
TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? duration,
EasingType easingType,
EasingMode easingMode)
{
- XamlTransformDoubleAnimationFactory animation = new(property, from, to, delay, duration, easingType, easingMode);
+ XamlTransformDoubleAnimationFactory animation = new(
+ property,
+ from,
+ to,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode);
this.xamlAnimationFactories.Add(animation);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index b0e7f2a109a..891f9765609 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -68,7 +68,7 @@ public AnimationBuilder DoubleAnimation(
double? from,
double to,
TimeSpan? delay,
- TimeSpan duration,
+ TimeSpan? duration,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
@@ -77,8 +77,8 @@ public AnimationBuilder DoubleAnimation(
property,
(float?)from,
(float)to,
- delay,
- duration,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
easingType,
easingMode);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
index 8195d4893dc..2d7ee81fd58 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
@@ -14,6 +14,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
///
public static partial class AnimationExtensions
{
+ ///
+ /// Gets the default delay of animations.
+ ///
+ public static TimeSpan DefaultDelay => default;
+
///
/// Gets the default duration of animations.
///
From ec9cae6ea36f542ed950a2ecbf34c008c8a510eb Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 19:56:53 +0100
Subject: [PATCH 048/171] Minor code tweaks
---
.../Xaml/Default/OpacityAnimation.cs | 4 ++--
.../Xaml/Default/ScaleAnimation.cs | 4 ++--
.../Xaml/Default/TranslationAnimation.cs | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index 9c5b4669840..2271593f89d 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// An opacity animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
public class OpacityAnimation : TypedAnimation, ITimeline
{
@@ -26,7 +26,7 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
From,
To,
Delay ?? delayHint,
- Duration ?? durationHint.GetValueOrDefault(),
+ Duration ?? durationHint,
EasingType ?? easingTypeHint ?? DefaultEasingType,
EasingMode ?? easingModeHint ?? DefaultEasingMode,
Layer);
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
index 0e4b2fe41dc..65008eb39c6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A scale animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
public class ScaleAnimation : TypedAnimation, ITimeline
{
@@ -24,7 +24,7 @@ public class ScaleAnimation : TypedAnimation, ITimeline
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
TimeSpan? delay = Delay ?? delayHint;
- TimeSpan duration = Duration ?? durationHint.GetValueOrDefault();
+ TimeSpan? duration = Duration ?? durationHint;
EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
EasingMode easingMode = EasingMode ?? easingModeHint ?? DefaultEasingMode;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 996701e2a61..8ddeca89c10 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A translation animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
public class TranslationAnimation : TypedAnimation, ITimeline
{
@@ -24,7 +24,7 @@ public class TranslationAnimation : TypedAnimation, ITimeline
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
TimeSpan? delay = Delay ?? delayHint;
- TimeSpan duration = Duration ?? durationHint.GetValueOrDefault();
+ TimeSpan? duration = Duration ?? durationHint;
EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
EasingMode easingMode = EasingMode ?? easingModeHint ?? DefaultEasingMode;
From 56bc3fc4ea319dd32f61cb0c47ed951f0a867f3e Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 20:22:53 +0100
Subject: [PATCH 049/171] Changed "from" parameters to be optional
---
.../Builders/AnimationBuilder.Default.cs | 138 +++++++++---------
.../Builders/AnimationBuilder.Models.cs | 12 +-
.../Builders/AnimationBuilder.Setup.cs | 24 +--
.../Builders/AnimationBuilder.cs | 12 +-
.../Xaml/Abstract/TypedAnimation{T}.cs | 8 +-
.../Xaml/Default/OpacityAnimation.cs | 6 +-
.../Xaml/Default/ScaleAnimation.cs | 6 +-
.../Xaml/Default/TranslationAnimation.cs | 6 +-
8 files changed, 106 insertions(+), 106 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 32ebc2c1f17..00d0307c6f6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -21,8 +21,8 @@ public sealed partial class AnimationBuilder
///
/// Adds a new opacity animation to the current schedule.
///
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -30,8 +30,8 @@ public sealed partial class AnimationBuilder
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Opacity(
- double? from,
double to,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -40,11 +40,11 @@ public AnimationBuilder Opacity(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), from, to, delay, duration, easingType, easingMode, false);
+ return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode, false);
}
}
@@ -52,8 +52,8 @@ public AnimationBuilder Opacity(
/// Adds a new translation animation for a single axis to the current schedule.
///
/// The target translation axis to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -62,8 +62,8 @@ public AnimationBuilder Opacity(
/// The current instance.
public AnimationBuilder Translation(
Axis axis,
- double? from,
double to,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -72,19 +72,19 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlDoubleAnimationFactory($"Translate{axis}", from, to, delay, duration, easingType, easingMode, false);
+ return AddXamlDoubleAnimationFactory($"Translate{axis}", to, from, delay, duration, easingType, easingMode, false);
}
}
///
/// Adds a new translation animation for the X and Y axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -92,8 +92,8 @@ public AnimationBuilder Translation(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Translation(
- Vector2? from,
Vector2 to,
+ Vector2? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -102,13 +102,13 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory("Translation.X", from?.X, to.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory("Translation.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory("Translation.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory("Translation.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), from?.X, to.X, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), to.X, from?.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), to.Y, from?.Y, delay, duration, easingType, easingMode);
}
return this;
@@ -117,8 +117,8 @@ public AnimationBuilder Translation(
///
/// Adds a new composition translation animation for all axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -126,22 +126,22 @@ public AnimationBuilder Translation(
/// The current instance.
/// This animation is only available on the composition layer.
public AnimationBuilder Translation(
- Vector3? from,
Vector3 to,
+ Vector3? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory("Translation", from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory("Translation", to, from, delay, duration, easingType, easingMode);
}
///
/// Adds a new composition offset animation for a single axis to the current schedule.
///
/// The target translation axis to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -150,21 +150,21 @@ public AnimationBuilder Translation(
/// This animation is only available on the composition layer.
public AnimationBuilder Offset(
Axis axis,
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
///
/// Adds a new composition offset animation for the X and Y axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -172,15 +172,15 @@ public AnimationBuilder Offset(
/// The current instance.
/// This animation is only available on the composition layer.
public AnimationBuilder Offset(
- Vector2? from,
Vector2 to,
+ Vector2? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
return this;
}
@@ -188,8 +188,8 @@ public AnimationBuilder Offset(
///
/// Adds a new composition offset translation animation for all axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -197,21 +197,21 @@ public AnimationBuilder Offset(
/// The current instance.
/// This animation is only available on the composition layer.
public AnimationBuilder Offset(
- Vector3? from,
Vector3 to,
+ Vector3? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), to, from, delay, duration, easingType, easingMode);
}
///
/// Adds a new uniform scale animation for all axes to the current schedule.
///
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -219,8 +219,8 @@ public AnimationBuilder Offset(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Scale(
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -232,12 +232,12 @@ public AnimationBuilder Scale(
Vector3? from3 = from is null ? null : new((float)(double)from);
Vector3 to3 = new((float)to);
- return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from3, to3, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode);
}
else
{
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from, to, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to, from, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to, from, delay, duration, easingType, easingMode);
return this;
}
@@ -247,8 +247,8 @@ public AnimationBuilder Scale(
/// Adds a new scale animation on a specified axis to the current schedule.
///
/// The target scale axis to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -257,8 +257,8 @@ public AnimationBuilder Scale(
/// The current instance.
public AnimationBuilder Scale(
Axis axis,
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -267,19 +267,19 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", from, to, delay, duration, easingType, easingMode);
+ return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", to, from, delay, duration, easingType, easingMode);
}
}
///
/// Adds a new scale animation for the X and Y axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -287,8 +287,8 @@ public AnimationBuilder Scale(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Scale(
- Vector2? from,
Vector2 to,
+ Vector2? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -297,13 +297,13 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), from?.X, to.X, delay, duration, easingType, easingMode);
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to.X, from?.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to.Y, from?.Y, delay, duration, easingType, easingMode);
}
return this;
@@ -312,8 +312,8 @@ public AnimationBuilder Scale(
///
/// Adds a new scale animation for all axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -321,21 +321,21 @@ public AnimationBuilder Scale(
/// The current instance.
/// This animation is only available on the composition layer.
public AnimationBuilder Scale(
- Vector3? from,
Vector3 to,
+ Vector3? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), to, from, delay, duration, easingType, easingMode);
}
///
/// Adds a new rotation animation to the current schedule.
///
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -343,8 +343,8 @@ public AnimationBuilder Scale(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Rotate(
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -353,14 +353,14 @@ public AnimationBuilder Rotate(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
double? fromDegrees = from * Math.PI / 180;
double toDegrees = to * Math.PI / 180;
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), fromDegrees, toDegrees, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), toDegrees, fromDegrees, delay, duration, easingType, easingMode);
return this;
}
@@ -369,8 +369,8 @@ public AnimationBuilder Rotate(
///
/// Adds a new rotation animation in degrees to the current schedule.
///
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -378,8 +378,8 @@ public AnimationBuilder Rotate(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder RotateInDegrees(
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -388,11 +388,11 @@ public AnimationBuilder RotateInDegrees(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), from, to, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), to, from, delay, duration, easingType, easingMode);
return this;
}
@@ -402,8 +402,8 @@ public AnimationBuilder RotateInDegrees(
/// Adds a new clip animation to the current schedule.
///
/// The clip size to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -412,8 +412,8 @@ public AnimationBuilder RotateInDegrees(
/// This animation is only available on the composition layer.
public AnimationBuilder Clip(
Side side,
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -430,8 +430,8 @@ public AnimationBuilder Clip(
CompositionClipScalarAnimation animation = new(
property,
- (float?)from,
(float)to,
+ (float?)from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
@@ -446,8 +446,8 @@ public AnimationBuilder Clip(
/// Adds a new size animation for a single axis to the current schedule.
///
/// The target size axis to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -456,8 +456,8 @@ public AnimationBuilder Clip(
/// The current instance.
public AnimationBuilder Size(
Axis axis,
- double? from,
double to,
+ double? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -466,7 +466,7 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float?)from, (float)to, delay, duration, easingType, easingMode);
+ return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -477,15 +477,15 @@ public AnimationBuilder Size(
_ => ThrowHelper.ThrowArgumentException("Invalid size axis")
};
- return AddXamlDoubleAnimationFactory(property, from, to, delay, duration, easingType, easingMode, true);
+ return AddXamlDoubleAnimationFactory(property, to, from, delay, duration, easingType, easingMode, true);
}
}
///
/// Adds a new size animation for the X and Y axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -493,8 +493,8 @@ public AnimationBuilder Size(
/// The target framework layer to animate.
/// The current instance.
public AnimationBuilder Size(
- Vector2? from,
Vector2 to,
+ Vector2? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -503,13 +503,13 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.X", from?.X, to.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.Y", from?.Y, to.Y, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), from?.X, to.X, delay, duration, easingType, easingMode, true);
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), from?.Y, to.Y, delay, duration, easingType, easingMode, true);
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), to.X, from?.X, delay, duration, easingType, easingMode, true);
+ AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), to.Y, from?.Y, delay, duration, easingType, easingMode, true);
}
return this;
@@ -518,8 +518,8 @@ public AnimationBuilder Size(
///
/// Adds a new composition size translation animation for all axes to the current schedule.
///
- /// The optional starting point for the animation.
/// The final point for the animation.
+ /// The optional starting point for the animation.
/// The optional initial delay for the animation.
/// The optional animation duration.
/// The optional easing function type for the animation.
@@ -527,14 +527,14 @@ public AnimationBuilder Size(
/// The current instance.
/// This animation is only available on the composition layer.
public AnimationBuilder Size(
- Vector3? from,
Vector3 to,
+ Vector3? from,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Size), from, to, delay, duration, easingType, easingMode);
+ return AddCompositionVector3AnimationFactory(nameof(Visual.Size), to, from, delay, duration, easingType, easingMode);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index 5f747c58205..bc3ccb51421 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -21,8 +21,8 @@ public sealed partial class AnimationBuilder
private sealed record CompositionDoubleAnimation(
CompositionObject Target,
string Property,
- float? From,
float To,
+ float? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
@@ -44,8 +44,8 @@ public void StartAnimation()
///
private sealed record CompositionScalarAnimationFactory(
string Property,
- float? From,
float To,
+ float? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
@@ -67,8 +67,8 @@ public CompositionAnimation GetAnimation(Visual visual)
///
private sealed record CompositionVector3AnimationFactory(
string Property,
- Vector3? From,
Vector3 To,
+ Vector3? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
@@ -90,8 +90,8 @@ public CompositionAnimation GetAnimation(Visual visual)
///
private sealed record CompositionClipScalarAnimation(
string Property,
- float? From,
float To,
+ float? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
@@ -114,8 +114,8 @@ public CompositionAnimation GetAnimation(Visual visual)
///
private sealed record XamlDoubleAnimationFactory(
string Property,
- double? From,
double To,
+ double? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
@@ -135,8 +135,8 @@ public Timeline GetAnimation(UIElement element)
///
private sealed record XamlTransformDoubleAnimationFactory(
string Property,
- double? From,
double To,
+ double? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
index 76747c0a46c..47efc17574d 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
@@ -34,8 +34,8 @@ public sealed partial class AnimationBuilder
/// Adds a new composition scalar animation to the current schedule.
///
/// The target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The animation duration.
/// The easing function for the animation.
@@ -43,8 +43,8 @@ public sealed partial class AnimationBuilder
/// The current instance.
private AnimationBuilder AddCompositionScalarAnimationFactory(
string property,
- float? from,
float to,
+ float? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
@@ -52,8 +52,8 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
{
CompositionScalarAnimationFactory animation = new(
property,
- from,
to,
+ from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
@@ -68,8 +68,8 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
/// Adds a new composition animation to the current schedule.
///
/// The target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The animation duration.
/// The easing function for the animation.
@@ -77,8 +77,8 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
/// The current instance.
private AnimationBuilder AddCompositionVector3AnimationFactory(
string property,
- Vector3? from,
Vector3 to,
+ Vector3? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
@@ -86,8 +86,8 @@ private AnimationBuilder AddCompositionVector3AnimationFactory(
{
CompositionVector3AnimationFactory animation = new(
property,
- from,
to,
+ from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
@@ -102,8 +102,8 @@ private AnimationBuilder AddCompositionVector3AnimationFactory(
/// Adds a new XAML animation to the current schedule.
///
/// The target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The animation duration.
/// The easing function for the animation.
@@ -112,8 +112,8 @@ private AnimationBuilder AddCompositionVector3AnimationFactory(
/// The current instance.
private AnimationBuilder AddXamlDoubleAnimationFactory(
string property,
- double? from,
double to,
+ double? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
@@ -122,8 +122,8 @@ private AnimationBuilder AddXamlDoubleAnimationFactory(
{
XamlDoubleAnimationFactory animation = new(
property,
- from,
to,
+ from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
@@ -139,8 +139,8 @@ private AnimationBuilder AddXamlDoubleAnimationFactory(
/// Adds a new XAML transform animation to the current schedule.
///
/// The target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
/// The animation duration.
/// The easing function for the animation.
@@ -148,8 +148,8 @@ private AnimationBuilder AddXamlDoubleAnimationFactory(
/// The current instance.
private AnimationBuilder AddXamlTransformDoubleAnimationFactory(
string property,
- double? from,
double to,
+ double? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
@@ -157,8 +157,8 @@ private AnimationBuilder AddXamlTransformDoubleAnimationFactory(
{
XamlTransformDoubleAnimationFactory animation = new(
property,
- from,
to,
+ from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index 891f9765609..d8c57e25caf 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -55,28 +55,28 @@ public sealed partial class AnimationBuilder
///
/// The target to animate.
/// The target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
- /// The animation duration.
+ /// The optional animation duration.
/// The optional easing function type for the animation.
/// The optional easing function mode for the animation.
/// The current instance.
public AnimationBuilder DoubleAnimation(
CompositionObject target,
string property,
- double? from,
double to,
- TimeSpan? delay,
- TimeSpan? duration,
+ double? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
CompositionDoubleAnimation animation = new(
target,
property,
- (float?)from,
(float)to,
+ (float?)from,
delay ?? DefaultDelay,
duration ?? DefaultDuration,
easingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
index abdd6d15e1c..d37a5efc8e9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
@@ -13,13 +13,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
public abstract class TypedAnimation : Animation
{
///
- /// Gets or sets the optional starting value for the animation.
+ /// Gets or sets the final value for the animation.
///
- public T? From { get; set; }
+ public T? To { get; set; }
///
- /// Gets or sets the final value for the animation.
+ /// Gets or sets the optional starting value for the animation.
///
- public T? To { get; set; }
+ public T? From { get; set; }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index 2271593f89d..9a837ce65da 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -10,9 +10,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// An opacity animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
- public class OpacityAnimation : TypedAnimation, ITimeline
+ public class OpacityAnimation : TypedAnimation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
@@ -23,8 +23,8 @@ public class OpacityAnimation : TypedAnimation, ITimeline
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
return builder.Opacity(
+ To!.Value,
From,
- To,
Delay ?? delayHint,
Duration ?? durationHint,
EasingType ?? easingTypeHint ?? DefaultEasingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
index 65008eb39c6..7a5024c59af 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A scale animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
public class ScaleAnimation : TypedAnimation, ITimeline
{
@@ -30,11 +30,11 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
if (Layer == FrameworkLayer.Composition)
{
- return builder.Scale(From?.ToVector3(), To!.ToVector3(), delay, duration, easingType, easingMode);
+ return builder.Scale(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
}
else
{
- return builder.Scale(From?.ToVector2(), To!.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ return builder.Scale(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 8ddeca89c10..75964ed10dd 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A translation animation working on the composition or XAML layer.
- /// This animation maps to .
+ /// This animation maps to .
///
public class TranslationAnimation : TypedAnimation, ITimeline
{
@@ -30,11 +30,11 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
if (Layer == FrameworkLayer.Composition)
{
- return builder.Translation(From?.ToVector3(), To!.ToVector3(), delay, duration, easingType, easingMode);
+ return builder.Translation(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
}
else
{
- return builder.Translation(From?.ToVector2(), To!.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ return builder.Translation(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
From 4458505b374f0faf9fdc5c3d16832a49e56ae698 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Sun, 20 Dec 2020 22:42:08 +0100
Subject: [PATCH 050/171] Added missing nullable default values
---
.../Builders/AnimationBuilder.Default.cs | 30 +++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 00d0307c6f6..f5ed4a85fdd 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -93,7 +93,7 @@ public AnimationBuilder Translation(
/// The current instance.
public AnimationBuilder Translation(
Vector2 to,
- Vector2? from,
+ Vector2? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -127,7 +127,7 @@ public AnimationBuilder Translation(
/// This animation is only available on the composition layer.
public AnimationBuilder Translation(
Vector3 to,
- Vector3? from,
+ Vector3? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -151,7 +151,7 @@ public AnimationBuilder Translation(
public AnimationBuilder Offset(
Axis axis,
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -173,7 +173,7 @@ public AnimationBuilder Offset(
/// This animation is only available on the composition layer.
public AnimationBuilder Offset(
Vector2 to,
- Vector2? from,
+ Vector2? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -198,7 +198,7 @@ public AnimationBuilder Offset(
/// This animation is only available on the composition layer.
public AnimationBuilder Offset(
Vector3 to,
- Vector3? from,
+ Vector3? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -220,7 +220,7 @@ public AnimationBuilder Offset(
/// The current instance.
public AnimationBuilder Scale(
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -258,7 +258,7 @@ public AnimationBuilder Scale(
public AnimationBuilder Scale(
Axis axis,
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -288,7 +288,7 @@ public AnimationBuilder Scale(
/// The current instance.
public AnimationBuilder Scale(
Vector2 to,
- Vector2? from,
+ Vector2? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -322,7 +322,7 @@ public AnimationBuilder Scale(
/// This animation is only available on the composition layer.
public AnimationBuilder Scale(
Vector3 to,
- Vector3? from,
+ Vector3? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -344,7 +344,7 @@ public AnimationBuilder Scale(
/// The current instance.
public AnimationBuilder Rotate(
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -379,7 +379,7 @@ public AnimationBuilder Rotate(
/// The current instance.
public AnimationBuilder RotateInDegrees(
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -413,7 +413,7 @@ public AnimationBuilder RotateInDegrees(
public AnimationBuilder Clip(
Side side,
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -457,7 +457,7 @@ public AnimationBuilder Clip(
public AnimationBuilder Size(
Axis axis,
double to,
- double? from,
+ double? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -494,7 +494,7 @@ public AnimationBuilder Size(
/// The current instance.
public AnimationBuilder Size(
Vector2 to,
- Vector2? from,
+ Vector2? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
@@ -528,7 +528,7 @@ public AnimationBuilder Size(
/// This animation is only available on the composition layer.
public AnimationBuilder Size(
Vector3 to,
- Vector3? from,
+ Vector3? from = null,
TimeSpan? delay = null,
TimeSpan? duration = null,
EasingType easingType = DefaultEasingType,
From 07a85858ab58f832b489b522b90d27a53b3f799a Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 13:39:30 +0100
Subject: [PATCH 051/171] Added more compositor animation extensions
---
.../Builders/AnimationBuilder.Models.cs | 12 +-
.../Extensions/CompositionObjectExtensions.cs | 84 ------
.../Extensions/CompositorExtensions.cs | 239 ++++++++++++++++--
.../Extensions/DependencyObjectExtensions.cs | 4 +-
4 files changed, 232 insertions(+), 107 deletions(-)
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index bc3ccb51421..1b1ad4cb574 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -33,7 +33,7 @@ private sealed record CompositionDoubleAnimation(
public void StartAnimation()
{
CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+ ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
Target.StartAnimation(Property, animation);
}
@@ -56,7 +56,7 @@ private sealed record CompositionScalarAnimationFactory(
public CompositionAnimation GetAnimation(Visual visual)
{
CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+ ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
return animation;
}
@@ -79,7 +79,7 @@ private sealed record CompositionVector3AnimationFactory(
public CompositionAnimation GetAnimation(Visual visual)
{
CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- Vector3KeyFrameAnimation animation = visual.Compositor.CreateVector3KeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+ Vector3KeyFrameAnimation animation = visual.Compositor.CreateVector3KeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
return animation;
}
@@ -103,7 +103,7 @@ public CompositionAnimation GetAnimation(Visual visual)
{
InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip());
CompositionEasingFunction easingFunction = clip.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, From, To, Duration, Delay, easingFunction);
+ ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
return animation;
}
@@ -126,7 +126,7 @@ private sealed record XamlDoubleAnimationFactory(
///
public Timeline GetAnimation(UIElement element)
{
- return element.CreateDoubleAnimation(Property, From, To, Delay, Duration, EasingType.ToEasingFunction(EasingMode), EnableDependentAnimation);
+ return element.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode), EnableDependentAnimation);
}
}
@@ -148,7 +148,7 @@ public Timeline GetAnimation(UIElement element)
{
CompositeTransform transform = element.GetTransform();
- return transform.CreateDoubleAnimation(Property, From, To, Delay, Duration, EasingType.ToEasingFunction(EasingMode));
+ return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode));
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
deleted file mode 100644
index d12081f4d9e..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositionObjectExtensions.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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.
-
-#nullable enable
-
-using System;
-using System.Numerics;
-using Windows.UI.Composition;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
-{
- ///
- /// An extension for the type.
- ///
- public static class CompositionObjectExtensions
- {
- ///
- /// Creates and starts a scalar animation on the current .
- ///
- /// The target to animate.
- /// The path that identifies the property to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The animation duration.
- /// The optional initial delay for the animation.
- /// The optional easing function for the animation.
- public static void StartScalarAnimation(
- this CompositionObject target,
- string propertyPath,
- float? from,
- float to,
- TimeSpan duration,
- TimeSpan? delay,
- CompositionEasingFunction? ease = null)
- {
- target.StartAnimation(propertyPath, target.Compositor.CreateScalarKeyFrameAnimation(null, from, to, duration, delay, ease));
- }
-
- ///
- /// Creates and starts a animation on the current .
- ///
- /// The target to animate.
- /// The path that identifies the property to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The animation duration.
- /// The optional initial delay for the animation.
- /// The optional easing function for the animation.
- public static void StartVector2Animation(
- this CompositionObject target,
- string propertyPath,
- Vector2? from,
- Vector2 to,
- TimeSpan duration,
- TimeSpan? delay,
- CompositionEasingFunction? ease = null)
- {
- target.StartAnimation(propertyPath, target.Compositor.CreateVector2KeyFrameAnimation(null, from, to, duration, delay, ease));
- }
-
- ///
- /// Creates and starts a animation on the current .
- ///
- /// The target to animate.
- /// The path that identifies the property to animate.
- /// The optional starting value for the animation.
- /// The final value for the animation.
- /// The animation duration.
- /// The optional initial delay for the animation.
- /// The optional easing function for the animation.
- public static void StartVector3Animation(
- this CompositionObject target,
- string propertyPath,
- Vector3? from,
- Vector3 to,
- TimeSpan duration,
- TimeSpan? delay,
- CompositionEasingFunction? ease = null)
- {
- target.StartAnimation(propertyPath, target.Compositor.CreateVector3KeyFrameAnimation(null, from, to, duration, delay, ease));
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
index c610ef4b866..293ec4a81a3 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/CompositorExtensions.cs
@@ -7,6 +7,7 @@
using System;
using System.Diagnostics.Contracts;
using System.Numerics;
+using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml.Media.Animation;
@@ -48,24 +49,64 @@ public static CubicBezierEasingFunction CreateCubicBezierEasingFunction(this Com
}
///
- /// Creates a instance with the given parameters to on a target element.
+ /// Creates a instance with the given parameters to on a target element.
///
/// The current instance used to create the animation.
/// The optional target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
/// The animation duration.
+ /// A instance with the specified parameters.
+ [Pure]
+ public static BooleanKeyFrameAnimation CreateBooleanKeyFrameAnimation(
+ this Compositor compositor,
+ string? target,
+ bool to,
+ bool? from,
+ TimeSpan? delay,
+ TimeSpan duration)
+ {
+ BooleanKeyFrameAnimation animation = compositor.CreateBooleanKeyFrameAnimation();
+
+ animation.Duration = duration;
+
+ if (delay.HasValue)
+ {
+ animation.DelayTime = delay.Value;
+ }
+
+ animation.InsertKeyFrame(1, to);
+
+ if (from.HasValue)
+ {
+ animation.InsertKeyFrame(0, from.Value);
+ }
+
+ animation.Target = target;
+
+ return animation;
+ }
+
+ ///
+ /// Creates a instance with the given parameters to on a target element.
+ ///
+ /// The current instance used to create the animation.
+ /// The optional target property to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
+ /// The animation duration.
/// The optional easing function for the animation.
/// A instance with the specified parameters.
[Pure]
public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
this Compositor compositor,
string? target,
- float? from,
float to,
- TimeSpan duration,
+ float? from,
TimeSpan? delay,
+ TimeSpan duration,
CompositionEasingFunction? ease = null)
{
ScalarKeyFrameAnimation animation = compositor.CreateScalarKeyFrameAnimation();
@@ -77,7 +118,14 @@ public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
animation.DelayTime = delay.Value;
}
- animation.InsertKeyFrame(1, to, ease ?? compositor.CreateLinearEasingFunction());
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
if (from.HasValue)
{
@@ -94,20 +142,20 @@ public static ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(
///
/// The current instance used to create the animation.
/// The optional target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
- /// The animation duration.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
+ /// The animation duration.
/// The optional easing function for the animation.
/// A instance with the specified parameters.
[Pure]
public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
this Compositor compositor,
string? target,
- Vector2? from,
Vector2 to,
- TimeSpan duration,
+ Vector2? from,
TimeSpan? delay,
+ TimeSpan duration,
CompositionEasingFunction? ease = null)
{
Vector2KeyFrameAnimation animation = compositor.CreateVector2KeyFrameAnimation();
@@ -119,7 +167,14 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
animation.DelayTime = delay.Value;
}
- animation.InsertKeyFrame(1, to, ease ?? compositor.CreateLinearEasingFunction());
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
if (from.HasValue)
{
@@ -136,20 +191,20 @@ public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(
///
/// The current instance used to create the animation.
/// The optional target property to animate.
- /// The optional starting value for the animation.
/// The final value for the animation.
- /// The animation duration.
+ /// The optional starting value for the animation.
/// The optional initial delay for the animation.
+ /// The animation duration.
/// The optional easing function for the animation.
/// A instance with the specified parameters.
[Pure]
public static Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation(
this Compositor compositor,
string? target,
- Vector3? from,
Vector3 to,
- TimeSpan duration,
+ Vector3? from,
TimeSpan? delay,
+ TimeSpan duration,
CompositionEasingFunction? ease = null)
{
Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation();
@@ -161,7 +216,161 @@ public static Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation(
animation.DelayTime = delay.Value;
}
- animation.InsertKeyFrame(1, to, ease ?? compositor.CreateLinearEasingFunction());
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
+
+ if (from.HasValue)
+ {
+ animation.InsertKeyFrame(0, from.Value);
+ }
+
+ animation.Target = target;
+
+ return animation;
+ }
+
+ ///
+ /// Creates a instance with the given parameters to on a target element.
+ ///
+ /// The current instance used to create the animation.
+ /// The optional target property to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function for the animation.
+ /// A instance with the specified parameters.
+ [Pure]
+ public static Vector4KeyFrameAnimation CreateVector4KeyFrameAnimation(
+ this Compositor compositor,
+ string? target,
+ Vector4 to,
+ Vector4? from,
+ TimeSpan? delay,
+ TimeSpan duration,
+ CompositionEasingFunction? ease = null)
+ {
+ Vector4KeyFrameAnimation animation = compositor.CreateVector4KeyFrameAnimation();
+
+ animation.Duration = duration;
+
+ if (delay.HasValue)
+ {
+ animation.DelayTime = delay.Value;
+ }
+
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
+
+ if (from.HasValue)
+ {
+ animation.InsertKeyFrame(0, from.Value);
+ }
+
+ animation.Target = target;
+
+ return animation;
+ }
+
+ ///
+ /// Creates a instance with the given parameters to on a target element.
+ ///
+ /// The current instance used to create the animation.
+ /// The optional target property to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function for the animation.
+ /// A instance with the specified parameters.
+ [Pure]
+ public static ColorKeyFrameAnimation CreateColorKeyFrameAnimation(
+ this Compositor compositor,
+ string? target,
+ Color to,
+ Color? from,
+ TimeSpan? delay,
+ TimeSpan duration,
+ CompositionEasingFunction? ease = null)
+ {
+ ColorKeyFrameAnimation animation = compositor.CreateColorKeyFrameAnimation();
+
+ animation.Duration = duration;
+
+ if (delay.HasValue)
+ {
+ animation.DelayTime = delay.Value;
+ }
+
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
+
+ if (from.HasValue)
+ {
+ animation.InsertKeyFrame(0, from.Value);
+ }
+
+ animation.Target = target;
+
+ return animation;
+ }
+
+ ///
+ /// Creates a instance with the given parameters to on a target element.
+ ///
+ /// The current instance used to create the animation.
+ /// The optional target property to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The optional easing function for the animation.
+ /// A instance with the specified parameters.
+ [Pure]
+ public static QuaternionKeyFrameAnimation CreateQuaternionKeyFrameAnimation(
+ this Compositor compositor,
+ string? target,
+ Quaternion to,
+ Quaternion? from,
+ TimeSpan? delay,
+ TimeSpan duration,
+ CompositionEasingFunction? ease = null)
+ {
+ QuaternionKeyFrameAnimation animation = compositor.CreateQuaternionKeyFrameAnimation();
+
+ animation.Duration = duration;
+
+ if (delay.HasValue)
+ {
+ animation.DelayTime = delay.Value;
+ }
+
+ if (ease is null)
+ {
+ animation.InsertKeyFrame(1, to);
+ }
+ else
+ {
+ animation.InsertKeyFrame(1, to, ease);
+ }
if (from.HasValue)
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
index 4306f0310f7..071471ba778 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
@@ -21,8 +21,8 @@ public static class DependencyObjectExtensions
///
/// The target to animate.
/// The property to animate inside the target .
- /// The optional initial property value.
/// The final property value.
+ /// The optional initial property value.
/// The optional delay for the animation.
/// The duration of the .
/// The easing function to use inside the .
@@ -32,8 +32,8 @@ public static class DependencyObjectExtensions
public static DoubleAnimation CreateDoubleAnimation(
this DependencyObject target,
string property,
- double? from,
double to,
+ double? from,
TimeSpan? delay,
TimeSpan duration,
EasingFunctionBase? easing = null,
From 406a298f1571ad461c419e2740a56357aca306a6 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 13:46:39 +0100
Subject: [PATCH 052/171] Added missing XAML animation creation extensions
---
.../Extensions/DependencyObjectExtensions.cs | 79 ++++++++++++++++++-
1 file changed, 78 insertions(+), 1 deletion(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
index 071471ba778..642dde9b8f7 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/DependencyObjectExtensions.cs
@@ -6,6 +6,8 @@
using System;
using System.Diagnostics.Contracts;
+using Windows.Foundation;
+using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;
@@ -41,12 +43,87 @@ public static DoubleAnimation CreateDoubleAnimation(
{
DoubleAnimation animation = new()
{
+ To = to,
From = from,
+ BeginTime = delay,
+ Duration = duration,
+ EasingFunction = easing,
+ EnableDependentAnimation = enableDependecyAnimations
+ };
+
+ Storyboard.SetTarget(animation, target);
+ Storyboard.SetTargetProperty(animation, property);
+
+ return animation;
+ }
+
+ ///
+ /// Prepares a with the given info.
+ ///
+ /// The target to animate.
+ /// The property to animate inside the target .
+ /// The final property value.
+ /// The optional initial property value.
+ /// The optional delay for the animation.
+ /// The duration of the .
+ /// The easing function to use inside the .
+ /// Indicates whether or not to apply this animation to elements that need the visual tree to be rearranged.
+ /// A instance with the specified parameters.
+ [Pure]
+ public static PointAnimation CreatePointAnimation(
+ this DependencyObject target,
+ string property,
+ Point to,
+ Point? from,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingFunctionBase? easing = null,
+ bool enableDependecyAnimations = false)
+ {
+ PointAnimation animation = new()
+ {
To = to,
+ From = from,
BeginTime = delay,
Duration = duration,
EasingFunction = easing,
- EnableDependentAnimation = enableDependecyAnimations,
+ EnableDependentAnimation = enableDependecyAnimations
+ };
+
+ Storyboard.SetTarget(animation, target);
+ Storyboard.SetTargetProperty(animation, property);
+
+ return animation;
+ }
+
+ ///
+ /// Prepares a with the given info.
+ ///
+ /// The target to animate.
+ /// The property to animate inside the target .
+ /// The final property value.
+ /// The optional initial property value.
+ /// The optional delay for the animation.
+ /// The duration of the .
+ /// The easing function to use inside the .
+ /// A instance with the specified parameters.
+ [Pure]
+ public static ColorAnimation CreateColorAnimation(
+ this DependencyObject target,
+ string property,
+ Color to,
+ Color? from,
+ TimeSpan? delay,
+ TimeSpan duration,
+ EasingFunctionBase? easing = null)
+ {
+ ColorAnimation animation = new()
+ {
+ To = to,
+ From = from,
+ BeginTime = delay,
+ Duration = duration,
+ EasingFunction = easing
};
Storyboard.SetTarget(animation, target);
From a60c4280e3394c0ad191411ff0e4d8901408c83f Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 14:15:10 +0100
Subject: [PATCH 053/171] Code refactoring, improved AnimationBuilder
flexibility
---
.../Builders/AnimationBuilder.Default.cs | 50 ++--
.../Builders/AnimationBuilder.Models.cs | 248 ++++++++++++++----
.../Builders/AnimationBuilder.Setup.cs | 62 +----
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 18 --
4 files changed, 229 insertions(+), 149 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index f5ed4a85fdd..d45af783d56 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -40,11 +40,11 @@ public AnimationBuilder Opacity(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlDoubleAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode, false);
+ return AddXamlAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode);
}
}
@@ -72,11 +72,11 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"Translation.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory($"Translation.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlDoubleAnimationFactory($"Translate{axis}", to, from, delay, duration, easingType, easingMode, false);
+ return AddXamlAnimationFactory($"Translate{axis}", to, from, delay, duration, easingType, easingMode);
}
}
@@ -102,8 +102,8 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory("Translation.X", to.X, from?.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory("Translation.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory("Translation.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory("Translation.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
@@ -133,7 +133,7 @@ public AnimationBuilder Translation(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory("Translation", to, from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory("Translation", to, from, delay, duration, easingType, easingMode);
}
///
@@ -157,7 +157,7 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory($"{nameof(Visual.Offset)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
///
@@ -179,8 +179,8 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Offset)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Offset)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Offset)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
return this;
}
@@ -204,7 +204,7 @@ public AnimationBuilder Offset(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Offset), to, from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.Offset), to, from, delay, duration, easingType, easingMode);
}
///
@@ -232,7 +232,7 @@ public AnimationBuilder Scale(
Vector3? from3 = from is null ? null : new((float)(double)from);
Vector3 to3 = new((float)to);
- return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode);
}
else
{
@@ -267,7 +267,7 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -297,8 +297,8 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Scale)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Scale)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Scale)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
@@ -328,7 +328,7 @@ public AnimationBuilder Scale(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Scale), to, from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.Scale), to, from, delay, duration, easingType, easingMode);
}
///
@@ -353,7 +353,7 @@ public AnimationBuilder Rotate(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -388,7 +388,7 @@ public AnimationBuilder RotateInDegrees(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -466,7 +466,7 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -477,7 +477,7 @@ public AnimationBuilder Size(
_ => ThrowHelper.ThrowArgumentException("Invalid size axis")
};
- return AddXamlDoubleAnimationFactory(property, to, from, delay, duration, easingType, easingMode, true);
+ return AddXamlAnimationFactory(property, to, from, delay, duration, easingType, easingMode);
}
}
@@ -503,13 +503,13 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
- AddCompositionScalarAnimationFactory($"{nameof(Visual.Size)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Size)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Size)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
}
else
{
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Width), to.X, from?.X, delay, duration, easingType, easingMode, true);
- AddXamlDoubleAnimationFactory(nameof(FrameworkElement.Height), to.Y, from?.Y, delay, duration, easingType, easingMode, true);
+ AddXamlAnimationFactory(nameof(FrameworkElement.Width), to.X, from?.X, delay, duration, easingType, easingMode);
+ AddXamlAnimationFactory(nameof(FrameworkElement.Height), to.Y, from?.Y, delay, duration, easingType, easingMode);
}
return this;
@@ -534,7 +534,7 @@ public AnimationBuilder Size(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- return AddCompositionVector3AnimationFactory(nameof(Visual.Size), to, from, delay, duration, easingType, easingMode);
+ return AddCompositionAnimationFactory(nameof(Visual.Size), to, from, delay, duration, easingType, easingMode);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index 1b1ad4cb574..d77f1445c26 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -3,8 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Diagnostics.Contracts;
using System.Numerics;
+using System.Runtime.CompilerServices;
+using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
+using Windows.Foundation;
+using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
@@ -16,72 +21,220 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
public sealed partial class AnimationBuilder
{
///
- /// A model representing a specified composition double animation for a target .
+ /// A model representing a generic animation for a target object.
///
- private sealed record CompositionDoubleAnimation(
- CompositionObject Target,
+ private sealed record AnimationFactory(
string Property,
- float To,
- float? From,
+ T To,
+ T? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
- : ICompositionAnimation
+ : ICompositionAnimationFactory, IXamlAnimationFactory
+ where T : unmanaged
{
///
- public void StartAnimation()
+ public CompositionAnimation GetAnimation(Visual visual)
{
- CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+ CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- Target.StartAnimation(Property, animation);
+ if (typeof(T) == typeof(bool))
+ {
+ return visual.Compositor.CreateBooleanKeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration);
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ return visual.Compositor.CreateScalarKeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(double))
+ {
+ return visual.Compositor.CreateScalarKeyFrameAnimation(
+ Property,
+ (float)GetToAs(),
+ (float)GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(Vector2))
+ {
+ return visual.Compositor.CreateVector2KeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(Vector3))
+ {
+ return visual.Compositor.CreateVector3KeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(Vector4))
+ {
+ return visual.Compositor.CreateVector4KeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ return visual.Compositor.CreateColorKeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else if (typeof(T) == typeof(Quaternion))
+ {
+ return visual.Compositor.CreateQuaternionKeyFrameAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
}
- }
- ///
- /// A model representing a specified composition scalar animation factory.
- ///
- private sealed record CompositionScalarAnimationFactory(
- string Property,
- float To,
- float? From,
- TimeSpan Delay,
- TimeSpan Duration,
- EasingType EasingType,
- EasingMode EasingMode)
- : ICompositionAnimationFactory
- {
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public Timeline GetAnimation(UIElement element)
{
- CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+ EasingFunctionBase easingFunction = EasingType.ToEasingFunction(EasingMode);
- return animation;
+ if (typeof(T) == typeof(float))
+ {
+ return element.CreateDoubleAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction,
+ true);
+ }
+ else if (typeof(T) == typeof(double))
+ {
+ return element.CreateDoubleAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction,
+ true);
+ }
+ else if (typeof(T) == typeof(Point))
+ {
+ return element.CreatePointAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction,
+ true);
+ }
+ else if (typeof(T) == typeof(Color))
+ {
+ return element.CreateColorAnimation(
+ Property,
+ GetToAs(),
+ GetFromAs(),
+ Delay,
+ Duration,
+ easingFunction);
+ }
+ else
+ {
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
+ }
+ }
+
+ ///
+ /// Gets the current target value as .
+ ///
+ /// The target value type to use.
+ /// The target type cast to .
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private TValue GetToAs()
+ where TValue : unmanaged
+ {
+ T to = To;
+
+ return Unsafe.As(ref to);
+ }
+
+ ///
+ /// Gets the current starting value as .
+ ///
+ /// The starting value type to use.
+ /// The starting type cast to nullable .
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private TValue? GetFromAs()
+ where TValue : unmanaged
+ {
+ if (From is null)
+ {
+ return null;
+ }
+
+ T from = From.GetValueOrDefault();
+
+ return Unsafe.As(ref from);
}
}
///
- /// A model representing a specified composition animation factory.
+ /// A model representing a specified composition double animation for a target .
///
- private sealed record CompositionVector3AnimationFactory(
+ private sealed record CompositionDoubleAnimation(
+ CompositionObject Target,
string Property,
- Vector3 To,
- Vector3? From,
+ float To,
+ float? From,
TimeSpan Delay,
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
- : ICompositionAnimationFactory
+ : ICompositionAnimation
{
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public void StartAnimation()
{
- CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- Vector3KeyFrameAnimation animation = visual.Compositor.CreateVector3KeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+ CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
- return animation;
+ Target.StartAnimation(Property, animation);
}
}
@@ -109,27 +262,6 @@ public CompositionAnimation GetAnimation(Visual visual)
}
}
- ///
- /// A model representing a specified XAML animation factory.
- ///
- private sealed record XamlDoubleAnimationFactory(
- string Property,
- double To,
- double? From,
- TimeSpan Delay,
- TimeSpan Duration,
- EasingType EasingType,
- EasingMode EasingMode,
- bool EnableDependentAnimation)
- : IXamlAnimationFactory
- {
- ///
- public Timeline GetAnimation(UIElement element)
- {
- return element.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode), EnableDependentAnimation);
- }
- }
-
///
/// A model representing a specified XAML animation factory targeting a transform.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
index 47efc17574d..593cb959d60 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
-using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -31,8 +30,9 @@ public sealed partial class AnimationBuilder
private readonly List xamlAnimationFactories = new();
///
- /// Adds a new composition scalar animation to the current schedule.
+ /// Adds a new composition animation to the current schedule.
///
+ /// The type of values to animate.
/// The target property to animate.
/// The final value for the animation.
/// The optional starting value for the animation.
@@ -41,16 +41,17 @@ public sealed partial class AnimationBuilder
/// The easing function for the animation.
/// The easing mode for the animation.
/// The current instance.
- private AnimationBuilder AddCompositionScalarAnimationFactory(
+ private AnimationBuilder AddCompositionAnimationFactory(
string property,
- float to,
- float? from,
+ T to,
+ T? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
EasingMode easingMode)
+ where T : unmanaged
{
- CompositionScalarAnimationFactory animation = new(
+ AnimationFactory animation = new(
property,
to,
from,
@@ -65,8 +66,9 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
}
///
- /// Adds a new composition animation to the current schedule.
+ /// Adds a new XAML animation to the current schedule.
///
+ /// The type of values to animate.
/// The target property to animate.
/// The final value for the animation.
/// The optional starting value for the animation.
@@ -75,16 +77,17 @@ private AnimationBuilder AddCompositionScalarAnimationFactory(
/// The easing function for the animation.
/// The easing mode for the animation.
/// The current instance.
- private AnimationBuilder AddCompositionVector3AnimationFactory(
+ private AnimationBuilder AddXamlAnimationFactory(
string property,
- Vector3 to,
- Vector3? from,
+ T to,
+ T? from,
TimeSpan? delay,
TimeSpan? duration,
EasingType easingType,
EasingMode easingMode)
+ where T : unmanaged
{
- CompositionVector3AnimationFactory animation = new(
+ AnimationFactory animation = new(
property,
to,
from,
@@ -93,43 +96,6 @@ private AnimationBuilder AddCompositionVector3AnimationFactory(
easingType,
easingMode);
- this.compositionAnimationFactories.Add(animation);
-
- return this;
- }
-
- ///
- /// Adds a new XAML animation to the current schedule.
- ///
- /// The target property to animate.
- /// The final value for the animation.
- /// The optional starting value for the animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The easing function for the animation.
- /// The easing mode for the animation.
- /// Whether to set .
- /// The current instance.
- private AnimationBuilder AddXamlDoubleAnimationFactory(
- string property,
- double to,
- double? from,
- TimeSpan? delay,
- TimeSpan? duration,
- EasingType easingType,
- EasingMode easingMode,
- bool enableDependentAnimation)
- {
- XamlDoubleAnimationFactory animation = new(
- property,
- to,
- from,
- delay ?? DefaultDelay,
- duration ?? DefaultDuration,
- easingType,
- easingMode,
- enableDependentAnimation);
-
this.xamlAnimationFactories.Add(animation);
return this;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 43e7dff65f8..15c23046387 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -70,24 +70,6 @@ public static Timeline GetAnimation(
animation = doubleAnimation;
}
- else if (typeof(T) == typeof(Vector2))
- {
- PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
-
- foreach (var keyFrame in keyFrames)
- {
- Vector2 vector = keyFrame.GetValueAs();
-
- pointAnimation.KeyFrames.Add(new EasingPointKeyFrame()
- {
- KeyTime = keyFrame.GetTimedProgress(duration),
- Value = new Point(vector.X, vector.Y),
- EasingFunction = keyFrame.EasingType.ToEasingFunction(keyFrame.EasingMode)
- });
- }
-
- animation = pointAnimation;
- }
else if (typeof(T) == typeof(Point))
{
PointAnimationUsingKeyFrames pointAnimation = new() { EnableDependentAnimation = true };
From 9105cf0313b04e2adf3025e357973286f6a218ee Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 15:58:27 +0100
Subject: [PATCH 054/171] Minor code refactoring
---
.../Xaml/Abstract/{TypedAnimation{T}.cs => Animation{T}.cs} | 2 +-
.../Xaml/Default/OpacityAnimation.cs | 2 +-
.../Xaml/Default/ScaleAnimation.cs | 2 +-
.../Xaml/Default/TranslationAnimation.cs | 2 +-
.../Animations/EffectDoubleAnimation.cs | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
rename Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/{TypedAnimation{T}.cs => Animation{T}.cs} (93%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
similarity index 93%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
index d37a5efc8e9..8eac45cb5dc 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/TypedAnimation{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
/// A base model representing a typed animation that can be used in XAML.
///
/// The type of values for the animation.
- public abstract class TypedAnimation : Animation
+ public abstract class Animation : Animation
{
///
/// Gets or sets the final value for the animation.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index 9a837ce65da..e5c1f0af3ad 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
/// An opacity animation working on the composition or XAML layer.
/// This animation maps to .
///
- public class OpacityAnimation : TypedAnimation, ITimeline
+ public class OpacityAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
index 7a5024c59af..cbeb0a6d234 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
/// A scale animation working on the composition or XAML layer.
/// This animation maps to .
///
- public class ScaleAnimation : TypedAnimation, ITimeline
+ public class ScaleAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 75964ed10dd..255c52565f1 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
/// A translation animation working on the composition or XAML layer.
/// This animation maps to .
///
- public class TranslationAnimation : TypedAnimation, ITimeline
+ public class TranslationAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index 88c2083b992..0f804a9487d 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -15,7 +15,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Animations
///
/// A set of animations that can be grouped together.
///
- public class EffectDoubleAnimation : TypedAnimation, ITimeline
+ public class EffectDoubleAnimation : Animation, ITimeline
{
///
/// Gets or sets the linked instance to animate.
From 1d3de3c1e5ae4eb4332089d6b107a08560372c8c Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 17:46:06 +0100
Subject: [PATCH 055/171] Improved internal AnimationBuilder architecture
---
.../Builders/AnimationBuilder.Models.cs | 100 +++++++++---------
.../Builders/AnimationBuilder.Setup.cs | 5 -
.../Builders/AnimationBuilder.cs | 51 +++++----
...KeyFrameAnimationBuilder{T}.Composition.cs | 42 ++++----
...malizedKeyFrameAnimationBuilder{T}.Xaml.cs | 4 +-
...KeyFrameAnimationBuilder{T}.Composition.cs | 8 +-
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 11 +-
.../Animations/EffectDoubleAnimation.cs | 2 +-
8 files changed, 113 insertions(+), 110 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index d77f1445c26..8fe4b6dc2e4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -15,6 +15,8 @@
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
+#nullable enable
+
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
@@ -35,13 +37,15 @@ private sealed record AnimationFactory(
where T : unmanaged
{
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
{
- CompositionEasingFunction easingFunction = visual.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ CompositionEasingFunction easingFunction = targetHint.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+
+ target = null;
if (typeof(T) == typeof(bool))
{
- return visual.Compositor.CreateBooleanKeyFrameAnimation(
+ return targetHint.Compositor.CreateBooleanKeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -50,7 +54,7 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(float))
{
- return visual.Compositor.CreateScalarKeyFrameAnimation(
+ return targetHint.Compositor.CreateScalarKeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -60,17 +64,17 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(double))
{
- return visual.Compositor.CreateScalarKeyFrameAnimation(
+ return targetHint.Compositor.CreateScalarKeyFrameAnimation(
Property,
(float)GetToAs(),
- (float)GetFromAs(),
+ (float?)GetFromAs(),
Delay,
Duration,
easingFunction);
}
else if (typeof(T) == typeof(Vector2))
{
- return visual.Compositor.CreateVector2KeyFrameAnimation(
+ return targetHint.Compositor.CreateVector2KeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -80,7 +84,7 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(Vector3))
{
- return visual.Compositor.CreateVector3KeyFrameAnimation(
+ return targetHint.Compositor.CreateVector3KeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -90,7 +94,7 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(Vector4))
{
- return visual.Compositor.CreateVector4KeyFrameAnimation(
+ return targetHint.Compositor.CreateVector4KeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -100,7 +104,7 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(Color))
{
- return visual.Compositor.CreateColorKeyFrameAnimation(
+ return targetHint.Compositor.CreateColorKeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -110,7 +114,7 @@ public CompositionAnimation GetAnimation(Visual visual)
}
else if (typeof(T) == typeof(Quaternion))
{
- return visual.Compositor.CreateQuaternionKeyFrameAnimation(
+ return targetHint.Compositor.CreateQuaternionKeyFrameAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -125,13 +129,13 @@ public CompositionAnimation GetAnimation(Visual visual)
}
///
- public Timeline GetAnimation(UIElement element)
+ public Timeline GetAnimation(DependencyObject targetHint)
{
- EasingFunctionBase easingFunction = EasingType.ToEasingFunction(EasingMode);
+ EasingFunctionBase? easingFunction = EasingType.ToEasingFunction(EasingMode);
if (typeof(T) == typeof(float))
{
- return element.CreateDoubleAnimation(
+ return targetHint.CreateDoubleAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -142,7 +146,7 @@ public Timeline GetAnimation(UIElement element)
}
else if (typeof(T) == typeof(double))
{
- return element.CreateDoubleAnimation(
+ return targetHint.CreateDoubleAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -153,7 +157,7 @@ public Timeline GetAnimation(UIElement element)
}
else if (typeof(T) == typeof(Point))
{
- return element.CreatePointAnimation(
+ return targetHint.CreatePointAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -164,7 +168,7 @@ public Timeline GetAnimation(UIElement element)
}
else if (typeof(T) == typeof(Color))
{
- return element.CreateColorAnimation(
+ return targetHint.CreateColorAnimation(
Property,
GetToAs(),
GetFromAs(),
@@ -215,10 +219,9 @@ private TValue GetToAs()
}
///
- /// A model representing a specified composition double animation for a target .
+ /// A model representing a specified composition scalar animation factory targeting a clip.
///
- private sealed record CompositionDoubleAnimation(
- CompositionObject Target,
+ private sealed record CompositionClipScalarAnimation(
string Property,
float To,
float? From,
@@ -226,22 +229,27 @@ private sealed record CompositionDoubleAnimation(
TimeSpan Duration,
EasingType EasingType,
EasingMode EasingMode)
- : ICompositionAnimation
+ : ICompositionAnimationFactory
{
///
- public void StartAnimation()
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
{
- CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+ Visual visual = (Visual)targetHint;
+ InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip());
+ CompositionEasingFunction easingFunction = clip.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ ScalarKeyFrameAnimation animation = clip.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
- Target.StartAnimation(Property, animation);
+ target = clip;
+
+ return animation;
}
}
///
- /// A model representing a specified composition scalar animation factory targeting a clip.
+ /// A model representing a specified composition double animation for a target .
///
- private sealed record CompositionClipScalarAnimation(
+ private sealed record CompositionDoubleAnimation(
+ CompositionObject Target,
string Property,
float To,
float? From,
@@ -252,11 +260,12 @@ private sealed record CompositionClipScalarAnimation(
: ICompositionAnimationFactory
{
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
{
- InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip());
- CompositionEasingFunction easingFunction = clip.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = visual.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+ CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
+ ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
+
+ target = Target;
return animation;
}
@@ -276,9 +285,9 @@ private sealed record XamlTransformDoubleAnimationFactory(
: IXamlAnimationFactory
{
///
- public Timeline GetAnimation(UIElement element)
+ public Timeline GetAnimation(DependencyObject targetHint)
{
- CompositeTransform transform = element.GetTransform();
+ CompositeTransform transform = ((UIElement)targetHint).GetTransform();
return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode));
}
@@ -292,9 +301,9 @@ internal interface IXamlAnimationFactory
///
/// Gets a instance representing the animation to start.
///
- /// The target instance to animate.
+ /// The suggested target instance to animate.
/// A instance with the specified animation.
- Timeline GetAnimation(UIElement element);
+ Timeline GetAnimation(DependencyObject targetHint);
}
///
@@ -305,20 +314,15 @@ internal interface ICompositionAnimationFactory
///
/// Gets a instance representing the animation to start.
///
- /// The target instance to animate.
+ /// The suggested target instance to animate.
+ /// An optional instance to animate instead of the suggested one.
/// A instance with the specified animation.
- CompositionAnimation GetAnimation(Visual visual);
- }
-
- ///
- /// An interface for custom external composition animations.
- ///
- internal interface ICompositionAnimation
- {
- ///
- /// Starts a with some embedded parameters.
- ///
- void StartAnimation();
+ ///
+ /// The separate parameter is needed because unlike with XAML animations, composition animations
+ /// can't store the target instance internally, and need to be started on the target object directly. This means that custom
+ /// animation factories that want to target an external object need to return that object separately to inform the callers.
+ ///
+ CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
index 593cb959d60..240ea88bb65 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs
@@ -14,11 +14,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
- ///
- /// The list of instances representing animations to run.
- ///
- private readonly List compositionAnimations = new();
-
///
/// The list of instances representing factories for composition animations to run.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index d8c57e25caf..24804087c31 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -82,7 +82,7 @@ public AnimationBuilder DoubleAnimation(
easingType,
easingMode);
- this.compositionAnimations.Add(animation);
+ this.compositionAnimationFactories.Add(animation);
return this;
}
@@ -93,27 +93,25 @@ public AnimationBuilder DoubleAnimation(
/// The target to animate.
public void Start(UIElement element)
{
- if (this.compositionAnimations.Count > 0)
- {
- foreach (var animation in this.compositionAnimations)
- {
- animation.StartAnimation();
- }
- }
-
if (this.compositionAnimationFactories.Count > 0)
{
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
Visual visual = ElementCompositionPreview.GetElementVisual(element);
- CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
foreach (var factory in this.compositionAnimationFactories)
{
- group.Add(factory.GetAnimation(visual));
+ var animation = factory.GetAnimation(visual, out var target);
+
+ if (target is null)
+ {
+ visual.StartAnimation(animation.Target, animation);
+ }
+ else
+ {
+ target.StartAnimation(animation.Target, animation);
+ }
}
-
- visual.StartAnimationGroup(group);
}
if (this.xamlAnimationFactories.Count > 0)
@@ -140,31 +138,30 @@ public Task StartAsync(UIElement element)
compositionTask = Task.CompletedTask,
xamlTask = Task.CompletedTask;
- if (this.compositionAnimationFactories.Count > 0 ||
- this.compositionAnimations.Count > 0)
+ if (this.compositionAnimationFactories.Count > 0)
{
+ ElementCompositionPreview.SetIsTranslationEnabled(element, true);
+
Visual visual = ElementCompositionPreview.GetElementVisual(element);
CompositionScopedBatch batch = visual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
TaskCompletionSource taskCompletionSource = new();
batch.Completed += (_, _) => taskCompletionSource.SetResult(null);
- foreach (var animation in this.compositionAnimations)
- {
- animation.StartAnimation();
- }
-
- ElementCompositionPreview.SetIsTranslationEnabled(element, true);
-
- CompositionAnimationGroup group = visual.Compositor.CreateAnimationGroup();
-
foreach (var factory in this.compositionAnimationFactories)
{
- group.Add(factory.GetAnimation(visual));
+ var animation = factory.GetAnimation(visual, out var target);
+
+ if (target is null)
+ {
+ visual.StartAnimation(animation.Target, animation);
+ }
+ else
+ {
+ target.StartAnimation(animation.Target, animation);
+ }
}
- visual.StartAnimationGroup(group);
-
batch.End();
compositionTask = taskCompletionSource.Task;
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index 015dc487541..8269d9538c8 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -10,6 +10,8 @@
using Windows.UI;
using Windows.UI.Composition;
+#nullable enable
+
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
@@ -19,14 +21,14 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder
/// Gets a instance representing the animation to start.
///
/// The type of keyframes being used to define the animation.
- /// The target instance to animate.
+ /// The target instance to animate.
/// The target property to animate.
/// The optional initial delay for the animation.
/// The animation duration.
/// The list of keyframes to use to build the animation.
/// A instance with the specified animation.
public static CompositionAnimation GetAnimation(
- Visual visual,
+ CompositionObject target,
string property,
TimeSpan? delay,
TimeSpan duration,
@@ -37,7 +39,7 @@ public static CompositionAnimation GetAnimation(
if (typeof(T) == typeof(bool))
{
- BooleanKeyFrameAnimation boolAnimation = visual.Compositor.CreateBooleanKeyFrameAnimation();
+ BooleanKeyFrameAnimation boolAnimation = target.Compositor.CreateBooleanKeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
@@ -50,98 +52,98 @@ public static CompositionAnimation GetAnimation(
}
else if (typeof(T) == typeof(float))
{
- ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
+ ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
scalarAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = scalarAnimation;
}
else if (typeof(T) == typeof(double))
{
- ScalarKeyFrameAnimation scalarAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
+ ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
scalarAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
(float)keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = scalarAnimation;
}
else if (typeof(T) == typeof(Vector2))
{
- Vector2KeyFrameAnimation vector2Animation = visual.Compositor.CreateVector2KeyFrameAnimation();
+ Vector2KeyFrameAnimation vector2Animation = target.Compositor.CreateVector2KeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
vector2Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = vector2Animation;
}
else if (typeof(T) == typeof(Vector3))
{
- Vector3KeyFrameAnimation vector3Animation = visual.Compositor.CreateVector3KeyFrameAnimation();
+ Vector3KeyFrameAnimation vector3Animation = target.Compositor.CreateVector3KeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
vector3Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = vector3Animation;
}
else if (typeof(T) == typeof(Vector4))
{
- Vector4KeyFrameAnimation vector4Animation = visual.Compositor.CreateVector4KeyFrameAnimation();
+ Vector4KeyFrameAnimation vector4Animation = target.Compositor.CreateVector4KeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
vector4Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = vector4Animation;
}
else if (typeof(T) == typeof(Color))
{
- ColorKeyFrameAnimation colorAnimation = visual.Compositor.CreateColorKeyFrameAnimation();
+ ColorKeyFrameAnimation colorAnimation = target.Compositor.CreateColorKeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
colorAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = colorAnimation;
}
else if (typeof(T) == typeof(Quaternion))
{
- QuaternionKeyFrameAnimation quaternionAnimation = visual.Compositor.CreateQuaternionKeyFrameAnimation();
+ QuaternionKeyFrameAnimation quaternionAnimation = target.Compositor.CreateQuaternionKeyFrameAnimation();
foreach (var keyFrame in keyFrames)
{
quaternionAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
keyFrame.GetValueAs(),
- visual.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
+ target.Compositor.CreateCubicBezierEasingFunction(keyFrame.EasingType, keyFrame.EasingMode));
}
animation = quaternionAnimation;
@@ -178,10 +180,12 @@ public Composition(string property, TimeSpan? delay, TimeSpan duration)
}
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
{
+ target = null;
+
return GetAnimation(
- visual,
+ targetHint,
this.property,
this.delay,
this.duration,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
index e4ca796c97b..1f98e954866 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -27,10 +27,10 @@ public Xaml(string property, TimeSpan? delay, TimeSpan duration)
}
///
- public Timeline GetAnimation(UIElement element)
+ public Timeline GetAnimation(DependencyObject targetHint)
{
return TimedKeyFrameAnimationBuilder.GetAnimation(
- element,
+ targetHint,
this.property,
this.delay,
this.duration,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
index 6c01782e47f..d3ba7ac0084 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -5,6 +5,8 @@
using System;
using Windows.UI.Composition;
+#nullable enable
+
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
@@ -26,14 +28,16 @@ public Composition(string property, TimeSpan? delay)
}
///
- public CompositionAnimation GetAnimation(Visual visual)
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
{
+ target = null;
+
// 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.
TimeSpan duration = this.keyFrames[this.keyFrames.Count - 1].GetTimedProgress(default);
return NormalizedKeyFrameAnimationBuilder.GetAnimation(
- visual,
+ targetHint,
this.property,
this.delay,
duration,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 15c23046387..6678f6bc2ed 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
-using System.Numerics;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
using Windows.Foundation;
@@ -22,14 +21,14 @@ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFram
/// Gets a instance representing the animation to start.
///
/// The type of keyframes being used to define the animation.
- /// The target instance to animate.
+ /// The target instance to animate.
/// The target property to animate.
/// The optional initial delay for the animation.
/// The animation duration.
/// The list of keyframes to use to build the animation.
/// A instance with the specified animation.
public static Timeline GetAnimation(
- UIElement element,
+ DependencyObject target,
string property,
TimeSpan? delay,
TimeSpan duration,
@@ -109,7 +108,7 @@ public static Timeline GetAnimation(
animation.BeginTime = delay;
- Storyboard.SetTarget(animation, element);
+ Storyboard.SetTarget(animation, target);
Storyboard.SetTargetProperty(animation, property);
return animation;
@@ -130,10 +129,10 @@ public Xaml(string property, TimeSpan? delay)
}
///
- public Timeline GetAnimation(UIElement element)
+ public Timeline GetAnimation(DependencyObject targetHint)
{
return GetAnimation(
- element,
+ targetHint,
this.property,
this.delay,
default,
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index 0f804a9487d..01c3d830575 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -30,8 +30,8 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
return builder.DoubleAnimation(
effect.Brush,
$"{effect.Id}.{nameof(GaussianBlurEffect.BlurAmount)}",
- From,
To,
+ From,
Delay ?? delayHint,
Duration ?? durationHint.GetValueOrDefault(),
EasingType ?? easingTypeHint ?? DefaultEasingType,
From 203b9077bff88ce614a838e0990c6efb6b4833f1 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 19:13:45 +0100
Subject: [PATCH 056/171] Added new Clip animation overload
---
.../Builders/AnimationBuilder.Default.cs | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index d45af783d56..b71dcf550c9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -442,6 +442,64 @@ public AnimationBuilder Clip(
return this;
}
+ ///
+ /// Adds a new clip animation to the current schedule.
+ ///
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Clip(
+ Thickness to,
+ Thickness? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ this.compositionAnimationFactories.Add(new CompositionClipScalarAnimation(
+ nameof(InsetClip.LeftInset),
+ (float)to.Left,
+ (float?)from?.Left,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode));
+
+ this.compositionAnimationFactories.Add(new CompositionClipScalarAnimation(
+ nameof(InsetClip.TopInset),
+ (float)to.Top,
+ (float?)from?.Top,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode));
+
+ this.compositionAnimationFactories.Add(new CompositionClipScalarAnimation(
+ nameof(InsetClip.RightInset),
+ (float)to.Right,
+ (float?)from?.Right,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode));
+
+ this.compositionAnimationFactories.Add(new CompositionClipScalarAnimation(
+ nameof(InsetClip.BottomInset),
+ (float)to.Bottom,
+ (float?)from?.Bottom,
+ delay ?? DefaultDelay,
+ duration ?? DefaultDuration,
+ easingType,
+ easingMode));
+
+ return this;
+ }
+
///
/// Adds a new size animation for a single axis to the current schedule.
///
From 89e097a7454b333dbd8b7b582cefcfa7c107e44a Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Mon, 21 Dec 2020 21:51:33 +0100
Subject: [PATCH 057/171] Added missing default animation XAML nodes
---
.../Xaml/Default/ClipAnimation.cs | 29 ++++++++++++++
.../Xaml/Default/OffsetAnimation.cs | 29 ++++++++++++++
.../Xaml/Default/OpacityAnimation.cs | 1 -
.../Xaml/Default/RotationAnimation.cs | 34 ++++++++++++++++
.../Default/RotationInDegreesAnimation.cs | 34 ++++++++++++++++
.../Xaml/Default/ScaleAnimation.cs | 1 -
.../Xaml/Default/SizeAnimation.cs | 40 +++++++++++++++++++
.../Xaml/Default/TranslationAnimation.cs | 1 -
8 files changed, 166 insertions(+), 3 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs
new file mode 100644
index 00000000000..96761a3d469
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs
@@ -0,0 +1,29 @@
+// 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 System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A clip animation working on the composition layer.
+ ///
+ public class ClipAnimation : Animation, ITimeline
+ {
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ return builder.Clip(
+ To!.Value,
+ From,
+ Delay ?? delayHint,
+ Duration ?? durationHint,
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
new file mode 100644
index 00000000000..4ab0528c873
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
@@ -0,0 +1,29 @@
+// 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 System;
+using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// An offset animation working on the composition layer.
+ ///
+ public class OffsetAnimation : Animation, ITimeline
+ {
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ return builder.Translation(
+ To!.ToVector3(),
+ From?.ToVector3(),
+ Delay ?? delayHint,
+ Duration ?? durationHint,
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
index e5c1f0af3ad..5dc950b6061 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OpacityAnimation.cs
@@ -10,7 +10,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// An opacity animation working on the composition or XAML layer.
- /// This animation maps to .
///
public class OpacityAnimation : Animation, ITimeline
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
new file mode 100644
index 00000000000..984404b8d29
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
@@ -0,0 +1,34 @@
+// 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 System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A rotation animation working on the composition or XAML layer.
+ ///
+ public class RotationAnimation : Animation, ITimeline
+ {
+ ///
+ /// Gets or sets the target framework layer to animate.
+ ///
+ public FrameworkLayer Layer { get; set; }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ return builder.Rotate(
+ To!.Value,
+ From,
+ Delay ?? delayHint,
+ Duration ?? durationHint,
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode,
+ Layer);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
new file mode 100644
index 00000000000..a42f3847c70
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
@@ -0,0 +1,34 @@
+// 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 System;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A rotation in degrees animation working on the composition or XAML layer.
+ ///
+ public class RotationInDegreesAnimation : Animation, ITimeline
+ {
+ ///
+ /// Gets or sets the target framework layer to animate.
+ ///
+ public FrameworkLayer Layer { get; set; }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ return builder.RotateInDegrees(
+ To!.Value,
+ From,
+ Delay ?? delayHint,
+ Duration ?? durationHint,
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
+ EasingMode ?? easingModeHint ?? DefaultEasingMode,
+ Layer);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
index cbeb0a6d234..cd4b5a46ef1 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -11,7 +11,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A scale animation working on the composition or XAML layer.
- /// This animation maps to .
///
public class ScaleAnimation : Animation, ITimeline
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
new file mode 100644
index 00000000000..fddbaa03979
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
@@ -0,0 +1,40 @@
+// 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 System;
+using Microsoft.Toolkit.Uwp.UI.Extensions;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A size animation working on the composition or XAML layer.
+ ///
+ public class SizeAnimation : Animation, ITimeline
+ {
+ ///
+ /// Gets or sets the target framework layer to animate.
+ ///
+ public FrameworkLayer Layer { get; set; }
+
+ ///
+ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
+ {
+ TimeSpan? delay = Delay ?? delayHint;
+ TimeSpan? duration = Duration ?? durationHint;
+ EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
+ EasingMode easingMode = EasingMode ?? easingModeHint ?? DefaultEasingMode;
+
+ if (Layer == FrameworkLayer.Composition)
+ {
+ return builder.Size(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ return builder.Size(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ }
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 255c52565f1..3b7c5974952 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -11,7 +11,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
/// A translation animation working on the composition or XAML layer.
- /// This animation maps to .
///
public class TranslationAnimation : Animation, ITimeline
{
From 22b605153046a9d3e583e09ba926e236c7410a8b Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 00:01:25 +0100
Subject: [PATCH 058/171] Minor code tweaks
---
.../NormalizedKeyFrameAnimationBuilder{T}.Composition.cs | 2 +-
.../Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs | 4 ++--
.../Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs | 4 ++--
.../Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index 8269d9538c8..a13a322c70a 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -171,7 +171,7 @@ public static CompositionAnimation GetAnimation(
public sealed class Composition : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
public Composition(string property, TimeSpan? delay, TimeSpan duration)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
index 1f98e954866..a3bfca3c7a5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormalizedKeyFrameAnimationBuilder
+ internal abstract partial class NormalizedKeyFrameAnimationBuilder
where T : unmanaged
{
///
@@ -18,7 +18,7 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormali
public sealed class Xaml : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
public Xaml(string property, TimeSpan? delay, TimeSpan duration)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
index d3ba7ac0084..eb89c2288ad 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFrameAnimationBuilder
+ internal abstract partial class TimedKeyFrameAnimationBuilder
where T : unmanaged
{
///
@@ -19,7 +19,7 @@ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFram
public sealed class Composition : TimedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
public Composition(string property, TimeSpan? delay)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 6678f6bc2ed..333c7d25dce 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -14,7 +14,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFrameAnimationBuilder
+ internal abstract partial class TimedKeyFrameAnimationBuilder
where T : unmanaged
{
///
@@ -120,7 +120,7 @@ public static Timeline GetAnimation(
public sealed class Xaml : TimedKeyFrameAnimationBuilder, AnimationBuilder.IXamlAnimationFactory
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
public Xaml(string property, TimeSpan? delay)
From a59bb79ce5b5c39327c389ea0c76d4c56f79d91a Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 00:04:08 +0100
Subject: [PATCH 059/171] More small code tweaks
---
.../Builders/AnimationBuilder.Models.cs | 42 +++++++++++--------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index 8fe4b6dc2e4..adcad50390c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -52,7 +52,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Delay,
Duration);
}
- else if (typeof(T) == typeof(float))
+
+ if (typeof(T) == typeof(float))
{
return targetHint.Compositor.CreateScalarKeyFrameAnimation(
Property,
@@ -62,7 +63,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(double))
+
+ if (typeof(T) == typeof(double))
{
return targetHint.Compositor.CreateScalarKeyFrameAnimation(
Property,
@@ -72,7 +74,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(Vector2))
+
+ if (typeof(T) == typeof(Vector2))
{
return targetHint.Compositor.CreateVector2KeyFrameAnimation(
Property,
@@ -82,7 +85,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(Vector3))
+
+ if (typeof(T) == typeof(Vector3))
{
return targetHint.Compositor.CreateVector3KeyFrameAnimation(
Property,
@@ -92,7 +96,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(Vector4))
+
+ if (typeof(T) == typeof(Vector4))
{
return targetHint.Compositor.CreateVector4KeyFrameAnimation(
Property,
@@ -102,7 +107,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(Color))
+
+ if (typeof(T) == typeof(Color))
{
return targetHint.Compositor.CreateColorKeyFrameAnimation(
Property,
@@ -112,7 +118,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else if (typeof(T) == typeof(Quaternion))
+
+ if (typeof(T) == typeof(Quaternion))
{
return targetHint.Compositor.CreateQuaternionKeyFrameAnimation(
Property,
@@ -122,10 +129,8 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
Duration,
easingFunction);
}
- else
- {
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
- }
+
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
}
///
@@ -144,7 +149,8 @@ public Timeline GetAnimation(DependencyObject targetHint)
easingFunction,
true);
}
- else if (typeof(T) == typeof(double))
+
+ if (typeof(T) == typeof(double))
{
return targetHint.CreateDoubleAnimation(
Property,
@@ -155,7 +161,8 @@ public Timeline GetAnimation(DependencyObject targetHint)
easingFunction,
true);
}
- else if (typeof(T) == typeof(Point))
+
+ if (typeof(T) == typeof(Point))
{
return targetHint.CreatePointAnimation(
Property,
@@ -166,7 +173,8 @@ public Timeline GetAnimation(DependencyObject targetHint)
easingFunction,
true);
}
- else if (typeof(T) == typeof(Color))
+
+ if (typeof(T) == typeof(Color))
{
return targetHint.CreateColorAnimation(
Property,
@@ -176,10 +184,8 @@ public Timeline GetAnimation(DependencyObject targetHint)
Duration,
easingFunction);
}
- else
- {
- return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
- }
+
+ return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
}
///
From 829f15af9651e74f865eacccf7c02000360fb5b7 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 01:17:38 +0100
Subject: [PATCH 060/171] Added ListBuilder type
---
.../Builders/Helpers/ListBuilder{T}.cs | 69 +++++++++++++++++++
...KeyFrameAnimationBuilder{T}.Composition.cs | 21 +++---
...malizedKeyFrameAnimationBuilder{T}.Xaml.cs | 2 +-
.../NormalizedKeyFrameAnimationBuilder{T}.cs | 8 +--
...KeyFrameAnimationBuilder{T}.Composition.cs | 5 +-
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 5 +-
.../TimedKeyFrameAnimationBuilder{T}.cs | 8 +--
7 files changed, 93 insertions(+), 25 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/Helpers/ListBuilder{T}.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Helpers/ListBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Helpers/ListBuilder{T}.cs
new file mode 100644
index 00000000000..df9bc575253
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Helpers/ListBuilder{T}.cs
@@ -0,0 +1,69 @@
+// 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 System;
+using System.Diagnostics.Contracts;
+using System.Runtime.CompilerServices;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Builders.Helpers
+{
+ ///
+ /// A small generic builder type that allows to create instances.
+ ///
+ /// The type of items to create a sequence of.
+ internal struct ListBuilder
+ {
+ ///
+ /// The array in use.
+ ///
+ private T[] array;
+
+ ///
+ /// The current index.
+ ///
+ private int index;
+
+ ///
+ /// Gets an emoty instance.
+ ///
+ public static ListBuilder Empty
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ ListBuilder builder;
+ builder.array = new T[1];
+ builder.index = 0;
+
+ return builder;
+ }
+ }
+
+ ///
+ /// Appens an item to the current builder.
+ ///
+ /// The item to append.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void Append(T item)
+ {
+ if (this.index >= this.array.Length)
+ {
+ Array.Resize(ref this.array, this.array.Length * 2);
+ }
+
+ this.array[this.index++] = item;
+ }
+
+ ///
+ /// Gets a instance with the current items.
+ ///
+ /// A instance with the current items.
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public ReadOnlySpan AsSpan()
+ {
+ return this.array.AsSpan(0, this.index);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
index a13a322c70a..d25869055c1 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using System.Numerics;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
@@ -32,7 +31,7 @@ public static CompositionAnimation GetAnimation(
string property,
TimeSpan? delay,
TimeSpan duration,
- List keyFrames)
+ ReadOnlySpan keyFrames)
where TKeyFrame : struct, IKeyFrameInfo
{
KeyFrameAnimation animation;
@@ -41,7 +40,7 @@ public static CompositionAnimation GetAnimation(
{
BooleanKeyFrameAnimation boolAnimation = target.Compositor.CreateBooleanKeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
boolAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -54,7 +53,7 @@ public static CompositionAnimation GetAnimation(
{
ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
scalarAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -68,7 +67,7 @@ public static CompositionAnimation GetAnimation(
{
ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
scalarAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -82,7 +81,7 @@ public static CompositionAnimation GetAnimation(
{
Vector2KeyFrameAnimation vector2Animation = target.Compositor.CreateVector2KeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
vector2Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -96,7 +95,7 @@ public static CompositionAnimation GetAnimation(
{
Vector3KeyFrameAnimation vector3Animation = target.Compositor.CreateVector3KeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
vector3Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -110,7 +109,7 @@ public static CompositionAnimation GetAnimation(
{
Vector4KeyFrameAnimation vector4Animation = target.Compositor.CreateVector4KeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
vector4Animation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -124,7 +123,7 @@ public static CompositionAnimation GetAnimation(
{
ColorKeyFrameAnimation colorAnimation = target.Compositor.CreateColorKeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
colorAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -138,7 +137,7 @@ public static CompositionAnimation GetAnimation(
{
QuaternionKeyFrameAnimation quaternionAnimation = target.Compositor.CreateQuaternionKeyFrameAnimation();
- foreach (var keyFrame in keyFrames)
+ foreach (ref readonly var keyFrame in keyFrames)
{
quaternionAnimation.InsertKeyFrame(
(float)keyFrame.GetNormalizedProgress(duration),
@@ -189,7 +188,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
this.property,
this.delay,
this.duration,
- this.keyFrames);
+ this.keyFrames.AsSpan());
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
index a3bfca3c7a5..4c9479e4b57 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -34,7 +34,7 @@ public Timeline GetAnimation(DependencyObject targetHint)
this.property,
this.delay,
this.duration,
- this.keyFrames);
+ this.keyFrames.AsSpan());
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
index 85e2d11cb0c..46d1cc4eaf8 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -3,8 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using System.Runtime.CompilerServices;
+using Microsoft.Toolkit.Uwp.UI.Animations.Builders.Helpers;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -33,9 +33,9 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder : INormali
private readonly TimeSpan duration;
///
- /// The list of keyframes to use.
+ /// The list builder of keyframes to use.
///
- private readonly List keyFrames = new();
+ private ListBuilder keyFrames = ListBuilder.Empty;
///
/// Initializes a new instance of the class.
@@ -57,7 +57,7 @@ public INormalizedKeyFrameAnimationBuilder KeyFrame(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- this.keyFrames.Add(new(progress, value, easingType, easingMode));
+ this.keyFrames.Append(new(progress, value, easingType, easingMode));
return this;
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
index eb89c2288ad..1f9428a5016 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs
@@ -34,14 +34,15 @@ 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.
- TimeSpan duration = this.keyFrames[this.keyFrames.Count - 1].GetTimedProgress(default);
+ ReadOnlySpan keyFrames = this.keyFrames.AsSpan();
+ TimeSpan duration = keyFrames[keyFrames.Length - 1].GetTimedProgress(default);
return NormalizedKeyFrameAnimationBuilder.GetAnimation(
targetHint,
this.property,
this.delay,
duration,
- this.keyFrames);
+ keyFrames);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index 333c7d25dce..c94da75dc6b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
using Windows.Foundation;
@@ -32,7 +31,7 @@ public static Timeline GetAnimation(
string property,
TimeSpan? delay,
TimeSpan duration,
- List keyFrames)
+ ReadOnlySpan keyFrames)
where TKeyFrame : struct, IKeyFrameInfo
{
Timeline animation;
@@ -136,7 +135,7 @@ public Timeline GetAnimation(DependencyObject targetHint)
this.property,
this.delay,
default,
- this.keyFrames);
+ this.keyFrames.AsSpan());
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
index 6ad0400c2f3..05319991138 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
@@ -3,8 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using System.Runtime.CompilerServices;
+using Microsoft.Toolkit.Uwp.UI.Animations.Builders.Helpers;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -28,9 +28,9 @@ internal abstract partial class TimedKeyFrameAnimationBuilder : ITimedKeyFram
private readonly TimeSpan? delay;
///
- /// The list of keyframes to use.
+ /// The list builder of keyframes to use.
///
- private readonly List keyFrames = new();
+ private ListBuilder keyFrames = ListBuilder.Empty;
///
/// Initializes a new instance of the class.
@@ -50,7 +50,7 @@ public ITimedKeyFrameAnimationBuilder KeyFrame(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- this.keyFrames.Add(new(progress, value, easingType, easingMode));
+ this.keyFrames.Append(new(progress, value, easingType, easingMode));
return this;
}
From 126797db169cb667577bf26e259f0f217ed9289a Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 01:39:56 +0100
Subject: [PATCH 061/171] Minor code style tweaks
---
.../Builders/AnimationBuilder.Default.cs | 42 +++++++++++--------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index b71dcf550c9..203e4201428 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -40,12 +40,14 @@ public AnimationBuilder Opacity(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode);
+ AddXamlAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode);
}
+
+ return this;
}
///
@@ -72,12 +74,14 @@ public AnimationBuilder Translation(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory($"Translation.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"Translation.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlAnimationFactory($"Translate{axis}", to, from, delay, duration, easingType, easingMode);
+ AddXamlAnimationFactory($"Translate{axis}", to, from, delay, duration, easingType, easingMode);
}
+
+ return this;
}
///
@@ -232,15 +236,15 @@ public AnimationBuilder Scale(
Vector3? from3 = from is null ? null : new((float)(double)from);
Vector3 to3 = new((float)to);
- return AddCompositionAnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode);
}
else
{
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to, from, delay, duration, easingType, easingMode);
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to, from, delay, duration, easingType, easingMode);
-
- return this;
}
+
+ return this;
}
///
@@ -267,12 +271,14 @@ public AnimationBuilder Scale(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Scale)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
- return AddXamlTransformDoubleAnimationFactory($"Scale{axis}", to, from, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory($"Scale{axis}", to, from, delay, duration, easingType, easingMode);
}
+
+ return this;
}
///
@@ -353,7 +359,7 @@ public AnimationBuilder Rotate(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -361,9 +367,9 @@ public AnimationBuilder Rotate(
double toDegrees = to * Math.PI / 180;
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), toDegrees, fromDegrees, delay, duration, easingType, easingMode);
-
- return this;
}
+
+ return this;
}
///
@@ -388,14 +394,14 @@ public AnimationBuilder RotateInDegrees(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), to, from, delay, duration, easingType, easingMode);
-
- return this;
}
+
+ return this;
}
///
@@ -524,7 +530,7 @@ public AnimationBuilder Size(
{
if (layer == FrameworkLayer.Composition)
{
- return AddCompositionAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.Size)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
}
else
{
@@ -535,8 +541,10 @@ public AnimationBuilder Size(
_ => ThrowHelper.ThrowArgumentException("Invalid size axis")
};
- return AddXamlAnimationFactory(property, to, from, delay, duration, easingType, easingMode);
+ AddXamlAnimationFactory(property, to, from, delay, duration, easingType, easingMode);
}
+
+ return this;
}
///
From c8e0567cee4a73645fe85fcd2511d8d352e1e72b Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 01:58:40 +0100
Subject: [PATCH 062/171] Added missing animation APIs
---
.../Builders/AnimationBuilder.Default.cs | 189 +++++++++++++++++-
.../Xaml/Default/RotationAnimation.cs | 2 +-
.../Default/RotationInDegreesAnimation.cs | 2 +-
3 files changed, 189 insertions(+), 4 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 203e4201428..6ca522abfe5 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -18,6 +18,57 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// Adds a new anchor point animation for a single axis to the current schedule.
+ ///
+ /// The target anchor point axis to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder AnchorPoint(
+ Axis axis,
+ double to,
+ double? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ AddCompositionAnimationFactory($"{nameof(Visual.AnchorPoint)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.AnchorPoint)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+
+ ///
+ /// Adds a new anchor point animation for the X and Y axes to the current schedule.
+ ///
+ /// The final point for the animation.
+ /// The optional starting point for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder AnchorPoint(
+ Vector2 to,
+ Vector2? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ AddCompositionAnimationFactory(nameof(Visual.AnchorPoint), to, from, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+
///
/// Adds a new opacity animation to the current schedule.
///
@@ -337,6 +388,96 @@ public AnimationBuilder Scale(
return AddCompositionAnimationFactory(nameof(Visual.Scale), to, from, delay, duration, easingType, easingMode);
}
+ ///
+ /// Adds a new center point animation on a specified axis to the current schedule.
+ ///
+ /// The target scale axis to animate.
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder CenterPoint(
+ Axis axis,
+ double to,
+ double? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ AddCompositionAnimationFactory($"{nameof(Visual.CenterPoint)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory($"Center{axis}", to, from, delay, duration, easingType, easingMode);
+ }
+
+ return this;
+ }
+
+ ///
+ /// Adds a new center point animation for the X and Y axes to the current schedule.
+ ///
+ /// The final point for the animation.
+ /// The optional starting point for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The target framework layer to animate.
+ /// The current instance.
+ public AnimationBuilder CenterPoint(
+ Vector2 to,
+ Vector2? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode,
+ FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ AddCompositionAnimationFactory($"{nameof(Visual.CenterPoint)}.X", to.X, from?.X, delay, duration, easingType, easingMode);
+ AddCompositionAnimationFactory($"{nameof(Visual.CenterPoint)}.Y", to.Y, from?.Y, delay, duration, easingType, easingMode);
+ }
+ else
+ {
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterX), to.X, from?.X, delay, duration, easingType, easingMode);
+ AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterY), to.Y, from?.Y, delay, duration, easingType, easingMode);
+ }
+
+ return this;
+ }
+
+ ///
+ /// Adds a new center point animation for all axes to the current schedule.
+ ///
+ /// The final point for the animation.
+ /// The optional starting point for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder CenterPoint(
+ Vector3 to,
+ Vector3? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionAnimationFactory(nameof(Visual.CenterPoint), to, from, delay, duration, easingType, easingMode);
+ }
+
///
/// Adds a new rotation animation to the current schedule.
///
@@ -348,7 +489,7 @@ public AnimationBuilder Scale(
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
/// The current instance.
- public AnimationBuilder Rotate(
+ public AnimationBuilder Rotation(
double to,
double? from = null,
TimeSpan? delay = null,
@@ -383,7 +524,7 @@ public AnimationBuilder Rotate(
/// The optional easing function mode for the animation.
/// The target framework layer to animate.
/// The current instance.
- public AnimationBuilder RotateInDegrees(
+ public AnimationBuilder RotationInDegrees(
double to,
double? from = null,
TimeSpan? delay = null,
@@ -404,6 +545,50 @@ public AnimationBuilder RotateInDegrees(
return this;
}
+ ///
+ /// Adds a new rotation axis animation to the current schedule.
+ ///
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder RotationAxis(
+ Vector3 to,
+ Vector3? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionAnimationFactory(nameof(Visual.RotationAxis), to, from, delay, duration, easingType, easingMode);
+ }
+
+ ///
+ /// Adds a new orientation animation to the current schedule.
+ ///
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Orientation(
+ Quaternion to,
+ Quaternion? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ return AddCompositionAnimationFactory(nameof(Visual.Orientation), to, from, delay, duration, easingType, easingMode);
+ }
+
///
/// Adds a new clip animation to the current schedule.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
index 984404b8d29..01967762b81 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationAnimation.cs
@@ -21,7 +21,7 @@ public class RotationAnimation : Animation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
- return builder.Rotate(
+ return builder.Rotation(
To!.Value,
From,
Delay ?? delayHint,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
index a42f3847c70..445480921e6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/RotationInDegreesAnimation.cs
@@ -21,7 +21,7 @@ public class RotationInDegreesAnimation : Animation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
- return builder.RotateInDegrees(
+ return builder.RotationInDegrees(
To!.Value,
From,
Delay ?? delayHint,
From aa79263da2f1b599aa12c76ec95d7a4bdc43dd51 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 02:07:50 +0100
Subject: [PATCH 063/171] Added AnimationBuilder.Transform API
---
.../Builders/AnimationBuilder.Default.cs | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 6ca522abfe5..838c2d42508 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -589,6 +589,53 @@ public AnimationBuilder Orientation(
return AddCompositionAnimationFactory(nameof(Visual.Orientation), to, from, delay, duration, easingType, easingMode);
}
+ ///
+ /// Adds a new transform animation to the current schedule.
+ ///
+ /// The final value for the animation.
+ /// The optional starting value for the animation.
+ /// The optional initial delay for the animation.
+ /// The optional animation duration.
+ /// The optional easing function type for the animation.
+ /// The optional easing function mode for the animation.
+ /// The current instance.
+ /// This animation is only available on the composition layer.
+ public AnimationBuilder Transform(
+ Matrix4x4 to,
+ Matrix4x4? from = null,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null,
+ EasingType easingType = DefaultEasingType,
+ EasingMode easingMode = DefaultEasingMode)
+ {
+ if (!Matrix4x4.Decompose(to, out Vector3 toScale, out Quaternion toRotation, out Vector3 toTranslation))
+ {
+ ThrowHelper.ThrowArgumentException("The destination matrix could not be decomposed");
+ }
+
+ Vector3? fromScale = null;
+ Quaternion? fromRotation = null;
+ Vector3? fromTranslation = null;
+
+ if (from.HasValue)
+ {
+ if (!Matrix4x4.Decompose(from.GetValueOrDefault(), out Vector3 scale3, out Quaternion rotation4, out Vector3 translation3))
+ {
+ ThrowHelper.ThrowArgumentException("The initial matrix could not be decomposed");
+ }
+
+ fromScale = scale3;
+ fromRotation = rotation4;
+ fromTranslation = translation3;
+ }
+
+ Scale(toScale, fromScale, delay, duration, easingType, easingMode);
+ Orientation(toRotation, fromRotation, delay, duration, easingType, easingMode);
+ Translation(toTranslation, fromTranslation, delay, duration, easingType, easingMode);
+
+ return this;
+ }
+
///
/// Adds a new clip animation to the current schedule.
///
From 2ca1542e3cda8f67e7d084f00e5ef2f2234cc937 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 02:20:32 +0100
Subject: [PATCH 064/171] Minor tweaks to public keyframe builder interfaces
---
.../Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs | 4 ++--
.../Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
index 39ec594fa92..20087a60882 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
/// An interface for an animation builder using normalized keyframes.
///
/// The type of values being set by the animation being constructed.
- public interface INormalizedKeyFrameAnimationBuilder
+ public interface INormalizedKeyFrameAnimationBuilder
where T : unmanaged
{
///
@@ -22,7 +22,7 @@ public interface INormalizedKeyFrameAnimationBuilder
/// The easing type to use to reach the new keyframe.
/// The easing mode to use to reach the new keyframe.
/// The same instance that the method was invoked upon.
- public INormalizedKeyFrameAnimationBuilder KeyFrame(
+ INormalizedKeyFrameAnimationBuilder KeyFrame(
double progress,
T value,
EasingType easingType = DefaultEasingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
index e9db4ad89f4..188a154a8fe 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
/// An interface for an animation builder using timed keyframes.
///
/// The type of values being set by the animation being constructed.
- public interface ITimedKeyFrameAnimationBuilder
+ public interface ITimedKeyFrameAnimationBuilder
where T : unmanaged
{
///
@@ -23,7 +23,7 @@ public interface ITimedKeyFrameAnimationBuilder
/// The easing type to use to reach the new keyframe.
/// The easing mode to use to reach the new keyframe.
/// The same instance that the method was invoked upon.
- public ITimedKeyFrameAnimationBuilder KeyFrame(
+ ITimedKeyFrameAnimationBuilder KeyFrame(
TimeSpan progress,
T value,
EasingType easingType = DefaultEasingType,
From 8385b6e8e6c5d89dca7715992d4372b1c49c82f7 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 02:25:12 +0100
Subject: [PATCH 065/171] Removed unnecessary extensions
---
.../Builders/AnimationBuilder.Models.cs | 7 ++-
.../Extensions/AnimationExtensions.cs | 2 +-
.../Extensions/UIElementExtensions.cs | 46 -------------------
3 files changed, 7 insertions(+), 48 deletions(-)
delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Extensions/UIElementExtensions.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
index adcad50390c..61606bda045 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
@@ -293,7 +293,12 @@ private sealed record XamlTransformDoubleAnimationFactory(
///
public Timeline GetAnimation(DependencyObject targetHint)
{
- CompositeTransform transform = ((UIElement)targetHint).GetTransform();
+ UIElement element = (UIElement)targetHint;
+
+ if (element.RenderTransform is not CompositeTransform transform)
+ {
+ element.RenderTransform = transform = new CompositeTransform();
+ }
return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode));
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
index 2d7ee81fd58..d115669f336 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
///
/// Common properties related to extensions.
///
- public static partial class AnimationExtensions
+ public static class AnimationExtensions
{
///
/// Gets the default delay of animations.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/UIElementExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/UIElementExtensions.cs
deleted file mode 100644
index 69efa23b76e..00000000000
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/UIElementExtensions.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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 System.Diagnostics.Contracts;
-using Windows.UI.Composition;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Hosting;
-using Windows.UI.Xaml.Media;
-
-namespace Microsoft.Toolkit.Uwp.UI.Animations.Extensions
-{
- ///
- /// An extension for the type.
- ///
- public static class UIElementExtensions
- {
- ///
- /// Returns the desired instance after assigning it to the property of the target .
- ///
- /// The desired type.
- /// The target to modify.
- /// A instance assigned to .
- public static T GetTransform(this UIElement element)
- where T : Transform, new()
- {
- if (element.RenderTransform is T transform)
- {
- return transform;
- }
-
- return (T)(element.RenderTransform = new T());
- }
-
- ///
- /// Returns the object for a given instance.
- ///
- /// The source element to get the visual for.
- /// The object associated with .
- [Pure]
- public static Visual GetVisual(this UIElement element)
- {
- return ElementCompositionPreview.GetElementVisual(element);
- }
- }
-}
From 66746f9e1f41d0aab7eba5cfc2c4004da8d663d4 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 17:48:01 +0100
Subject: [PATCH 066/171] Added builder types for new keyframe APIs
---
.../AnimationBuilder.PropertyBuilders.cs | 191 ++++++++++++++++++
1 file changed, 191 insertions(+)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
new file mode 100644
index 00000000000..7f652b1b3a0
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
@@ -0,0 +1,191 @@
+// 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 System;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Media.Animation;
+using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
+
+#nullable enable
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ public sealed partial class AnimationBuilder
+ {
+ ///
+ /// An animation for an animation builder using keyframes, targeting a specific property.
+ ///
+ /// The type of values being set by the animation being constructed.
+ public interface IPropertyAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// Adds a custom animation based on normalized keyframes ot the current schedule.
+ ///
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The current instance.
+ public AnimationBuilder NormalizedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null);
+
+ ///
+ /// Adds a custom animation based on timed keyframes to the current schedule.
+ ///
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The current instance.
+ public AnimationBuilder TimedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null);
+ }
+
+ ///
+ /// A custom for a shared animation.
+ ///
+ /// The type of property to animate.
+ private sealed record PropertyAnimationBuilder(
+ AnimationBuilder Builder,
+ string Property,
+ FrameworkLayer Layer)
+ : IPropertyAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ public AnimationBuilder NormalizedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null)
+ {
+ return Builder.NormalizedKeyFrames(Property, build, delay, duration, Layer);
+ }
+
+ ///
+ public AnimationBuilder TimedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null)
+ {
+ return Builder.TimedKeyFrames(Property, build, delay, Layer);
+ }
+ }
+
+ ///
+ /// A custom for a composition clip animation.
+ ///
+ private sealed record CompositionClipAnimationBuilder(
+ AnimationBuilder Builder,
+ string Property)
+ : IPropertyAnimationBuilder
+ {
+ ///
+ public AnimationBuilder NormalizedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null)
+ {
+ NormalizedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, duration ?? DefaultDuration);
+
+ build(builder);
+
+ Builder.compositionAnimationFactories.Add(new Factory(builder));
+
+ return Builder;
+ }
+
+ ///
+ public AnimationBuilder TimedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null)
+ {
+ TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay);
+
+ build(builder);
+
+ Builder.compositionAnimationFactories.Add(new Factory(builder));
+
+ return Builder;
+ }
+
+ ///
+ /// A private factory implementing .
+ ///
+ private sealed record Factory(ICompositionAnimationFactory Builder) : ICompositionAnimationFactory
+ {
+ ///
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
+ {
+ Visual visual = (Visual)targetHint;
+ InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip());
+ CompositionAnimation animation = Builder.GetAnimation(clip, out _);
+
+ target = clip;
+
+ return animation;
+ }
+ }
+ }
+
+ ///
+ /// A custom for a XAML transform animation.
+ ///
+ private sealed record XamlTransformPropertyAnimationBuilder(
+ AnimationBuilder Builder,
+ string Property)
+ : IPropertyAnimationBuilder
+ {
+ ///
+ public AnimationBuilder NormalizedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null)
+ {
+ NormalizedKeyFrameAnimationBuilder.Xaml builder = new(Property, delay, duration ?? DefaultDuration);
+
+ build(builder);
+
+ Builder.xamlAnimationFactories.Add(new Factory(builder));
+
+ return Builder;
+ }
+
+ ///
+ public AnimationBuilder TimedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null)
+ {
+ TimedKeyFrameAnimationBuilder.Xaml builder = new(Property, delay);
+
+ build(builder);
+
+ Builder.xamlAnimationFactories.Add(new Factory(builder));
+
+ return Builder;
+ }
+
+ ///
+ /// A private factory implementing .
+ ///
+ private sealed record Factory(IXamlAnimationFactory Builder) : IXamlAnimationFactory
+ {
+ ///
+ public Timeline GetAnimation(DependencyObject targetHint)
+ {
+ UIElement element = (UIElement)targetHint;
+
+ if (element.RenderTransform is not CompositeTransform transform)
+ {
+ element.RenderTransform = transform = new CompositeTransform();
+ }
+
+ return Builder.GetAnimation(transform);
+ }
+ }
+ }
+ }
+}
From df043fbf3c9eaae2fa4374b5db507b94cae93105 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 17:49:06 +0100
Subject: [PATCH 067/171] Minor code tweaks and bug fixes
---
.../Builders/AnimationBuilder.Custom.cs | 4 +-
.../Builders/AnimationBuilder.Default.cs | 1 -
...odels.cs => AnimationBuilder.Factories.cs} | 66 +++++++++----------
.../Builders/AnimationBuilder.cs | 2 +-
4 files changed, 36 insertions(+), 37 deletions(-)
rename Microsoft.Toolkit.Uwp.UI.Animations/Builders/{AnimationBuilder.Models.cs => AnimationBuilder.Factories.cs} (99%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
index 4456a8575a4..82b3cbcacf2 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
@@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
public sealed partial class AnimationBuilder
{
///
- /// Adds a custom animation based on normalized keyframes ot the current schedule.
+ /// Adds a custom animation based on normalized keyframes to the current schedule.
///
/// The type of values to animate.
/// The target property to animate.
@@ -51,7 +51,7 @@ public AnimationBuilder NormalizedKeyFrames(
}
///
- /// Adds a custom animation based on timed keyframes ot the current schedule.
+ /// Adds a custom animation based on timed keyframes to the current schedule.
///
/// The type of values to animate.
/// The target property to animate.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
index 838c2d42508..3c85424851c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs
@@ -40,7 +40,6 @@ public AnimationBuilder AnchorPoint(
EasingMode easingMode = DefaultEasingMode)
{
AddCompositionAnimationFactory($"{nameof(Visual.AnchorPoint)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
- AddCompositionAnimationFactory($"{nameof(Visual.AnchorPoint)}.{axis}", (float)to, (float?)from, delay, duration, easingType, easingMode);
return this;
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
similarity index 99%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
index 61606bda045..031a887775f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Models.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
@@ -22,6 +22,38 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// An interface for factories of XAML animations.
+ ///
+ internal interface IXamlAnimationFactory
+ {
+ ///
+ /// Gets a instance representing the animation to start.
+ ///
+ /// The suggested target instance to animate.
+ /// A instance with the specified animation.
+ Timeline GetAnimation(DependencyObject targetHint);
+ }
+
+ ///
+ /// An interface for factories of composition animations.
+ ///
+ internal interface ICompositionAnimationFactory
+ {
+ ///
+ /// Gets a instance representing the animation to start.
+ ///
+ /// The suggested target instance to animate.
+ /// An optional instance to animate instead of the suggested one.
+ /// A instance with the specified animation.
+ ///
+ /// The separate parameter is needed because unlike with XAML animations, composition animations
+ /// can't store the target instance internally, and need to be started on the target object directly. This means that custom
+ /// animation factories that want to target an external object need to return that object separately to inform the callers.
+ ///
+ CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target);
+ }
+
///
/// A model representing a generic animation for a target object.
///
@@ -254,7 +286,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
///
/// A model representing a specified composition double animation for a target .
///
- private sealed record CompositionDoubleAnimation(
+ private sealed record CompositionDoubleAnimationFactory(
CompositionObject Target,
string Property,
float To,
@@ -303,37 +335,5 @@ public Timeline GetAnimation(DependencyObject targetHint)
return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode));
}
}
-
- ///
- /// An interface for factories of XAML animations.
- ///
- internal interface IXamlAnimationFactory
- {
- ///
- /// Gets a instance representing the animation to start.
- ///
- /// The suggested target instance to animate.
- /// A instance with the specified animation.
- Timeline GetAnimation(DependencyObject targetHint);
- }
-
- ///
- /// An interface for factories of composition animations.
- ///
- internal interface ICompositionAnimationFactory
- {
- ///
- /// Gets a instance representing the animation to start.
- ///
- /// The suggested target instance to animate.
- /// An optional instance to animate instead of the suggested one.
- /// A instance with the specified animation.
- ///
- /// The separate parameter is needed because unlike with XAML animations, composition animations
- /// can't store the target instance internally, and need to be started on the target object directly. This means that custom
- /// animation factories that want to target an external object need to return that object separately to inform the callers.
- ///
- CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target);
- }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index 24804087c31..773d916daee 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -72,7 +72,7 @@ public AnimationBuilder DoubleAnimation(
EasingType easingType = DefaultEasingType,
EasingMode easingMode = DefaultEasingMode)
{
- CompositionDoubleAnimation animation = new(
+ CompositionDoubleAnimationFactory animation = new(
target,
property,
(float)to,
From 6c8b949155b4be460484c7562185e2aa91a99624 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 18:10:20 +0100
Subject: [PATCH 068/171] Added strongly-typed keyframed animation APIs
---
.../Builders/AnimationBuilder.Custom.cs | 233 ++++++++++++++++++
1 file changed, 233 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
index 82b3cbcacf2..db8195f96d2 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
@@ -5,6 +5,11 @@
#nullable enable
using System;
+using System.Numerics;
+using Microsoft.Toolkit.Diagnostics;
+using Windows.UI.Composition;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations
@@ -12,6 +17,234 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// Adds a new anchor point animation for a single axis to the current schedule.
+ ///
+ /// The target anchor point axis to animate.
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder AnchorPoint(Axis axis)
+ {
+ return new PropertyAnimationBuilder(this, $"{nameof(Visual.AnchorPoint)}.{axis}", FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new anchor point animation for the X and Y axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder AnchorPoint()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.AnchorPoint), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new opacity animation to the current schedule.
+ ///
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder Opacity(FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.Opacity), layer);
+ }
+
+ ///
+ /// Adds a new translation animation for a single axis to the current schedule.
+ ///
+ /// The target translation axis to animate.
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder Translation(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, $"Translation.{axis}", layer);
+ }
+
+ return new XamlTransformPropertyAnimationBuilder(this, $"Translate{axis}");
+ }
+
+ ///
+ /// Adds a new composition translation animation for all axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Translation()
+ {
+ return new PropertyAnimationBuilder(this, "Translation", FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new composition offset animation for a single axis to the current schedule.
+ ///
+ /// The target translation axis to animate.
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Offset(Axis axis)
+ {
+ return new PropertyAnimationBuilder(this, $"{nameof(Visual.Offset)}.{axis}", FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new composition offset translation animation for all axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Offset()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.Offset), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new scale animation on a specified axis to the current schedule.
+ ///
+ /// The target scale axis to animate.
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder Scale(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, $"{nameof(Visual.Scale)}.{axis}", layer);
+ }
+
+ return new XamlTransformPropertyAnimationBuilder(this, $"Scale{axis}");
+ }
+
+ ///
+ /// Adds a new scale animation for all axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Scale()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.Scale), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new center point animation on a specified axis to the current schedule.
+ ///
+ /// The target scale axis to animate.
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder CenterPoint(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, $"{nameof(Visual.CenterPoint)}.{axis}", layer);
+ }
+
+ return new XamlTransformPropertyAnimationBuilder(this, $"Center{axis}");
+ }
+
+ ///
+ /// Adds a new center point animation for all axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder CenterPoint()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.CenterPoint), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new rotation animation to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Rotation()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.RotationAngle), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new rotation animation in degrees to the current schedule.
+ ///
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder RotationInDegrees(FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.RotationAngleInDegrees), layer);
+ }
+
+ return new XamlTransformPropertyAnimationBuilder(this, nameof(CompositeTransform.Rotation));
+ }
+
+ ///
+ /// Adds a new rotation axis animation to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder RotationAxis()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.RotationAxis), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new orientation animation to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Orientation()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.Orientation), FrameworkLayer.Composition);
+ }
+
+ ///
+ /// Adds a new clip animation to the current schedule.
+ ///
+ /// The clip size to animate.
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Clip(Side side)
+ {
+ string property = side switch
+ {
+ Side.Top => nameof(InsetClip.TopInset),
+ Side.Bottom => nameof(InsetClip.BottomInset),
+ Side.Right => nameof(InsetClip.RightInset),
+ Side.Left => nameof(InsetClip.LeftInset),
+ _ => ThrowHelper.ThrowArgumentException("Invalid clip size")
+ };
+
+ return new CompositionClipAnimationBuilder(this, property);
+ }
+
+ ///
+ /// Adds a new size animation for a single axis to the current schedule.
+ ///
+ /// The target size axis to animate.
+ /// The target framework layer to animate.
+ /// An instance to configure the animation.
+ public IPropertyAnimationBuilder Size(Axis axis, FrameworkLayer layer = FrameworkLayer.Composition)
+ {
+ if (layer == FrameworkLayer.Composition)
+ {
+ return new PropertyAnimationBuilder(this, $"{nameof(Visual.Size)}.{axis}", layer);
+ }
+
+ string property = axis switch
+ {
+ Axis.X => nameof(FrameworkElement.Width),
+ Axis.Y => nameof(FrameworkElement.Height),
+ _ => ThrowHelper.ThrowArgumentException("Invalid size axis")
+ };
+
+ return new PropertyAnimationBuilder(this, property, layer);
+ }
+
+ ///
+ /// Adds a new composition size translation animation for all axes to the current schedule.
+ ///
+ /// An instance to configure the animation.
+ /// This animation is only available on the composition layer.
+ public IPropertyAnimationBuilder Size()
+ {
+ return new PropertyAnimationBuilder(this, nameof(Visual.Size), FrameworkLayer.Composition);
+ }
+
///
/// Adds a custom animation based on normalized keyframes to the current schedule.
///
From ca8038478d0a345749f5c4ec4b605613e153cc56 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 18:23:43 +0100
Subject: [PATCH 069/171] Renamed AnimationBuilder.New() to Create()
---
.../Builders/AnimationBuilder.cs | 8 ++++----
.../Xaml/AnimationCollection2.cs | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index 773d916daee..4b9b0933c8b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -22,12 +22,12 @@ public sealed partial class AnimationBuilder
{
///
///
- /// A static constructor for the type.
+ /// Creates a new instance to setup an animation schedule.
/// This can be used as the entry point to construct a custom animation sequence.
///
/// For instance:
///
- /// AnimationBuilder.New()
+ /// AnimationBuilder.Create()
/// .Opacity(from: 0, to: 1, duration: 400)
/// .Translation(Axis.X, from: -40, to: 0, duration: 400)
/// .Start(MyButton);
@@ -38,7 +38,7 @@ public sealed partial class AnimationBuilder
///
/// For instance:
///
- /// var animation = AnimationBuilder.New().Opacity(0, 1, duration: 400).Size(1.2, 1, duration: 400);
+ /// var animation = AnimationBuilder.Create().Opacity(0, 1, duration: 400).Size(1.2, 1, duration: 400);
///
/// animation.Start(MyButton);
/// animation.Start(MyGrid);
@@ -48,7 +48,7 @@ public sealed partial class AnimationBuilder
///
/// An empty instance to use to construct an animation sequence.
[Pure]
- public static AnimationBuilder New() => new();
+ public static AnimationBuilder Create() => new();
///
/// Adds a new custom double animation targeting an arbitrary composition object.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index fd7841b7f1f..c7dc05cbb0b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -75,7 +75,7 @@ public async Task StartAsync(UIElement element)
{
Started?.Invoke(this, EventArgs.Empty);
- var builder = AnimationBuilder.New();
+ var builder = AnimationBuilder.Create();
foreach (ITimeline animation in Animations)
{
From ef4a24924fe829ac783ad73ea18eb8cb2571c9cd Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 18:25:36 +0100
Subject: [PATCH 070/171] Added missing AnimationBuilder private constructor
---
.../Builders/AnimationBuilder.cs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index 4b9b0933c8b..d5117cfcdda 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -20,6 +20,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// This is private as the public entry point is the method.
+ private AnimationBuilder()
+ {
+ }
+
///
///
/// Creates a new instance to setup an animation schedule.
From 2790c4f621696378ec32095d4e90d23c3cbef9a9 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 19:08:29 +0100
Subject: [PATCH 071/171] Removed unnecessary visibility modifiers
---
.../Builders/AnimationBuilder.PropertyBuilders.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
index 7f652b1b3a0..9391108d5f7 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
@@ -30,7 +30,7 @@ public interface IPropertyAnimationBuilder
/// The optional initial delay for the animation.
/// The animation duration.
/// The current instance.
- public AnimationBuilder NormalizedKeyFrames(
+ AnimationBuilder NormalizedKeyFrames(
Action> build,
TimeSpan? delay = null,
TimeSpan? duration = null);
@@ -41,7 +41,7 @@ public AnimationBuilder NormalizedKeyFrames(
/// The callback to use to construct the custom animation.
/// The optional initial delay for the animation.
/// The current instance.
- public AnimationBuilder TimedKeyFrames(
+ AnimationBuilder TimedKeyFrames(
Action> build,
TimeSpan? delay = null);
}
From 921061cf66ca1037cd0aff5976914b69dafe3b7d Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 19:59:19 +0100
Subject: [PATCH 072/171] Added APIs to insert external animations
---
.../Builders/AnimationBuilder.External.cs | 55 +++++++++++++++++++
.../Builders/AnimationBuilder.Factories.cs | 52 +++++++++---------
...ustom.cs => AnimationBuilder.KeyFrames.cs} | 0
.../Builders/AnimationBuilder.cs | 39 -------------
.../Animations/EffectDoubleAnimation.cs | 19 ++++---
5 files changed, 92 insertions(+), 73 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.External.cs
rename Microsoft.Toolkit.Uwp.UI.Animations/Builders/{AnimationBuilder.Custom.cs => AnimationBuilder.KeyFrames.cs} (100%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.External.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.External.cs
new file mode 100644
index 00000000000..68dd890babd
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.External.cs
@@ -0,0 +1,55 @@
+// 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.
+
+#nullable enable
+
+using Windows.UI.Composition;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ public sealed partial class AnimationBuilder
+ {
+ ///
+ /// Adds a new external animation to the current schedule, which will be executed on the same
+ /// target object the current instance will be invoked upon.
+ ///
+ /// The external instance to add to the schedule.
+ /// The current instance.
+ public AnimationBuilder ExternalAnimation(CompositionAnimation animation)
+ {
+ this.compositionAnimationFactories.Add(new ExternalCompositionAnimation(null, animation));
+
+ return this;
+ }
+
+ ///
+ /// Adds a new external animation to the current schedule, which will be executed on a given
+ /// when the current instance is invoked.
+ ///
+ /// The target to invoke the animation upon.
+ /// The external instance to add to the schedule.
+ /// The current instance.
+ public AnimationBuilder ExternalAnimation(CompositionObject target, CompositionAnimation animation)
+ {
+ this.compositionAnimationFactories.Add(new ExternalCompositionAnimation(target, animation));
+
+ return this;
+ }
+
+ ///
+ /// Adds a new external animation to the current schedule, which will be executed on the same
+ /// target object the current instance will be invoked upon.
+ ///
+ /// The external instance to add to the schedule.
+ /// The current instance.
+ public AnimationBuilder ExternalAnimation(Timeline animation)
+ {
+ this.xamlAnimationFactories.Add(new ExternalXamlAnimation(animation));
+
+ return this;
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
index 031a887775f..09a59be3360 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs
@@ -283,32 +283,6 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
}
}
- ///
- /// A model representing a specified composition double animation for a target .
- ///
- private sealed record CompositionDoubleAnimationFactory(
- CompositionObject Target,
- string Property,
- float To,
- float? From,
- TimeSpan Delay,
- TimeSpan Duration,
- EasingType EasingType,
- EasingMode EasingMode)
- : ICompositionAnimationFactory
- {
- ///
- public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
- {
- CompositionEasingFunction easingFunction = Target.Compositor.CreateCubicBezierEasingFunction(EasingType, EasingMode);
- ScalarKeyFrameAnimation animation = Target.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction);
-
- target = Target;
-
- return animation;
- }
- }
-
///
/// A model representing a specified XAML animation factory targeting a transform.
///
@@ -335,5 +309,31 @@ public Timeline GetAnimation(DependencyObject targetHint)
return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode));
}
}
+
+ ///
+ /// A model representing an external composition animation with an optional target .
+ ///
+ private sealed record ExternalCompositionAnimation(CompositionObject? Target, CompositionAnimation Animation) : ICompositionAnimationFactory
+ {
+ ///
+ public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target)
+ {
+ target = Target;
+
+ return Animation;
+ }
+ }
+
+ ///
+ /// A model representing an external composition animation with an optional target .
+ ///
+ private sealed record ExternalXamlAnimation(Timeline Animation) : IXamlAnimationFactory
+ {
+ ///
+ public Timeline GetAnimation(DependencyObject targetHint)
+ {
+ return Animation;
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs
similarity index 100%
rename from Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Custom.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
index d5117cfcdda..87d85875906 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.cs
@@ -4,14 +4,12 @@
#nullable enable
-using System;
using System.Diagnostics.Contracts;
using System.Threading.Tasks;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Media.Animation;
-using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
@@ -58,43 +56,6 @@ private AnimationBuilder()
[Pure]
public static AnimationBuilder Create() => new();
- ///
- /// Adds a new custom double animation targeting an arbitrary composition object.
- ///
- /// The target to animate.
- /// The target property to animate.
- /// The final value for the animation.
- /// The optional starting value for the animation.
- /// The optional initial delay for the animation.
- /// The optional animation duration.
- /// The optional easing function type for the animation.
- /// The optional easing function mode for the animation.
- /// The current instance.
- public AnimationBuilder DoubleAnimation(
- CompositionObject target,
- string property,
- double to,
- double? from = null,
- TimeSpan? delay = null,
- TimeSpan? duration = null,
- EasingType easingType = DefaultEasingType,
- EasingMode easingMode = DefaultEasingMode)
- {
- CompositionDoubleAnimationFactory animation = new(
- target,
- property,
- (float)to,
- (float?)from,
- delay ?? DefaultDelay,
- duration ?? DefaultDuration,
- easingType,
- easingMode);
-
- this.compositionAnimationFactories.Add(animation);
-
- return this;
- }
-
///
/// Starts the animations present in the current instance.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index 01c3d830575..3dc529f548d 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -5,8 +5,10 @@
using System;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Toolkit.Uwp.UI.Animations;
+using Microsoft.Toolkit.Uwp.UI.Animations.Extensions;
using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
using Microsoft.Toolkit.Uwp.UI.Media.Effects;
+using Windows.UI.Composition;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -27,15 +29,16 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
{
BlurEffect effect = (BlurEffect)Target;
- return builder.DoubleAnimation(
- effect.Brush,
+ CompositionAnimation animation = effect.Brush.Compositor.CreateScalarKeyFrameAnimation(
$"{effect.Id}.{nameof(GaussianBlurEffect.BlurAmount)}",
- To,
- From,
- Delay ?? delayHint,
- Duration ?? durationHint.GetValueOrDefault(),
- EasingType ?? easingTypeHint ?? DefaultEasingType,
- EasingMode ?? easingModeHint ?? DefaultEasingMode);
+ (float)To,
+ (float?)From,
+ Delay ?? delayHint ?? DefaultDelay,
+ Duration ?? durationHint ?? DefaultDuration,
+ effect.Brush.Compositor.CreateCubicBezierEasingFunction(
+ EasingMode ?? easingModeHint ?? DefaultEasingMode));
+
+ return builder.ExternalAnimation(effect.Brush, animation);
}
}
}
From 232ea5922fff1f1a2cc3e0bf2f3c2efe88485723 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Tue, 22 Dec 2020 20:05:29 +0100
Subject: [PATCH 073/171] Minor code refactoring
---
.../AnimationBuilder.PropertyBuilders.cs | 30 ---------------
.../IPropertyAnimationBuilder{T}.cs | 38 +++++++++++++++++++
.../Animations/EffectDoubleAnimation.cs | 1 +
3 files changed, 39 insertions(+), 30 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
index 9391108d5f7..43660ec787c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs
@@ -16,36 +16,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
public sealed partial class AnimationBuilder
{
- ///
- /// An animation for an animation builder using keyframes, targeting a specific property.
- ///
- /// The type of values being set by the animation being constructed.
- public interface IPropertyAnimationBuilder
- where T : unmanaged
- {
- ///
- /// Adds a custom animation based on normalized keyframes ot the current schedule.
- ///
- /// The callback to use to construct the custom animation.
- /// The optional initial delay for the animation.
- /// The animation duration.
- /// The current instance.
- AnimationBuilder NormalizedKeyFrames(
- Action> build,
- TimeSpan? delay = null,
- TimeSpan? duration = null);
-
- ///
- /// Adds a custom animation based on timed keyframes to the current schedule.
- ///
- /// The callback to use to construct the custom animation.
- /// The optional initial delay for the animation.
- /// The current instance.
- AnimationBuilder TimedKeyFrames(
- Action> build,
- TimeSpan? delay = null);
- }
-
///
/// A custom for a shared animation.
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
new file mode 100644
index 00000000000..e04a5dd6c62
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
@@ -0,0 +1,38 @@
+// 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 System;
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations
+{
+ ///
+ /// An animation for an animation builder using keyframes, targeting a specific property.
+ ///
+ /// The type of values being set by the animation being constructed.
+ public interface IPropertyAnimationBuilder
+ where T : unmanaged
+ {
+ ///
+ /// Adds a custom animation based on normalized keyframes ot the current schedule.
+ ///
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The animation duration.
+ /// The current instance.
+ AnimationBuilder NormalizedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null,
+ TimeSpan? duration = null);
+
+ ///
+ /// Adds a custom animation based on timed keyframes to the current schedule.
+ ///
+ /// The callback to use to construct the custom animation.
+ /// The optional initial delay for the animation.
+ /// The current instance.
+ AnimationBuilder TimedKeyFrames(
+ Action> build,
+ TimeSpan? delay = null);
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
index 3dc529f548d..5816e8fd176 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/EffectDoubleAnimation.cs
@@ -36,6 +36,7 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
Delay ?? delayHint ?? DefaultDelay,
Duration ?? durationHint ?? DefaultDuration,
effect.Brush.Compositor.CreateCubicBezierEasingFunction(
+ EasingType ?? easingTypeHint ?? DefaultEasingType,
EasingMode ?? easingModeHint ?? DefaultEasingMode));
return builder.ExternalAnimation(effect.Brush, animation);
From 1f4806b72118d3a4a9fdcb82c8c558fa80acefcb Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Wed, 23 Dec 2020 01:57:39 +0100
Subject: [PATCH 074/171] Added IsSequential property to animation collections
---
.../Xaml/AnimationCollection2.cs | 42 ++++++++++++++++---
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
index c7dc05cbb0b..cbbd62b0235 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationCollection2.cs
@@ -35,6 +35,24 @@ public sealed class AnimationCollection2 : DependencyObject
///
public IList Animations { get; set; } = new List();
+ ///
+ /// Gets or sets a value indicating whether top level animation nodes in this collection are invoked
+ /// sequentially. This applies to both nodes (which will still trigger
+ /// contained animations at the same time), and other top level animation nodes. The default value
+ /// is , which means that all contained animations will start at the same time.
+ ///
+ /// Note that this property will also cause a change in behavior for the animation. With the default
+ /// configuration, with all animations starting at the same time, it's not possible to use multiple
+ /// animations targeting the same property (as they'll cause a conflict and be ignored when on the
+ /// composition layer, or cause a crash when on the XAML layer). When animations are started sequentially
+ /// instead, each sequential block will be able to share target properties with animations from other
+ /// sequential blocks, without issues. Note that especially for simple scenarios (eg. an opacity animation
+ /// that just transitions to a state and then back, or between two states), it is recommended to use a single
+ /// keyframe animation instead, which will result in less overhead when creating and starting the animation.
+ ///
+ ///
+ public bool IsSequential { get; set; }
+
///
/// Gets or sets the weak reference to the parent that owns the current animation collection.
///
@@ -75,14 +93,28 @@ public async Task StartAsync(UIElement element)
{
Started?.Invoke(this, EventArgs.Empty);
- var builder = AnimationBuilder.Create();
-
- foreach (ITimeline animation in Animations)
+ if (IsSequential)
{
- builder = animation.AppendToBuilder(builder);
+ foreach (ITimeline animation in Animations)
+ {
+ var builder = AnimationBuilder.Create();
+
+ animation.AppendToBuilder(builder);
+
+ await builder.StartAsync(element);
+ }
}
+ else
+ {
+ var builder = AnimationBuilder.Create();
- await builder.StartAsync(element);
+ foreach (ITimeline animation in Animations)
+ {
+ builder = animation.AppendToBuilder(builder);
+ }
+
+ await builder.StartAsync(element);
+ }
Ended?.Invoke(this, EventArgs.Empty);
}
From 86dc1d38642928fd28bc39ca2ce57cc324b03f5f Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Wed, 23 Dec 2020 12:26:31 +0100
Subject: [PATCH 075/171] Moved XAML keyframe types
---
.../Xaml/Abstract/Animation{T}.cs | 8 ++++++
.../Xaml/Abstract/KeyFrame{T}.cs | 26 +++++++++++++++++++
.../KeyFrames/ScalarKeyFrame.cs} | 6 ++---
.../KeyFrames/Vector2KeyFrame.cs} | 7 +++--
.../KeyFrames/Vector3KeyFrame.cs | 5 ++--
.../KeyFrames/Vector4KeyFrame.cs | 5 ++--
6 files changed, 48 insertions(+), 9 deletions(-)
create mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/KeyFrame{T}.cs
rename Microsoft.Toolkit.Uwp.UI.Animations/{CompositionAnimations/KeyFrames/Vector2KeyFrame.cs => Xaml/KeyFrames/ScalarKeyFrame.cs} (65%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{CompositionAnimations/KeyFrames/ScalarKeyFrame.cs => Xaml/KeyFrames/Vector2KeyFrame.cs} (59%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{CompositionAnimations => Xaml}/KeyFrames/Vector3KeyFrame.cs (64%)
rename Microsoft.Toolkit.Uwp.UI.Animations/{CompositionAnimations => Xaml}/KeyFrames/Vector4KeyFrame.cs (64%)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
index 8eac45cb5dc..29ee3721a4c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{T}.cs
@@ -4,6 +4,8 @@
#nullable enable
+using System.Collections.Generic;
+
namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
{
///
@@ -21,5 +23,11 @@ public abstract class Animation : Animation
/// Gets or sets the optional starting value for the animation.
///
public T? From { get; set; }
+
+ ///
+ /// Gets or sets the optional keyframe collection for the current animation.
+ /// Setting this will overwrite the and values.
+ ///
+ public IList> KeyFrames { get; set; } = new List>();
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/KeyFrame{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/KeyFrame{T}.cs
new file mode 100644
index 00000000000..9896a55b940
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/KeyFrame{T}.cs
@@ -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.
+
+#nullable enable
+
+namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
+{
+ ///
+ /// A base model representing a typed keyframe that can be used in XAML.
+ ///
+ /// The type of values for the keyframe.
+ public abstract class KeyFrame
+ {
+ ///
+ /// Gets or sets the key time for the current keyframe. This is a normalized
+ /// value in the [0, 1] range, relative to the total animation duration.
+ ///
+ public double Key { get; set; }
+
+ ///
+ /// Gets or sets the animation value for the current keyframe.
+ ///
+ public T? Value { get; set; }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector2KeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/ScalarKeyFrame.cs
similarity index 65%
rename from Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector2KeyFrame.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/ScalarKeyFrame.cs
index c6286be85ef..5cb49343eae 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector2KeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/ScalarKeyFrame.cs
@@ -2,14 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Numerics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- /// of type
+ /// A type for scalar animations.
///
- public class Vector2KeyFrame : TypedKeyFrame
+ public class ScalarKeyFrame : KeyFrame
{
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/ScalarKeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
similarity index 59%
rename from Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/ScalarKeyFrame.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
index b27e05b6523..b9860185aac 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/ScalarKeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
@@ -2,12 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Numerics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
+
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- /// of type
+ /// A type for animations.
///
- public class ScalarKeyFrame : TypedKeyFrame
+ public class Vector2KeyFrame : KeyFrame
{
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector3KeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
similarity index 64%
rename from Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector3KeyFrame.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
index 98bca721815..ff1ed4dd95f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector3KeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
@@ -3,13 +3,14 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- /// of type
+ /// A type for animations.
///
- public class Vector3KeyFrame : TypedKeyFrame
+ public class Vector3KeyFrame : KeyFrame
{
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector4KeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector4KeyFrame.cs
similarity index 64%
rename from Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector4KeyFrame.cs
rename to Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector4KeyFrame.cs
index f7675638b53..f9509aa0492 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/CompositionAnimations/KeyFrames/Vector4KeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector4KeyFrame.cs
@@ -3,13 +3,14 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
+using Microsoft.Toolkit.Uwp.UI.Animations.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///
- /// of type
+ /// A type for animations.
///
- public class Vector4KeyFrame : TypedKeyFrame
+ public class Vector4KeyFrame : KeyFrame
{
}
}
From 35b29b391ecc6d5ff25b16dd41b534aab1666085 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Wed, 23 Dec 2020 12:53:05 +0100
Subject: [PATCH 076/171] Added support for ObjectAnimationUsingKeyFrames
---
.../Builders/Interfaces/IKeyFrameInfo.cs | 3 +--
.../INormalizedKeyFrameAnimationBuilder{T}.cs | 1 -
.../Interfaces/IPropertyAnimationBuilder{T}.cs | 1 -
.../ITimedKeyFrameAnimationBuilder{T}.cs | 1 -
.../NormalizedKeyFrameAnimationBuilder{T}.cs | 1 -
.../TimedKeyFrameAnimationBuilder{T}.Xaml.cs | 15 +++++++++++++++
.../Builders/TimedKeyFrameAnimationBuilder{T}.cs | 1 -
7 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
index 63764ea2299..f4c52dc78f6 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IKeyFrameInfo.cs
@@ -29,8 +29,7 @@ internal interface IKeyFrameInfo
/// The type of values being set by the animation being constructed.
/// The value for the current keyframe.
[Pure]
- T GetValueAs()
- where T : unmanaged;
+ T GetValueAs();
///
/// Gets the normalized progress for the current keyframe.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
index 20087a60882..316214a240b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/INormalizedKeyFrameAnimationBuilder{T}.cs
@@ -12,7 +12,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
/// The type of values being set by the animation being constructed.
public interface INormalizedKeyFrameAnimationBuilder
- where T : unmanaged
{
///
/// Adds a new normalized keyframe to the builder in use.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
index e04a5dd6c62..13b45040c43 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs
@@ -11,7 +11,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
/// The type of values being set by the animation being constructed.
public interface IPropertyAnimationBuilder
- where T : unmanaged
{
///
/// Adds a custom animation based on normalized keyframes ot the current schedule.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
index 188a154a8fe..9f5c4cde418 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/ITimedKeyFrameAnimationBuilder{T}.cs
@@ -13,7 +13,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
/// The type of values being set by the animation being constructed.
public interface ITimedKeyFrameAnimationBuilder
- where T : unmanaged
{
///
/// Adds a new timed keyframe to the builder in use.
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
index 46d1cc4eaf8..44b70c1fa40 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.cs
@@ -106,7 +106,6 @@ public KeyFrameInfo(
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue GetValueAs()
- where TValue : unmanaged
{
return Unsafe.As(ref Unsafe.AsRef(in this.value));
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
index c94da75dc6b..d9775457b2f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Xaml.cs
@@ -100,6 +100,21 @@ public static Timeline GetAnimation(
animation = colorAnimation;
}
+ else if (typeof(T) == typeof(object))
+ {
+ ObjectAnimationUsingKeyFrames objectAnimation = new() { EnableDependentAnimation = true };
+
+ foreach (var keyFrame in keyFrames)
+ {
+ objectAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame()
+ {
+ KeyTime = keyFrame.GetTimedProgress(duration),
+ Value = keyFrame.GetValueAs()
+ });
+ }
+
+ animation = objectAnimation;
+ }
else
{
return ThrowHelper.ThrowInvalidOperationException("Invalid animation type");
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
index 05319991138..6e1dcfe8fbd 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.cs
@@ -99,7 +99,6 @@ public KeyFrameInfo(
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue GetValueAs()
- where TValue : unmanaged
{
return Unsafe.As(ref Unsafe.AsRef(in this.value));
}
From 8d75564f647155d0dba06941f3ac38ab1a07ebc7 Mon Sep 17 00:00:00 2001
From: Sergio Pedri
Date: Wed, 23 Dec 2020 13:26:37 +0100
Subject: [PATCH 077/171] Switched XAML animation types to strongly typed
---
.../Xaml/Default/OffsetAnimation.cs | 8 ++++----
.../Xaml/Default/ScaleAnimation.cs | 13 +++++++++----
.../Xaml/Default/SizeAnimation.cs | 13 +++++++++----
.../Xaml/Default/TranslationAnimation.cs | 13 +++++++++----
.../Xaml/KeyFrames/Vector2KeyFrame.cs | 2 +-
.../Xaml/KeyFrames/Vector3KeyFrame.cs | 4 ++--
.../Xaml/KeyFrames/Vector4KeyFrame.cs | 2 +-
7 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
index 4ab0528c873..5de866dcd70 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/OffsetAnimation.cs
@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
+using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -12,14 +12,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
///
/// An offset animation working on the composition layer.
///
- public class OffsetAnimation : Animation, ITimeline
+ public class OffsetAnimation : Animation, ITimeline
{
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
return builder.Translation(
- To!.ToVector3(),
- From?.ToVector3(),
+ To.Value,
+ From,
Delay ?? delayHint,
Duration ?? durationHint,
EasingType ?? easingTypeHint ?? DefaultEasingType,
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
index cd4b5a46ef1..c33a951a3c9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ScaleAnimation.cs
@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
+using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
///
/// A scale animation working on the composition or XAML layer.
///
- public class ScaleAnimation : Animation, ITimeline
+ public class ScaleAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
@@ -22,6 +22,8 @@ public class ScaleAnimation : Animation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
+ Vector3 to = To.Value;
+ Vector3? from = From;
TimeSpan? delay = Delay ?? delayHint;
TimeSpan? duration = Duration ?? durationHint;
EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
@@ -29,11 +31,14 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
if (Layer == FrameworkLayer.Composition)
{
- return builder.Scale(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
+ return builder.Scale(to, from, delay, duration, easingType, easingMode);
}
else
{
- return builder.Scale(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ Vector2 to2 = new(to.X, to.Y);
+ Vector2? from2 = from is null ? null : new(from.Value.X, from.Value.Y);
+
+ return builder.Scale(to2, from2, delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
index fddbaa03979..593a7adda59 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/SizeAnimation.cs
@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
+using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
///
/// A size animation working on the composition or XAML layer.
///
- public class SizeAnimation : Animation, ITimeline
+ public class SizeAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
@@ -22,6 +22,8 @@ public class SizeAnimation : Animation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
+ Vector3 to = To.Value;
+ Vector3? from = From;
TimeSpan? delay = Delay ?? delayHint;
TimeSpan? duration = Duration ?? durationHint;
EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
@@ -29,11 +31,14 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
if (Layer == FrameworkLayer.Composition)
{
- return builder.Size(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
+ return builder.Size(to, from, delay, duration, easingType, easingMode);
}
else
{
- return builder.Size(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ Vector2 to2 = new(to.X, to.Y);
+ Vector2? from2 = from is null ? null : new(from.Value.X, from.Value.Y);
+
+ return builder.Size(to2, from2, delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
index 3b7c5974952..9975c633773 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/TranslationAnimation.cs
@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Toolkit.Uwp.UI.Extensions;
+using System.Numerics;
using Windows.UI.Xaml.Media.Animation;
using static Microsoft.Toolkit.Uwp.UI.Animations.Extensions.AnimationExtensions;
@@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations.Xaml
///
/// A translation animation working on the composition or XAML layer.
///
- public class TranslationAnimation : Animation, ITimeline
+ public class TranslationAnimation : Animation, ITimeline
{
///
/// Gets or sets the target framework layer to animate.
@@ -22,6 +22,8 @@ public class TranslationAnimation : Animation, ITimeline
///
AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint)
{
+ Vector3 to = To.Value;
+ Vector3? from = From;
TimeSpan? delay = Delay ?? delayHint;
TimeSpan? duration = Duration ?? durationHint;
EasingType easingType = EasingType ?? easingTypeHint ?? DefaultEasingType;
@@ -29,11 +31,14 @@ AnimationBuilder ITimeline.AppendToBuilder(AnimationBuilder builder, TimeSpan? d
if (Layer == FrameworkLayer.Composition)
{
- return builder.Translation(To!.ToVector3(), From?.ToVector3(), delay, duration, easingType, easingMode);
+ return builder.Translation(to, from, delay, duration, easingType, easingMode);
}
else
{
- return builder.Translation(To!.ToVector2(), From?.ToVector2(), delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
+ Vector2 to2 = new(to.X, to.Y);
+ Vector2? from2 = from is null ? null : new(from.Value.X, from.Value.Y);
+
+ return builder.Translation(to2, from2, delay, duration, easingType, easingMode, FrameworkLayer.Xaml);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
index b9860185aac..0936a652e63 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector2KeyFrame.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
///
/// A type for animations.
///
- public class Vector2KeyFrame : KeyFrame
+ public class Vector2KeyFrame : KeyFrame
{
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
index ff1ed4dd95f..10de95b96aa 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/KeyFrames/Vector3KeyFrame.cs
@@ -8,9 +8,9 @@
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
///