Esempio n. 1
0
        internal FillContent(LottieDrawable lottieDrawable, BaseLayer layer, ShapeFill fill)
        {
            _layer          = layer;
            Name            = fill.Name;
            _lottieDrawable = lottieDrawable;
            if (fill.Color == null || fill.Opacity == null)
            {
                _colorAnimation   = null;
                _opacityAnimation = null;
                return;
            }

            _path.FillType = fill.FillType;

            _colorAnimation = fill.Color.CreateAnimation();
            _colorAnimation.ValueChanged += (sender, args) =>
            {
                _lottieDrawable.InvalidateSelf();
            };
            layer.AddAnimation(_colorAnimation);
            _opacityAnimation = fill.Opacity.CreateAnimation();
            _opacityAnimation.ValueChanged += (sender, args) =>
            {
                _lottieDrawable.InvalidateSelf();
            };
            layer.AddAnimation(_opacityAnimation);
        }
Esempio n. 2
0
 public void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
 {
     if (property == LottieProperty.Color)
     {
         _colorAnimation.SetValueCallback((ILottieValueCallback <Color?>)callback);
     }
     else if (property == LottieProperty.Opacity)
     {
         _opacityAnimation.SetValueCallback((ILottieValueCallback <int?>)callback);
     }
     else if (property == LottieProperty.ColorFilter)
     {
         if (callback == null)
         {
             _colorFilterAnimation = null;
         }
         else
         {
             _colorFilterAnimation = new ValueCallbackKeyframeAnimation <ColorFilter, ColorFilter>((ILottieValueCallback <ColorFilter>)callback);
             _colorFilterAnimation.ValueChanged += (sender, args) =>
             {
                 _lottieDrawable.InvalidateSelf();
             };
             _layer.AddAnimation(_colorFilterAnimation);
         }
     }
 }
Esempio n. 3
0
 internal StrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, ShapeStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.Opacity, stroke.Width, stroke.LineDashPattern, stroke.DashOffset)
 {
     Name            = stroke.Name;
     _colorAnimation = stroke.Color.CreateAnimation();
     _colorAnimation.ValueChanged += OnValueChanged;
     layer.AddAnimation(_colorAnimation);
 }
        internal GradientFillContent(ILottieDrawable lottieDrawable, BaseLayer layer, GradientFill fill)
        {
            _layer          = layer;
            Name            = fill.Name;
            _hidden         = fill.IsHidden;
            _lottieDrawable = lottieDrawable;
            _type           = fill.GradientType;
            _path.FillType  = fill.FillType;
            _cacheSteps     = (int)(lottieDrawable.Composition.Duration / CacheStepsMs);

            _colorAnimation = fill.GradientColor.CreateAnimation();
            _colorAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_colorAnimation);

            _opacityAnimation = fill.Opacity.CreateAnimation();
            _opacityAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_opacityAnimation);

            _startPointAnimation = fill.StartPoint.CreateAnimation();
            _startPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_startPointAnimation);

            _endPointAnimation = fill.EndPoint.CreateAnimation();
            _endPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_endPointAnimation);
        }
 internal TransformKeyframeAnimation(AnimatableTransform animatableTransform)
 {
     _anchorPoint = animatableTransform.AnchorPoint.CreateAnimation();
     _position    = animatableTransform.Position.CreateAnimation();
     _scale       = animatableTransform.Scale.CreateAnimation();
     _rotation    = animatableTransform.Rotation.CreateAnimation();
     _opacity     = animatableTransform.Opacity.CreateAnimation();
 }
Esempio n. 6
0
 internal ShapeContent(LottieDrawable lottieDrawable, BaseLayer layer, ShapePath shape)
 {
     Name            = shape.Name;
     _lottieDrawable = lottieDrawable;
     _shapeAnimation = shape.GetShapePath().CreateAnimation();
     layer.AddAnimation(_shapeAnimation);
     _shapeAnimation.ValueChanged += OnValueChanged;
 }
