Ejemplo n.º 1
0
 private static void ExecuteCompletionCommand(FrameworkElement element, ActiveTimeline <Timeline> active)
 {
     // If a secondary completion command exists and the completing animation is a
     // secondary animation, execute the corresponding command
     if (GetSecondaryCompletionCommand(element) is ICommand secondaryCompletion &&
         GetSecondary(element) is IAnimationSettings secondary &&
         (AnimationSettings)secondary == active.Settings)
     {
         secondaryCompletion.Execute(null);
     }
Ejemplo n.º 2
0
        private static void RunAnimation(FrameworkElement element, AnimationSettings settings, bool runFromIdle, bool isSequence = false)
        {
            var timeline          = new Timeline();
            var iterationBehavior = GetIterationBehavior(element);
            var iterationCount    = GetIterationCount(element);

            // FADE IN/OUT
            if (settings.Kind.HasFlag(AnimationKind.FadeTo))
            {
                element.FadeTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.FadeFrom))
            {
                element.FadeFrom(settings, ref timeline);
            }

            // ROTATE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.RotateTo))
            {
                element.RotateTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.RotateFrom))
            {
                element.RotateFrom(settings, ref timeline);
            }

            // SCALE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.ScaleXTo))
            {
                element.ScaleXTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleXFrom))
            {
                element.ScaleXFrom(settings, ref timeline);
            }
            if (settings.Kind.HasFlag(AnimationKind.ScaleYTo))
            {
                element.ScaleYTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleYFrom))
            {
                element.ScaleYFrom(settings, ref timeline);
            }
#if __UWP__
            if (settings.Kind.HasFlag(AnimationKind.ScaleZTo))
            {
                element.ScaleZTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleZFrom))
            {
                element.ScaleZFrom(settings, ref timeline);
            }
#endif

            // TRANSLATE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.TranslateXTo))
            {
                element.TranslateXTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateXFrom))
            {
                element.TranslateXFrom(settings, ref timeline);
            }
            if (settings.Kind.HasFlag(AnimationKind.TranslateYTo))
            {
                element.TranslateYTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateYFrom))
            {
                element.TranslateYFrom(settings, ref timeline);
            }
#if __UWP__
            if (settings.Kind.HasFlag(AnimationKind.TranslateZTo))
            {
                element.TranslateZTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateZFrom))
            {
                element.TranslateZFrom(settings, ref timeline);
            }
#endif

            // BLUR TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.BlurTo))
            {
                element.BlurTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.BlurFrom))
            {
                element.BlurFrom(settings, ref timeline);
            }

            ActiveTimeline <Timeline> active = null;

            if (runFromIdle)
            {
                // If the animation is running for an "idle" ActiveTimeline,
                // then it must be set to the existing ActiveTimeline
                // instead of creating a new one
                var guid = GetElementGuid(element);
                active = _actives.SetTimeline(guid, timeline);
            }
            else
            {
                // Add the new ActiveTimeline
                active = _actives.Add(timeline, settings, element, AnimationState.Idle, iterationBehavior, iterationCount, isSequence);
            }

            // We decrement the iteration count right before running the animation
            if (active.IterationCount > 0)
            {
                active.IterationCount--;
            }

            StartTimeline(timeline);
        }
Ejemplo n.º 3
0
        private static void RunAnimation(FrameworkElement element, AnimationSettings settings, bool runFromIdle, bool isSequence = false)
        {
#if !__WPF__
            if (Debugger.IsAttached && GetEnableDebugging(element) == DebugTarget.RunAnimation)
            {
                Debugger.Break();
            }
#endif

            var timeline          = new Timeline();
            var iterationBehavior = GetIterationBehavior(element);
            var iterationCount    = GetIterationCount(element);

            // FADE IN/OUT
            if (settings.Kind.HasFlag(AnimationKind.FadeTo))
            {
                element.FadeTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.FadeFrom))
            {
                element.FadeFrom(settings, ref timeline);
            }

            // ROTATE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.RotateTo))
            {
                element.RotateTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.RotateFrom))
            {
                element.RotateFrom(settings, ref timeline);
            }

// ColorAnimation supported only on Uno and WPF (not on native UWP due to Composition-only implementations)
#if WINDOWS_UWP || HAS_UNO || __WPF__
            // COLOR TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.ColorTo))
            {
                element.ColorTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ColorFrom))
            {
                element.ColorFrom(settings, ref timeline);
            }
#endif

            // SCALE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.ScaleXTo))
            {
                element.ScaleXTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleXFrom))
            {
                element.ScaleXFrom(settings, ref timeline);
            }
            if (settings.Kind.HasFlag(AnimationKind.ScaleYTo))
            {
                element.ScaleYTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleYFrom))
            {
                element.ScaleYFrom(settings, ref timeline);
            }
#if __UWP__
            if (settings.Kind.HasFlag(AnimationKind.ScaleZTo))
            {
                element.ScaleZTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.ScaleZFrom))
            {
                element.ScaleZFrom(settings, ref timeline);
            }
#endif

            // TRANSLATE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.TranslateXTo))
            {
                element.TranslateXTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateXFrom))
            {
                element.TranslateXFrom(settings, ref timeline);
            }
            if (settings.Kind.HasFlag(AnimationKind.TranslateYTo))
            {
                element.TranslateYTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateYFrom))
            {
                element.TranslateYFrom(settings, ref timeline);
            }
#if __UWP__
            if (settings.Kind.HasFlag(AnimationKind.TranslateZTo))
            {
                element.TranslateZTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TranslateZFrom))
            {
                element.TranslateZFrom(settings, ref timeline);
            }
#endif

#if __WPF__ || __UWP__
            // BLUR TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.BlurTo))
            {
                element.BlurTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.BlurFrom))
            {
                element.BlurFrom(settings, ref timeline);
            }
#endif

#if __UWP__
            // SATURATE TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.SaturateTo))
            {
                element.SaturateTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.SaturateFrom))
            {
                element.SaturateFrom(settings, ref timeline);
            }

            // TINT TO/FROM
            if (settings.Kind.HasFlag(AnimationKind.TintTo))
            {
                element.TintTo(settings, ref timeline);
            }
            else if (settings.Kind.HasFlag(AnimationKind.TintFrom))
            {
                element.TintFrom(settings, ref timeline);
            }
#endif

            ActiveTimeline <Timeline> active = null;

            if (runFromIdle)
            {
                // If the animation is running for an "idle" ActiveTimeline,
                // then it must be set to the existing ActiveTimeline
                // instead of creating a new one
                var guid = GetElementGuid(element);
                active = _actives.SetTimeline(guid, timeline);
            }
            else
            {
                // Add the new ActiveTimeline
                active = _actives.Add(timeline, settings, element, AnimationState.Idle, iterationBehavior, iterationCount, isSequence);
            }

            // We decrement the iteration count right before running the animation
            if (active.IterationCount > 0)
            {
                active.IterationCount--;
            }

            StartTimeline(timeline);
        }