internal FillContent(ILottieDrawable lottieDrawable, BaseLayer layer, ShapeFill fill) { _layer = layer; Name = fill.Name; _hidden = fill.IsHidden; _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); }
internal static BaseLayer ForModel(Layer layerModel, ILottieDrawable drawable, LottieComposition composition) { switch (layerModel.GetLayerType()) { case Layer.LayerType.Shape: return(new ShapeLayer(drawable, layerModel)); case Layer.LayerType.PreComp: return(new CompositionLayer(drawable, layerModel, composition.GetPrecomps(layerModel.RefId), composition)); case Layer.LayerType.Solid: return(new SolidLayer(drawable, layerModel)); case Layer.LayerType.Image: return(new ImageLayer(drawable, layerModel)); case Layer.LayerType.Null: return(new NullLayer(drawable, layerModel)); case Layer.LayerType.Text: return(new TextLayer(drawable, layerModel)); case Layer.LayerType.Unknown: default: // Do nothing LottieLog.Warn("Unknown layer type " + layerModel.GetLayerType()); return(null); } }
internal ContentGroup(ILottieDrawable lottieDrawable, BaseLayer layer, string name, bool hidden, List <IContent> contents, AnimatableTransform transform) { Name = name; _hidden = hidden; _contents = contents; if (transform != null) { _transformAnimation = transform.CreateAnimation(); _transformAnimation.AddAnimationsToLayer(layer); _transformAnimation.ValueChanged += (sender, args) => { lottieDrawable.InvalidateSelf(); }; } var greedyContents = new List <IGreedyContent>(); for (var i = contents.Count - 1; i >= 0; i--) { var content = contents[i]; if (content is IGreedyContent greedyContent) { greedyContents.Add(greedyContent); } } for (var i = greedyContents.Count - 1; i >= 0; i--) { greedyContents[i].AbsorbContent(_contents); } }
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 ShapeLayer(ILottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel) { // Naming this __container allows it to be ignored in KeyPath matching. ShapeGroup shapeGroup = new ShapeGroup("__container", layerModel.Shapes, false); _contentGroup = new ContentGroup(lottieDrawable, this, shapeGroup); _contentGroup.SetContents(new List <IContent>(), new List <IContent>()); }
internal ShapeContent(ILottieDrawable lottieDrawable, BaseLayer layer, ShapePath shape) { Name = shape.Name; _lottieDrawable = lottieDrawable; _shapeAnimation = shape.GetShapePath().CreateAnimation(); layer.AddAnimation(_shapeAnimation); _shapeAnimation.ValueChanged += OnValueChanged; }
internal SolidLayer(ILottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel) { LayerModel = layerModel; _paint.Alpha = 0; _paint.Style = Paint.PaintStyle.Fill; _paint.Color = layerModel.SolidColor; }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { if (!drawable.EnableMergePaths()) { Debug.WriteLine("Animation contains merge paths but they are disabled.", LottieLog.Tag); return(null); } return(new MergePathsContent(this)); }
internal StrokeContent(ILottieDrawable lottieDrawable, BaseLayer layer, ShapeStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.MiterLimit, stroke.Opacity, stroke.Width, stroke.LineDashPattern, stroke.DashOffset) { _layer = layer; Name = stroke.Name; _colorAnimation = stroke.Color.CreateAnimation(); _colorAnimation.ValueChanged += OnValueChanged; layer.AddAnimation(_colorAnimation); }
internal BaseStrokeContent(ILottieDrawable lottieDrawable, BaseLayer layer, SKStrokeCap cap, SKStrokeJoin join, float miterLimit, AnimatableIntegerValue opacity, AnimatableFloatValue width, List <AnimatableFloatValue> dashPattern, AnimatableFloatValue offset) { _lottieDrawable = lottieDrawable; _layer = layer; Paint.Style = SKPaintStyle.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; } }
private static List <IContent> ContentsFromModels(ILottieDrawable drawable, BaseLayer layer, List <IContentModel> contentModels) { var contents = new List <IContent>(contentModels.Count); for (var i = 0; i < contentModels.Count; i++) { var content = contentModels[i].ToContent(drawable, layer); if (content != null) { contents.Add(content); } } return(contents); }
internal EllipseContent(ILottieDrawable lottieDrawable, BaseLayer layer, CircleShape circleShape) { Name = circleShape.Name; _lottieDrawable = lottieDrawable; _sizeAnimation = circleShape.Size.CreateAnimation(); _positionAnimation = circleShape.Position.CreateAnimation(); _circleShape = circleShape; layer.AddAnimation(_sizeAnimation); layer.AddAnimation(_positionAnimation); _sizeAnimation.ValueChanged += OnValueChanged; _positionAnimation.ValueChanged += OnValueChanged; }
internal RectangleContent(ILottieDrawable 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; }
internal RepeaterContent(ILottieDrawable 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; }
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; } }
internal GradientStrokeContent(ILottieDrawable lottieDrawable, BaseLayer layer, GradientStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.MiterLimit, 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); }
internal BaseLayer(ILottieDrawable lottieDrawable, Layer layerModel) { LottieDrawable = lottieDrawable; LayerModel = layerModel; _drawTraceName = layerModel.Name + ".Draw"; _contentPaint.SetAlpha(255); _clearPaint.BlendMode = SKBlendMode.Clear; _addMaskPaint.BlendMode = SKBlendMode.DstIn; _addMaskPaint.Color = SKColors.Black; _subtractMaskPaint.BlendMode = SKBlendMode.DstOut; _subtractMaskPaint.Color = SKColors.Black; if (layerModel.GetMatteType() == Layer.MatteType.Invert) { _mattePaint.BlendMode = SKBlendMode.DstOut; } else { _mattePaint.BlendMode = SKBlendMode.DstIn; } _mattePaint.Color = SKColors.Black; Transform = layerModel.Transform.CreateAnimation(); Transform.ValueChanged += OnValueChanged; if (layerModel.Masks != null && layerModel.Masks.Count > 0) { _mask = new MaskKeyframeAnimation(layerModel.Masks); foreach (var animation in _mask.MaskAnimations) { // Don't call AddAnimation() because progress gets set manually in setProgress to // properly handle time scale. animation.ValueChanged += OnValueChanged; } foreach (var animation in _mask.OpacityAnimations) { AddAnimation(animation); animation.ValueChanged += OnValueChanged; } } SetupInOutAnimations(); }
internal TextLayer(ILottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel) { _lottieDrawable = lottieDrawable; _composition = layerModel.Composition; _textAnimation = (TextKeyframeAnimation)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) { _strokeColorAnimation = textProperties._stroke.CreateAnimation(); _strokeColorAnimation.ValueChanged += OnValueChanged; AddAnimation(_strokeColorAnimation); } 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); } }
internal ImageLayer(ILottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel) { }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(new ContentGroup(drawable, layer, this)); }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(new PolystarContent(drawable, layer, this)); }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(new GradientStrokeContent(drawable, layer, this)); }
public TextDelegate(ILottieDrawable drawable) { _drawable = drawable; }
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; } } }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(new TrimPathContent(layer, this)); }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(new EllipseContent(drawable, layer, this)); }
/// <summary> /// This normally needs to be able to invalidate the view/drawable but not for the test. /// </summary> internal TextDelegate() { _drawable = null; }
internal ContentGroup(ILottieDrawable lottieDrawable, BaseLayer layer, ShapeGroup shapeGroup) : this(lottieDrawable, layer, shapeGroup.Name, shapeGroup.IsHidden, ContentsFromModels(lottieDrawable, layer, shapeGroup.Items), FindTransform(shapeGroup.Items)) { }
public IContent ToContent(ILottieDrawable drawable, BaseLayer layer) { return(null); }
public TextDelegate(ILottieDrawable drawable) { _drawable = drawable; _animationView = null; }