Esempio n. 7
0
 internal SplitDimensionPathKeyframeAnimation(IBaseKeyframeAnimation <float?, float?> xAnimation, IBaseKeyframeAnimation <float?, float?> yAnimation)
     : base(new List <Keyframe <Vector2?> >())
 {
     _xAnimation = xAnimation;
     _yAnimation = yAnimation;
     // We need to call an initial setProgress so point gets set with the initial value.
     Progress = Progress;
 }
Esempio n. 8
0
        internal CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List <Layer> layerModels, LottieComposition composition) : base(lottieDrawable, layerModel)
        {
            var timeRemapping = layerModel.TimeRemapping;

            if (timeRemapping != null)
            {
                _timeRemapping = timeRemapping.CreateAnimation();
                AddAnimation(_timeRemapping);
                _timeRemapping.ValueChanged += OnValueChanged;
            }
            else
            {
                _timeRemapping = null;
            }

            var layerMap = new Dictionary <long, BaseLayer>(composition.Layers.Count);

            BaseLayer mattedLayer = null;

            for (var i = layerModels.Count - 1; i >= 0; i--)
            {
                var lm    = layerModels[i];
                var layer = ForModel(lm, lottieDrawable, composition);
                if (layer == null)
                {
                    continue;
                }
                layerMap[layer.LayerModel.Id] = layer;
                if (mattedLayer != null)
                {
                    mattedLayer.MatteLayer = layer;
                    mattedLayer            = null;
                }
                else
                {
                    _layers.Insert(0, layer);
                    switch (lm.GetMatteType())
                    {
                    case Layer.MatteType.Add:
                    case Layer.MatteType.Invert:
                        mattedLayer = layer;
                        break;
                    }
                }
            }

            foreach (var layer in layerMap)
            {
                var layerView = layer.Value;
                AssertNonNullForGitHubIssue(layerMap, layerView);
                if (layerMap.TryGetValue(layerView.LayerModel.ParentId, out BaseLayer parentLayer))
                {
                    layerView.ParentLayer = parentLayer;
                }
            }
        }
Esempio n. 9
0
        internal BaseStrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, CapStyle cap, LineJoin join, float miterLimit, AnimatableIntegerValue opacity, AnimatableFloatValue width, List <AnimatableFloatValue> dashPattern, AnimatableFloatValue offset)
        {
            _lottieDrawable = lottieDrawable;
            _layer          = layer;

            Paint.Style       = Paint.PaintStyle.Stroke;
            Paint.StrokeCap   = cap;
            Paint.StrokeJoin  = join;
            Paint.StrokeMiter = miterLimit;

            _opacityAnimation = opacity.CreateAnimation();
            _widthAnimation   = width.CreateAnimation();

            if (offset == null)
            {
                _dashPatternOffsetAnimation = null;
            }
            else
            {
                _dashPatternOffsetAnimation = offset.CreateAnimation();
            }
            _dashPatternAnimations = new List <IBaseKeyframeAnimation <float?, float?> >(dashPattern.Count);
            _dashPatternValues     = new float[dashPattern.Count];

            for (var i = 0; i < dashPattern.Count; i++)
            {
                _dashPatternAnimations.Add(dashPattern[i].CreateAnimation());
            }

            layer.AddAnimation(_opacityAnimation);
            layer.AddAnimation(_widthAnimation);
            for (var i = 0; i < _dashPatternAnimations.Count; i++)
            {
                layer.AddAnimation(_dashPatternAnimations[i]);
            }
            if (_dashPatternOffsetAnimation != null)
            {
                layer.AddAnimation(_dashPatternOffsetAnimation);
            }

            _opacityAnimation.ValueChanged += OnValueChanged;
            _widthAnimation.ValueChanged   += OnValueChanged;

            for (var i = 0; i < dashPattern.Count; i++)
            {
                _dashPatternAnimations[i].ValueChanged += OnValueChanged;
            }
            if (_dashPatternOffsetAnimation != null)
            {
                _dashPatternOffsetAnimation.ValueChanged += OnValueChanged;
            }
        }
