From c828437239d08dcd82ad3407667d11cf733a7a7d Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 31 Mar 2018 16:32:20 +0800 Subject: [PATCH] Minor fixes. --- samples/ControlCatalog/SideBar.xaml | 14 ++++- samples/RenderTest/MainWindow.xaml | 2 +- samples/RenderTest/Pages/AnimationsPage.xaml | 8 +-- src/Avalonia.Styling/Styling/Style.cs | 14 ++++- .../Animation/Keyframes/TransformKeyFrames.cs | 51 +++++++++++-------- 5 files changed, 60 insertions(+), 29 deletions(-) diff --git a/samples/ControlCatalog/SideBar.xaml b/samples/ControlCatalog/SideBar.xaml index 3013c5a80e..e5baf9e942 100644 --- a/samples/ControlCatalog/SideBar.xaml +++ b/samples/ControlCatalog/SideBar.xaml @@ -1,4 +1,5 @@ - + + + diff --git a/samples/RenderTest/MainWindow.xaml b/samples/RenderTest/MainWindow.xaml index 51da5f342a..dc0d7b1c17 100644 --- a/samples/RenderTest/MainWindow.xaml +++ b/samples/RenderTest/MainWindow.xaml @@ -1,6 +1,6 @@ diff --git a/samples/RenderTest/Pages/AnimationsPage.xaml b/samples/RenderTest/Pages/AnimationsPage.xaml index f8d486bfc4..21ecc3f0bb 100644 --- a/samples/RenderTest/Pages/AnimationsPage.xaml +++ b/samples/RenderTest/Pages/AnimationsPage.xaml @@ -1,7 +1,6 @@ - - - + + - + + diff --git a/src/Avalonia.Styling/Styling/Style.cs b/src/Avalonia.Styling/Styling/Style.cs index 9c6ed71781..5583cb229a 100644 --- a/src/Avalonia.Styling/Styling/Style.cs +++ b/src/Avalonia.Styling/Styling/Style.cs @@ -8,6 +8,7 @@ using System.Reactive.Linq; using Avalonia.Controls; using Avalonia.Metadata; using Avalonia.Animation; +using System.Diagnostics; namespace Avalonia.Styling { @@ -117,7 +118,18 @@ namespace Avalonia.Styling foreach (var animation in Animations) { - subs.Add(animation.Apply((Animatable)control, match.ObservableResult)); + // TODO: Needs more work in passing the appropriate + // observable. + IObservable obsMatch = match.ObservableResult; + + if (match.ImmediateResult == true) + { + obsMatch = Observable.Return(true); + } + + var sub = animation.Apply((Animatable)control, obsMatch); + subs.Add(sub); + } foreach (var setter in Setters) diff --git a/src/Avalonia.Visuals/Animation/Keyframes/TransformKeyFrames.cs b/src/Avalonia.Visuals/Animation/Keyframes/TransformKeyFrames.cs index 4ad7c39bed..814f51bde1 100644 --- a/src/Avalonia.Visuals/Animation/Keyframes/TransformKeyFrames.cs +++ b/src/Avalonia.Visuals/Animation/Keyframes/TransformKeyFrames.cs @@ -16,7 +16,7 @@ namespace Avalonia.Animation.Keyframes public class TransformKeyFrames : KeyFrames { DoubleKeyFrames childKeyFrames; - + /// public override IDisposable Apply(Animation animation, Animatable control, IObservable obsMatch) { @@ -27,45 +27,52 @@ namespace Avalonia.Animation.Keyframes { var renderTransformType = ctrl.RenderTransform.GetType(); + if (childKeyFrames == null) + { + InitializeInternalDoubleKeyFrames(); + } + // It's only 1 transform object so let's target that. if (renderTransformType == Property.OwnerType) { - var targetTransform = Convert.ChangeType(ctrl.RenderTransform, Property.OwnerType); - - if (childKeyFrames == null) - { - childKeyFrames = new DoubleKeyFrames(); - - foreach (KeyFrame k in this) - { - childKeyFrames.Add(k); - } - - childKeyFrames.Property = Property; - } - return childKeyFrames.Apply(animation, ctrl.RenderTransform, obsMatch); } + // TODO: Selection within TransformGroup is not working if (renderTransformType == typeof(TransformGroup)) { - foreach (Transform t in ((TransformGroup)ctrl.RenderTransform).Children) + foreach (Transform transform in ((TransformGroup)ctrl.RenderTransform).Children) { - if (renderTransformType == Property.OwnerType) + if (transform.GetType() == Property.OwnerType) { - + return childKeyFrames.Apply(animation, transform, obsMatch); } } + } + + return null; + + // // Throw exception when there is no appropriate transform object found. + // throw new Exception + // ($"TransformKeyFrame hasn't found an appropriate Transform object with type {Property.OwnerType} in target {control}."); - // not existing in the transform - } } else { - throw new InvalidProgramException($"Unsupported property {Property}"); + throw new Exception($"Unsupported property {Property}"); + } + } + + void InitializeInternalDoubleKeyFrames() + { + childKeyFrames = new DoubleKeyFrames(); + + foreach (KeyFrame keyframe in this) + { + childKeyFrames.Add(keyframe); } - return null; + childKeyFrames.Property = Property; } ///