Beispiel #1
0
 public AnimationSequence <T> Animate(Easing easing, Action <T> action, Action completed = null, double duration = .2, double delay = 0, string id = null, Lerp lerp = null)
 {
     steps.Add(new AnimationStep <T>
     {
         Easing    = easing,
         Action    = action,
         Completed = completed,
         Duration  = duration,
         Delay     = delay,
         Id        = id,
         Lerp      = lerp,
     });
     return(this);
 }
        public static Animation CreateAnimation <T>(T view, Easing easing, Action <T> action, Action completed = null, double duration = .2, double delay = 0, bool repeats = false, bool autoReverses = false, string id = null, Lerp lerp = null)
            where T : View
        {
            ContextualObject.MonitorChanges();
            action(view);
            var changedProperties       = ContextualObject.StopMonitoringChanges();
            List <Animation> animations = null;

            if (changedProperties.Count == 0)
            {
                return(null);
            }

            if (changedProperties.Count > 1)
            {
                animations = new List <Animation>();
            }

            foreach (var change in changedProperties)
            {
                var prop   = change.Key;
                var values = change.Value;
                if (values.newValue == values.oldValue)
                {
                    continue;
                }
                var animation = new Animation
                {
                    Duration         = duration,
                    Easing           = easing,
                    Repeats          = repeats,
                    StartDelay       = delay,
                    StartValue       = values.oldValue,
                    EndValue         = values.newValue,
                    ContextualObject = prop.view,
                    PropertyName     = prop.property,
                    Id   = id,
                    Lerp = lerp,
                };
                if (autoReverses)
                {
                    animation = animation.CreateAutoReversing();
                }
                if (animations == null)
                {
                    return(animation);
                }
                animations.Add(animation);
            }

            return(new Animation(animations)
            {
                Id = id,
                Duration = duration,
                Easing = easing,
                Repeats = repeats,
            });
        }
 public static T Animate <T>(this T view, Action <T> action, Action completed = null, double duration = .2, double delay = 0, bool repeats = false, bool autoReverses = false, string id = null, Lerp lerp = null)
     where T : View => view.Animate(Easing.Default, action, completed, duration, delay, repeats, autoReverses, id, lerp);
        public static T Animate <T>(this T view, Easing easing, Action <T> action, Action completed = null, double duration = .2, double delay = 0, bool repeats = false, bool autoReverses = false, string id = null, Lerp lerp = null)
            where T : View
        {
            var animation = CreateAnimation(view, easing, action, completed, duration, delay, repeats, autoReverses, id, lerp);

            view.AddAnimation(animation);
            return(view);
        }