Esempio n. 10
0
        internal EllipseContent(LottieDrawable lottieDrawable, BaseLayer layer, CircleShape circleShape)
        {
            Name               = circleShape.Name;
            _lottieDrawable    = lottieDrawable;
            _sizeAnimation     = circleShape.Size.CreateAnimation();
            _positionAnimation = circleShape.Position.CreateAnimation();

            layer.AddAnimation(_sizeAnimation);
            layer.AddAnimation(_positionAnimation);

            _sizeAnimation.ValueChanged     += OnValueChanged;
            _positionAnimation.ValueChanged += OnValueChanged;
        }
Esempio n. 11
0
 public void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
 {
     if (property == LottieProperty.ColorFilter)
     {
         if (callback == null)
         {
             _colorFilterAnimation = null;
         }
         else
         {
             _colorFilterAnimation = new ValueCallbackKeyframeAnimation <ColorFilter, ColorFilter>((ILottieValueCallback <ColorFilter>)callback);
         }
     }
 }
Esempio n. 12
0
 public override void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
 {
     base.AddValueCallback(property, callback);
     if (property == LottieProperty.ColorFilter)
     {
         if (callback == null)
         {
             _colorFilterAnimation = null;
         }
         else
         {
             _colorFilterAnimation = new ValueCallbackKeyframeAnimation <SKColorFilter, SKColorFilter>((ILottieValueCallback <SKColorFilter>)callback);
         }
     }
 }
Esempio n. 13
0
        internal RectangleContent(LottieDrawable lottieDrawable, BaseLayer layer, RectangleShape rectShape)
        {
            Name                   = rectShape.Name;
            _lottieDrawable        = lottieDrawable;
            _positionAnimation     = rectShape.Position.CreateAnimation();
            _sizeAnimation         = rectShape.Size.CreateAnimation();
            _cornerRadiusAnimation = rectShape.CornerRadius.CreateAnimation();

            layer.AddAnimation(_positionAnimation);
            layer.AddAnimation(_sizeAnimation);
            layer.AddAnimation(_cornerRadiusAnimation);

            _positionAnimation.ValueChanged     += OnValueChanged;
            _sizeAnimation.ValueChanged         += OnValueChanged;
            _cornerRadiusAnimation.ValueChanged += OnValueChanged;
        }
Esempio n. 14
0
        public override void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
        {
            base.AddValueCallback(property, callback);

            if (property == LottieProperty.TimeRemap)
            {
                if (callback == null)
                {
                    _timeRemapping = null;
                }
                else
                {
                    _timeRemapping = new ValueCallbackKeyframeAnimation <float?, float?>((ILottieValueCallback <float?>)callback);
                }
            }
        }
Esempio n. 15
0
        internal TrimPathContent(BaseLayer layer, ShapeTrimPath trimPath)
        {
            Name             = trimPath.Name;
            Type             = trimPath.GetType();
            _startAnimation  = trimPath.Start.CreateAnimation();
            _endAnimation    = trimPath.End.CreateAnimation();
            _offsetAnimation = trimPath.Offset.CreateAnimation();

            layer.AddAnimation(_startAnimation);
            layer.AddAnimation(_endAnimation);
            layer.AddAnimation(_offsetAnimation);

            _startAnimation.ValueChanged  += OnValueChanged;
            _endAnimation.ValueChanged    += OnValueChanged;
            _offsetAnimation.ValueChanged += OnValueChanged;
        }
 public void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
 {
     if (property == LottieProperty.ColorFilter)
     {
         if (callback == null)
         {
             _colorFilterAnimation = null;
         }
         else
         {
             _colorFilterAnimation = new ValueCallbackKeyframeAnimation <SKColorFilter, SKColorFilter>((ILottieValueCallback <SKColorFilter>)callback);
             _colorFilterAnimation.ValueChanged += OnValueChanged;
             _layer.AddAnimation(_colorFilterAnimation);
         }
     }
 }
