Exemplo n.º 1
0
        public override Xamarin.Forms.Animation CreateReverseAnimation()
        {
            double A = 0, R = 0, G = 0, B = 0;

            var Parent = new Xamarin.Forms.Animation((d) => Target.GetType().GetProperty(PropertyName).SetValue(Target, Xamarin.Forms.Color.FromRgba(R, G, B, A)), 0, 1, AnimationEasing);


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                A = d;
            }, Xamarin.Forms.Color.FromHex(EndValue.ToString()).A, Xamarin.Forms.Color.FromHex(StartValue.ToString()).A));


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                R = d;
            }, Xamarin.Forms.Color.FromHex(EndValue.ToString()).R, Xamarin.Forms.Color.FromHex(StartValue.ToString()).R));


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                G = d;
            }, Xamarin.Forms.Color.FromHex(EndValue.ToString()).G, Xamarin.Forms.Color.FromHex(StartValue.ToString()).G));

            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                B = d;
            }, Xamarin.Forms.Color.FromHex(EndValue.ToString()).B, Xamarin.Forms.Color.FromHex(StartValue.ToString()).B));



            return(Parent);
        }
Exemplo n.º 2
0
        private Xamarin.Forms.Animation CreateFarwardAnimationForFourValues()
        {
            double v1 = 0, v2 = 0, v3 = 0, v4 = 0;


            var Parent = new Xamarin.Forms.Animation((d) => Target.GetType().GetProperty(PropertyName).SetValue(Target, new CornerRadius(v1, v2, v3, v4)), 0, 1, AnimationEasing);



            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v1 = d;
            }, Convert.ToDouble(_structStartValues[0]), Convert.ToDouble(_structEndValues[0])));


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v2 = d;
            }, Convert.ToDouble(_structStartValues[1]), Convert.ToDouble(_structEndValues[1])));


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v3 = d;
            }, Convert.ToDouble(_structStartValues[2]), Convert.ToDouble(_structEndValues[2])));

            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v4 = d;
            }, Convert.ToDouble(_structStartValues[3]), Convert.ToDouble(_structEndValues[3])));



            return(Parent);
        }
        private void OnButton1Clicked(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            Xamarin.Forms.Animation animation = new Xamarin.Forms.Animation(
                (double value) =>
            {
                button.Scale = value;
            }, 1, 5, Easing.Linear, () =>
            {
                Debug.WriteLine("finished");
            }
                );

            animation.Commit(this, "Animation1", 16, 1000,
                             Easing.Linear, (double finalValue, bool wasCancelled) =>
            {
                Debug.WriteLine("finished: {0} {1}", finalValue, wasCancelled);;
                button.Scale = 1;
            },
                             () =>
            {
                Debug.WriteLine("repeat");
                return(false);
            });
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            double startRotation = 0.0;
            double endRotation;

            if (StartRotation.HasValue)
            {
                startRotation = StartRotation.Value;
            }
            else
            {
                startRotation = element.Rotation;
            }
            if (EndRotation.HasValue)
            {
                endRotation = EndRotation.Value;
            }
            else
            {
                endRotation = startRotation + 360.0;
            }

            var animation = new Xamarin.Forms.Animation();

            element.AnchorX = 0.5;
            element.AnchorY = 0.5;

            animation.WithConcurrent((f) => element.Rotation = f, startRotation, endRotation, Easing);

            return(animation);
        }
        public override Xamarin.Forms.Animation OnAnimate()
        {
            var animation = new Xamarin.Forms.Animation();

            for (var i = 1; i < _sortedKeyFrames.Count; i++)
            {
                var fromFrame = (KeyFrame <TValue>)_sortedKeyFrames[i - 1];
                var toFrame   = (KeyFrame <TValue>)_sortedKeyFrames[i];

                var toFrameEasing = toFrame.Easing != Easing.Linear
                    ? toFrame.Easing
                    : Easing;

                var frameAnimation = new Xamarin.Forms.Animation(x =>
                {
                    var value = Tweener.Tween(fromFrame.Value, toFrame.Value, x);
                    Target.SetValue(TargetProperty, value);
                },
                                                                 easing: toFrameEasing);

                var beginAt = (double)fromFrame.KeyTime / Duration;
                var endAt   = (double)toFrame.KeyTime / Duration;

                animation.Add(beginAt, endAt, frameAnimation);
            }

            return(animation);
        }
        private void OnButton2Clicked(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            Xamarin.Forms.Animation animation = new Xamarin.Forms.Animation(
                v => button.Scale = v, 1, 5);

            animation.Commit(this, "Animation2", 16, 1000, Easing.Linear, (v, c) => button.Scale = 1, () => true);
        }
