From 9c84c44b58bf10fa246137662d52f1d5464904b9 Mon Sep 17 00:00:00 2001 From: karkarl <7976322+karkarl@users.noreply.github.com> Date: Tue, 28 Jan 2025 16:33:46 -0800 Subject: [PATCH] remove elementAnimator --- WinUIGallery/Common/DefaultElementAnimator.cs | 128 ------------------ .../ControlPages/ItemsRepeaterPage.xaml | 2 - .../ControlPages/ItemsRepeaterPage.xaml.cs | 6 - .../ItemsRepeater/ItemsRepeaterSample4_cs.txt | 8 -- WinUIGallery/Directory.Build.props | 2 - 5 files changed, 146 deletions(-) delete mode 100644 WinUIGallery/Common/DefaultElementAnimator.cs diff --git a/WinUIGallery/Common/DefaultElementAnimator.cs b/WinUIGallery/Common/DefaultElementAnimator.cs deleted file mode 100644 index 113f0bf78..000000000 --- a/WinUIGallery/Common/DefaultElementAnimator.cs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Microsoft.UI.Xaml.Controls; -using System; -using System.Numerics; -using Windows.Foundation; -using Microsoft.UI.Composition; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Hosting; - -namespace WinUIGallery.Common; - -#if WINUI_PRERELEASE -public class DefaultElementAnimator : ElementAnimator -{ - private const double DefaultAnimationDurationInMs = 300.0; - public static double AnimationSlowdownFactor { get; set; } - - static DefaultElementAnimator() - { - AnimationSlowdownFactor = 1.0; - } - - protected override bool HasShowAnimationCore(UIElement element, AnimationContext context) - { - return true; - } - - protected override bool HasHideAnimationCore(UIElement element, AnimationContext context) - { - return true; - } - - protected override bool HasBoundsChangeAnimationCore( - UIElement element, - AnimationContext context, - Rect oldBounds, - Rect newBounds) - { - return true; - } - - protected override void StartShowAnimation(UIElement element, AnimationContext context) - { - var visual = ElementCompositionPreview.GetElementVisual(element); - var compositor = visual.Compositor; - - var fadeInAnimation = compositor.CreateScalarKeyFrameAnimation(); - fadeInAnimation.InsertKeyFrame(0.0f, 0.0f); - - if (HasBoundsChangeAnimationsPending && HasHideAnimationsPending) - { - fadeInAnimation.InsertKeyFrame(0.66f, 0.0f); - } - else if (HasBoundsChangeAnimationsPending || HasHideAnimationsPending) - { - fadeInAnimation.InsertKeyFrame(0.5f, 0.0f); - } - - fadeInAnimation.InsertKeyFrame(1.0f, 1.0f); - fadeInAnimation.Duration = TimeSpan.FromMilliseconds( - DefaultAnimationDurationInMs * ((HasHideAnimationsPending ? 1 : 0) + (HasBoundsChangeAnimationsPending ? 1 : 0) + 1) * AnimationSlowdownFactor); - - var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); - visual.StartAnimation("Opacity", fadeInAnimation); - batch.End(); - batch.Completed += delegate { OnShowAnimationCompleted(element); }; - } - - protected override void StartHideAnimation(UIElement element, AnimationContext context) - { - var visual = ElementCompositionPreview.GetElementVisual(element); - var compositor = visual.Compositor; - - var fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation(); - fadeOutAnimation.InsertExpressionKeyFrame(0.0f, "this.CurrentValue"); - fadeOutAnimation.InsertKeyFrame(1.0f, 0.0f); - fadeOutAnimation.Duration = TimeSpan.FromMilliseconds(DefaultAnimationDurationInMs * AnimationSlowdownFactor); - - var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); - visual.StartAnimation("Opacity", fadeOutAnimation); - batch.End(); - batch.Completed += delegate - { - visual.Opacity = 1.0f; - OnHideAnimationCompleted(element); - }; - } - - protected override void StartBoundsChangeAnimation(UIElement element, AnimationContext context, Rect oldBounds, Rect newBounds) - { - var visual = ElementCompositionPreview.GetElementVisual(element); - var compositor = visual.Compositor; - var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); - - // Animate offset. - if (oldBounds.X != newBounds.X || - oldBounds.Y != newBounds.Y) - { - AnimateOffset(element, visual, compositor, oldBounds, newBounds); - } - - batch.End(); - batch.Completed += delegate { OnBoundsChangeAnimationCompleted(element); }; - } - - private void AnimateOffset(UIElement element, Visual visual, Compositor compositor, Rect oldBounds, Rect newBounds) - { - var offsetAnimation = compositor.CreateVector2KeyFrameAnimation(); - - offsetAnimation.SetVector2Parameter("delta", new Vector2( - (float)(oldBounds.X - newBounds.X), - (float)(oldBounds.Y - newBounds.Y))); - offsetAnimation.SetVector2Parameter("final", new Vector2()); - offsetAnimation.InsertExpressionKeyFrame(0.0f, "this.CurrentValue + delta"); - if (HasHideAnimationsPending) - { - offsetAnimation.InsertExpressionKeyFrame(0.5f, "delta"); - } - offsetAnimation.InsertExpressionKeyFrame(1.0f, "final"); - offsetAnimation.Duration = TimeSpan.FromMilliseconds( - DefaultAnimationDurationInMs * ((HasHideAnimationsPending ? 1 : 0) + 1) * AnimationSlowdownFactor); - - visual.StartAnimation("TransformMatrix._41_42", offsetAnimation); - } -} -#endif diff --git a/WinUIGallery/ControlPages/ItemsRepeaterPage.xaml b/WinUIGallery/ControlPages/ItemsRepeaterPage.xaml index cf32ae3f6..74cdb463b 100644 --- a/WinUIGallery/ControlPages/ItemsRepeaterPage.xaml +++ b/WinUIGallery/ControlPages/ItemsRepeaterPage.xaml @@ -332,8 +332,6 @@ private void InitializeData() HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,20" TextChanged="FilterRecipes_FilterChanged"/> Enable Animations -