Skip to content

Commit

Permalink
Disable experimental composition animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
escape-llc committed Jun 20, 2018
1 parent f9f4139 commit 03e9cf3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define COMPOSITION_ENABLED
#undef COMPOSITION_ENABLED
using eScape.Core;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -318,6 +318,7 @@ FrameworkElement CreateElement(ISeriesItemValueDouble isiv) {
// connect the shim to template root element's Visibility
BindTo(shim, nameof(Visibility), fe, UIElement.VisibilityProperty);
fe.DataContext = shim;
fe.SizeChanged -= Element_SizeChanged;
fe.SizeChanged += Element_SizeChanged;
#if COMPOSITION_ENABLED
UniversalApiContract.v3.CompositionSupport.AttachAnimations(fe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void AttachAnimations(UIElement uix) {
var elementVisual = ElementCompositionPreview.GetElementVisual(uix);
var compositor = elementVisual.Compositor;
var elementImplicitAnimation = compositor.CreateImplicitAnimationCollection();
// Define trigger and animation that should play when the trigger is triggered.
// Define trigger and animation that should play when the trigger is triggered.
elementImplicitAnimation[nameof(Visual.Offset)] = CreateAnimationGroup(compositor, OffsetAnimationDuration);
elementVisual.ImplicitAnimations = elementImplicitAnimation;
}
Expand All @@ -106,4 +106,79 @@ public static void DetachAnimations(UIElement uix) {
}
#endregion
}
}
}
namespace eScapeLLC.UWP.Charts.UniversalApiContract.v4 {
/// <summary>
/// Support class for Composition v4 APIs.
/// <para/>
/// CreateHostbackdropBrush, class <see cref="ElementCompositionPreview"/>,
/// GetPointerPositionPropertySet, SetImplicitHideAnimation, SetImplicitShowAnimation, SetIsTranslationEnabled
/// </summary>
public static class CompositionSupport {
#region API contract info
/// <summary>
/// Where to look for contract.
/// </summary>
public const String CONTRACT = "Windows.Foundation.UniversalApiContract";
/// <summary>
/// Version base APIs appear in.
/// </summary>
public const int VERSION = 4;
/// <summary>
/// Get whether we have API support.
/// </summary>
public static bool IsSupported { get; } = ApiInformation.IsApiContractPresent(CONTRACT, VERSION);
/// <summary>
/// Globally set the duration of the offset animation.
/// </summary>
public static int AnimationDuration { get; set; } = 3250;
#endregion
#region internal (doesn't check CONTRACT)
/// <summary>
/// Create the <see cref="CompositionAnimationGroup"/>.
/// Doesn't check for CONTRACT.
/// </summary>
/// <param name="compositor"></param>
/// <param name="fadein">true: 0..1; false: 1..0.</param>
/// <param name="duration">Duration of animation in MS.</param>
/// <returns>New instance.</returns>
private static ICompositionAnimationBase CreateAnimationGroup(Compositor compositor, bool fadein, int duration) {
// Define Opacity Animation for the Animation group
var animation = compositor.CreateScalarKeyFrameAnimation();
animation.Target = nameof(Visual.Opacity);
animation.InsertKeyFrame(0f, fadein ? 0f : 1f);
animation.InsertKeyFrame(1f, fadein ? 1f : 0f);
animation.Duration = TimeSpan.FromMilliseconds(duration);
var animationGroup = compositor.CreateAnimationGroup();
animationGroup.Add(animation);
return animation;
}
#endregion
#region external (MUST check CONTRACT)
/// <summary>
/// Attach implicit show/hide animations to given element.
/// Creates new instances of everything.
/// </summary>
/// <param name="uix"></param>
public static void AttachAnimations(UIElement uix) {
if (!IsSupported) return;
var elementVisual = ElementCompositionPreview.GetElementVisual(uix);
var compositor = elementVisual.Compositor;
var show = CreateAnimationGroup(compositor, true, AnimationDuration);
ElementCompositionPreview.SetImplicitShowAnimation(uix, show);
var hide = CreateAnimationGroup(compositor, false, AnimationDuration);
ElementCompositionPreview.SetImplicitHideAnimation(uix, hide);
}
/// <summary>
/// Detach implicit animations from given element.
/// </summary>
/// <param name="uix"></param>
public static void DetachAnimations(UIElement uix) {
if (!IsSupported) return;
var elementVisual = ElementCompositionPreview.GetElementVisual(uix);
ElementCompositionPreview.SetImplicitShowAnimation(uix, null);
ElementCompositionPreview.SetImplicitHideAnimation(uix, null);
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]
[assembly: AssemblyVersion("1.5.1.*")]
[assembly: AssemblyFileVersion("1.5.1.*")]
[assembly: ComVisible(false)]

0 comments on commit 03e9cf3

Please sign in to comment.