Esempio n. 17
0
        internal RepeaterContent(LottieDrawable lottieDrawable, BaseLayer layer, Repeater repeater)
        {
            _lottieDrawable = lottieDrawable;
            _layer          = layer;
            Name            = repeater.Name;
            _copies         = repeater.Copies.CreateAnimation();
            layer.AddAnimation(_copies);
            _copies.ValueChanged += OnValueChanged;

            _offset = repeater.Offset.CreateAnimation();
            layer.AddAnimation(_offset);
            _offset.ValueChanged += OnValueChanged;

            _transform = repeater.Transform.CreateAnimation();
            _transform.AddAnimationsToLayer(layer);
            _transform.ValueChanged += OnValueChanged;
        }
Esempio n. 18
0
        internal PolystarContent(ILottieDrawable lottieDrawable, BaseLayer layer, PolystarShape polystarShape)
        {
            _lottieDrawable = lottieDrawable;

            Name                       = polystarShape.Name;
            _type                      = polystarShape.GetType();
            _hidden                    = polystarShape.IsHidden;
            _pointsAnimation           = polystarShape.Points.CreateAnimation();
            _positionAnimation         = polystarShape.Position.CreateAnimation();
            _rotationAnimation         = polystarShape.Rotation.CreateAnimation();
            _outerRadiusAnimation      = polystarShape.OuterRadius.CreateAnimation();
            _outerRoundednessAnimation = polystarShape.OuterRoundedness.CreateAnimation();
            if (_type == PolystarShape.Type.Star)
            {
                _innerRadiusAnimation      = polystarShape.InnerRadius.CreateAnimation();
                _innerRoundednessAnimation = polystarShape.InnerRoundedness.CreateAnimation();
            }
            else
            {
                _innerRadiusAnimation      = null;
                _innerRoundednessAnimation = null;
            }

            layer.AddAnimation(_pointsAnimation);
            layer.AddAnimation(_positionAnimation);
            layer.AddAnimation(_rotationAnimation);
            layer.AddAnimation(_outerRadiusAnimation);
            layer.AddAnimation(_outerRoundednessAnimation);
            if (_type == PolystarShape.Type.Star)
            {
                layer.AddAnimation(_innerRadiusAnimation);
                layer.AddAnimation(_innerRoundednessAnimation);
            }

            _pointsAnimation.ValueChanged           += OnValueChanged;
            _positionAnimation.ValueChanged         += OnValueChanged;
            _rotationAnimation.ValueChanged         += OnValueChanged;
            _outerRadiusAnimation.ValueChanged      += OnValueChanged;
            _outerRoundednessAnimation.ValueChanged += OnValueChanged;
            if (_type == PolystarShape.Type.Star)
            {
                _innerRadiusAnimation.ValueChanged      += OnValueChanged;
                _innerRoundednessAnimation.ValueChanged += OnValueChanged;
            }
        }
Esempio n. 19
0
        internal GradientStrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, GradientStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.Opacity, stroke.Width, stroke.LineDashPattern, stroke.DashOffset)
        {
            Name        = stroke.Name;
            _type       = stroke.GradientType;
            _cacheSteps = (int)(lottieDrawable.Composition.Duration / CacheStepsMs);

            _colorAnimation = stroke.GradientColor.CreateAnimation();
            _colorAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_colorAnimation);

            _startPointAnimation = stroke.StartPoint.CreateAnimation();
            _startPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_startPointAnimation);

            _endPointAnimation = stroke.EndPoint.CreateAnimation();
            _endPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_endPointAnimation);
        }
Esempio n. 20
0
 public override void AddValueCallback <T>(LottieProperty property, ILottieValueCallback <T> callback)
 {
     base.AddValueCallback(property, callback);
     if (property == LottieProperty.StrokeColor)
     {
         _colorAnimation.SetValueCallback((ILottieValueCallback <Color?>)callback);
     }
     else if (property == LottieProperty.ColorFilter)
     {
         if (callback == null)
         {
             _colorFilterAnimation = null;
         }
         else
         {
             _colorFilterAnimation = new ValueCallbackKeyframeAnimation <ColorFilter, ColorFilter>((ILottieValueCallback <ColorFilter>)callback);
             _colorFilterAnimation.ValueChanged += OnValueChanged;
             _layer.AddAnimation(_colorAnimation);
         }
     }
 }