Exemplo n.º 7
0
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent((f) => element.Opacity = f, 1, 0, null, 0.5, 1);
            animation.WithConcurrent((f) => element.Scale   = f, element.Scale, EndScale, Easing.CubicIn);

            return(animation);
        }
Exemplo n.º 8
0
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var translation = GetTranslation(element);
            var animation   = new Xamarin.Forms.Animation();

            if (FromZDirection != ZDirection.Steady)
            {
                animation.WithConcurrent(
                    f => element.Scale = f,
                    (FromZDirection == ZDirection.Away ? 0.3 : 2.0), 1,
                    Easings.BackOut, 0, 1);
            }
            ;
            animation.WithConcurrent(
                (f) => element.Opacity = f,
                0, 1,
                null,
                0, 0.25);

            switch (FromDirection)
            {
            case CircleDirection.TopLeft:
                DistanceX = Distance * -0.5;
                DistanceY = -Distance;
                break;

            case CircleDirection.TopRight:
                DistanceX = Distance * 0.5;
                DistanceY = -Distance;
                break;

            case CircleDirection.BottomLeft:
                DistanceX = Distance * -0.5;
                DistanceY = Distance;
                break;

            case CircleDirection.BottomRight:
                DistanceX = Distance * 0.5;
                DistanceY = Distance;
                break;
            }

            animation.WithConcurrent(
                (f) => element.TranslationX = f,
                element.TranslationX + DistanceX, element.TranslationX,
                Easings.QuinticOut,
                0, 0.7);

            animation.WithConcurrent(
                (f) => element.TranslationY = f,
                element.TranslationY + DistanceY, element.TranslationY,
                Easings.BackOut,
                0, 1);

            return(animation);
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            // Center of rotation X = 1
            animation.WithConcurrent((f) => element.RotationY = f, 0, 80, Easing.CubicOut);
            animation.WithConcurrent((f) => element.Opacity   = f, 1, 0, null, 0.99, 1);

            return(animation);
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            // CentreOfRotation = Centre
            animation.WithConcurrent((f) => element.RotationX = f, 0, Reverse ? 90 : -90, Easing);
            animation.WithConcurrent((f) => element.Opacity   = f, 1, 0);

            return(animation);
        }
Exemplo n.º 11
0
        internal Xamarin.Forms.Animation FadeIn()
        {
            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent((f) => Target.Opacity = f, 0, 1, Xamarin.Forms.Easing.CubicOut);

            animation.WithConcurrent(
                (f) => Target.TranslationY = f,
                Target.TranslationY + ((Direction == FadeDirection.Up) ? 50 : -50), Target.TranslationY,
                Xamarin.Forms.Easing.CubicOut, 0, 1);

            return(animation);
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent((f) => element.RotationY = f, 0, 170, null, 0, 0.4);
            animation.WithConcurrent((f) => element.RotationY = f, 170, 190, null, 0.4, 0.5);
            animation.WithConcurrent((f) => element.RotationY = f, 190, 360, null, 0.5, 0.8);

            // Scale to 1.1 then back again
            animation.WithConcurrent((f) => element.Scale = f, 1, 1.3, null, 0.5, 0.8);
            animation.WithConcurrent((f) => element.Scale = f, 1.3, 1, null, 0.8, 1);

            return(animation);
        }
Exemplo n.º 13
0
        internal Xamarin.Forms.Animation FadeOut()
        {
            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent(
                (f) => Target.Opacity = f,
                1, 0);

            animation.WithConcurrent(
                (f) => Target.TranslationY = f,
                Target.TranslationY, Target.TranslationY + ((Direction == FadeDirection.Up) ? 50 : -50));

            return(animation);
        }
Exemplo n.º 14
0
        public void PlayReverse()
        {
            uint Length = 0;
            var  Parent = new Xamarin.Forms.Animation();

            for (int i = PropertyAnimations.Count - 1; i >= 0; i--)
            {
                PropertyAnimations[i].Target = IsGlobal ? Target : PropertyAnimations[i].Target;
                Length += PropertyAnimations[i].Length;
                Parent.Add(0, 1, PropertyAnimations[i].CreateReverseAnimation());
            }

            Parent.Commit(Target, $"{nameof(ParallelAnimation)}", Rate, Length, AnimationEasing, GetFinishedAction());
        }