Esempio n. 21
0
        internal TextLayer(LottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel)
        {
            _lottieDrawable              = lottieDrawable;
            _composition                 = layerModel.Composition;
            _textAnimation               = layerModel.Text.CreateAnimation();
            _textAnimation.ValueChanged += OnValueChanged;
            AddAnimation(_textAnimation);

            var textProperties = layerModel.TextProperties;

            if (textProperties?._color != null)
            {
                _colorAnimation = textProperties._color.CreateAnimation();
                _colorAnimation.ValueChanged += OnValueChanged;
                AddAnimation(_colorAnimation);
            }

            if (textProperties?._stroke != null)
            {
                _strokeAnimation = textProperties._stroke.CreateAnimation();
                _strokeAnimation.ValueChanged += OnValueChanged;
                AddAnimation(_strokeAnimation);
            }

            if (textProperties?._strokeWidth != null)
            {
                _strokeWidthAnimation = textProperties._strokeWidth.CreateAnimation();
                _strokeWidthAnimation.ValueChanged += OnValueChanged;
                AddAnimation(_strokeWidthAnimation);
            }

            if (textProperties?._tracking != null)
            {
                _trackingAnimation = textProperties._tracking.CreateAnimation();
                _trackingAnimation.ValueChanged += OnValueChanged;
                AddAnimation(_trackingAnimation);
            }
        }
 public void SetAnimation(IBaseKeyframeAnimation animation)
 {
     _animation = animation;
 }
Esempio n. 23
0
        internal CompositionLayer(ILottieDrawable lottieDrawable, Layer layerModel, List <Layer> layerModels, LottieComposition composition) : base(lottieDrawable, layerModel)
        {
            var timeRemapping = layerModel.TimeRemapping;

            if (timeRemapping != null)
            {
                _timeRemapping = timeRemapping.CreateAnimation();
                AddAnimation(_timeRemapping);
                _timeRemapping.ValueChanged += OnValueChanged;
            }
            else
            {
                _timeRemapping = null;
            }

            var layerMap = new Dictionary <long, BaseLayer>(composition.Layers.Count);

            BaseLayer mattedLayer = null;

            for (var i = layerModels.Count - 1; i >= 0; i--)
            {
                var lm    = layerModels[i];
                var layer = ForModel(lm, lottieDrawable, composition);
                if (layer == null)
                {
                    continue;
                }
                layerMap[layer.LayerModel.Id] = layer;
                if (mattedLayer != null)
                {
                    mattedLayer.MatteLayer = layer;
                    mattedLayer            = null;
                }
                else
                {
                    _layers.Insert(0, layer);
                    switch (lm.GetMatteType())
                    {
                    case Layer.MatteType.Add:
                    case Layer.MatteType.Invert:
                        mattedLayer = layer;
                        break;
                    }
                }
            }

            foreach (var layer in layerMap)
            {
                var layerView = layer.Value;
                // This shouldn't happen but it appears as if sometimes on pre-lollipop devices when
                // compiled with d8, layerView is null sometimes.
                // https://github.com/airbnb/lottie-android/issues/524
                if (layerView == null)
                {
                    continue;
                }
                if (layerMap.TryGetValue(layerView.LayerModel.ParentId, out BaseLayer parentLayer))
                {
                    layerView.ParentLayer = parentLayer;
                }
            }
        }
Esempio n. 24
0
 internal SplitDimensionPathKeyframeAnimation(IBaseKeyframeAnimation <float?, float?> xAnimation, IBaseKeyframeAnimation <float?, float?> yAnimation)
     : base(new List <Keyframe <Vector2?> >())
 {
     _xAnimation = xAnimation;
     _yAnimation = yAnimation;
 }