Exemplo n.º 15
0
        public void Play()
        {
            uint Length = 0;
            var  Parent = new Xamarin.Forms.Animation();

            foreach (var propertyAnimation in PropertyAnimations)
            {
                propertyAnimation.Target = IsGlobal ? Target : propertyAnimation.Target;
                Length += propertyAnimation.Length;
                Parent.Add(0, 1, propertyAnimation.CreateFarwardAnimation());
            }


            Parent.Commit(Target, $"{nameof(ParallelAnimation)}", Rate, Length, AnimationEasing, GetFinishedAction());
        }
        private void OnButton3Clicked(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            Xamarin.Forms.Animation parentAnimation = new Xamarin.Forms.Animation();

            Xamarin.Forms.Animation upAnimation = new Xamarin.Forms.Animation(v => button.Scale = v, 1, 5, Easing.SpringIn, () => Debug.WriteLine("up finished"));

            parentAnimation.Add(0, 0.5, upAnimation);

            Xamarin.Forms.Animation downAnimation = new Xamarin.Forms.Animation(v => button.Scale = v, 5, 1, Easing.SpringOut, () => Debug.WriteLine("down finished"));

            parentAnimation.Insert(0.5, 1, downAnimation);

            parentAnimation.Commit(this, "Animation3", 16, 5000, null, (v, c) => Debug.WriteLine("parent finished: {0} {1}", v, c));
        }
Exemplo n.º 17
0
        public override Xamarin.Forms.Animation OnAnimate()
        {
            var animation = new Xamarin.Forms.Animation();

            foreach (var anim in Animations)
            {
                var beginAt  = GetBeginAt(anim);
                var finishAt = GetFinishAt(anim);

                if (anim.Duration > 0)
                {
                    finishAt = Math.Min(finishAt, beginAt + (double)anim.Duration / Duration);
                    Debug.WriteLine($"FinishAt updated to {finishAt}");
                }
                animation.Add(beginAt, finishAt, anim.OnAnimate());
            }

            return(animation);
        }
Exemplo n.º 18
0
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            if (Side == Side.Left)
            {
                element.AnchorX = AnchorX.HasValue ? AnchorX.Value : 0;
                element.AnchorY = AnchorY.HasValue ? AnchorY.Value : 0;

                // Rotation
                animation.WithConcurrent((f) => element.Rotation = f, 0, 80, Easing.CubicInOut, 0, 0.2);
                animation.WithConcurrent((f) => element.Rotation = f, 80, 60, Easing.CubicInOut, 0.2, 0.4);
                animation.WithConcurrent((f) => element.Rotation = f, 60, 80, Easing.CubicInOut, 0.4, 0.6);
                animation.WithConcurrent((f) => element.Rotation = f, 80, 60, Easing.CubicInOut, 0.6, 0.8);
                animation.WithConcurrent((f) => element.Rotation = f, 60, 70, Easing.Linear, 0.8, 1);

                // Fall
                animation.WithConcurrent((f) => element.TranslationY = f, element.TranslationY, element.TranslationY + Distance, Easing.CubicIn, 0.7, 1);

                // Opacity
                animation.WithConcurrent((f) => element.Opacity = f, 1, 0, null, 0.9, 1);
            }
            else
            {
                element.AnchorX = AnchorX.HasValue ? AnchorX.Value : 1;
                element.AnchorY = AnchorY.HasValue ? AnchorY.Value : 0;

                // Rotation
                animation.WithConcurrent((f) => element.Rotation = f, 0, -80, Easing.CubicInOut, 0, 0.2);
                animation.WithConcurrent((f) => element.Rotation = f, -80, -60, Easing.CubicInOut, 0.2, 0.4);
                animation.WithConcurrent((f) => element.Rotation = f, -60, -80, Easing.CubicInOut, 0.4, 0.6);
                animation.WithConcurrent((f) => element.Rotation = f, -80, -60, Easing.CubicInOut, 0.6, 0.8);
                animation.WithConcurrent((f) => element.Rotation = f, -60, -70, Easing.Linear, 0.8, 1);

                // Fall
                animation.WithConcurrent((f) => element.TranslationY = f, element.TranslationY, element.TranslationY + Distance, Easing.CubicIn, 0.7, 1);

                // Opacity
                animation.WithConcurrent((f) => element.Opacity = f, 1, 0, null, 0.9, 1);
            }

            return(animation);
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            if (RotateDirection == RotateAnimationDirection.RotateUp)
            {
                element.AnchorX = 0;
                element.AnchorY = 1.5;

                animation.WithConcurrent((f) => element.Rotation = f, 45, 0, Easing.SinIn);
            }
            else
            {
                element.AnchorX = 0;
                element.AnchorY = -0.5;

                animation.WithConcurrent((f) => element.Rotation = f, -45, 0, Easing.SinIn);
            }
            animation.WithConcurrent((f) => element.Opacity = f, 0, 1, Easing.SinIn, 0, 0.25);

            return(animation);
        }
Exemplo n.º 20
0
        private Xamarin.Forms.Animation CreateReverseAnimationForTwoValues()
        {
            double v1 = 0, v2 = 0;

            var Parent = new Xamarin.Forms.Animation((d) => Target.GetType().GetProperty(PropertyName).SetValue(Target, new Thickness(v1, v2)), 0, 1, AnimationEasing);


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v1 = d;
            }, Convert.ToDouble(_structEndValues[0]), Convert.ToDouble(_structStartValues[0])));


            Parent.Add(0, 1, new Xamarin.Forms.Animation(d =>
            {
                v2 = d;
            }, Convert.ToDouble(_structEndValues[1]), Convert.ToDouble(_structStartValues[1])));



            return(Parent);
        }
Exemplo n.º 21
0
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var translation = GetTranslation(element);
            var animation   = new Xamarin.Forms.Animation();

            element.Opacity = 1;
            animation.WithConcurrent(
                (f) => element.Opacity = f,
                1, 0,
                null,
                0.5, 1);

            if (ToDirection != ZDirection.Steady)
            {
                animation.WithConcurrent(
                    (f) => element.Scale = f,
                    1, (ToDirection == ZDirection.Away ? 0.3 : 2.0),
                    Easings.BackIn, 0, 1);
            }
            if (Math.Abs(DistanceX) > 0)
            {
                animation.WithConcurrent(
                    (f) => element.TranslationX = f,
                    element.TranslationX, element.TranslationX + DistanceX,
                    Easings.BackIn,
                    0, 1);
            }
            if (Math.Abs(DistanceY) > 0)
            {
                animation.WithConcurrent(
                    (f) => element.TranslationX = f,
                    element.TranslationY, element.TranslationY + DistanceY,
                    Easings.BackIn,
                    0, 1);
            }

            return(animation);
        }
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent(
                (f) => element.Opacity = f,
                1, 0);

            if (Math.Abs(DistanceX) > 0)
            {
                animation.WithConcurrent(
                    (f) => element.TranslationX = f,
                    element.TranslationX, element.TranslationX + DistanceX);
            }
            if (Math.Abs(DistanceY) > 0)
            {
                animation.WithConcurrent(
                    (f) => element.TranslationY = f,
                    element.TranslationY, element.TranslationY + DistanceY);
            }

            return(animation);
        }
Exemplo n.º 23
0
        public override Xamarin.Forms.Animation CreateAnimation(VisualElement element)
        {
            var toBounds   = element.Bounds;
            var fromBounds = FromElement.Bounds;

            element.Layout(fromBounds);
            element.AnchorX = 0;
            element.AnchorY = 0;

            var animation = new Xamarin.Forms.Animation();

            animation.WithConcurrent((f) => element.Opacity = f, 0, 1, null, 0, 0.25);
            animation.WithConcurrent((f) =>
            {
                var newBounds = new Rectangle(
                    fromBounds.X + (toBounds.X - fromBounds.X) * f,
                    fromBounds.Y + (toBounds.Y - fromBounds.Y) * f,
                    fromBounds.Width + (toBounds.Width - fromBounds.Width) * f,
                    fromBounds.Height + (toBounds.Height - fromBounds.Height) * f);
                element.Layout(newBounds);
            });

            return(animation);
        }
Exemplo n.º 24
0
        public void PlayReverse()
        {
            Xamarin.Forms.Animation PropertyAnimation = CreateReverseAnimation();

            PropertyAnimation.Commit(Target, $"{Target.ToString()}{PropertyName}Animation{Guid.NewGuid()}", Rate, Length, AnimationEasing, GetFinishedAction());
        }