コード例 #1
0
        public void Dispose()
        {
            var task = CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                _lottieDrawable.ClearComposition();
                _lottieDrawable = null;
            }).AsTask();

            task.Wait();
        }
コード例 #2
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.Add(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;
                if (layerMap.TryGetValue(layerView.LayerModel.ParentId, out BaseLayer parentLayer))
                {
                    layerView.ParentLayer = parentLayer;
                }
            }
        }
コード例 #3
0
 public async Task TestMaxFrame()
 {
     await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         var composition = CreateComposition(31, 391);
         var drawable    = new LottieDrawable();
         drawable.SetComposition(composition);
         drawable.MaxProgress = 0.25f;
         Assert.Equal(121f, drawable.MaxFrame);
     });
 }
コード例 #4
0
 public async Task TestMinWithStartFrameFrame()
 {
     await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         var composition = CreateComposition(100, 200);
         var drawable    = new LottieDrawable();
         drawable.SetComposition(composition);
         drawable.MinProgress = 0.5f;
         Assert.Equal(150f, drawable.MinFrame);
     });
 }
コード例 #5
0
        public KeyPathTest()
        {
            var task = CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                _lottieDrawable = new LottieDrawable();

                LottieComposition composition = LottieCompositionFactory.FromJsonStringSync(Fixtures.Squares, "squares").Value;
                _lottieDrawable.SetComposition(composition);
            }).AsTask();

            task.Wait();
        }
コード例 #6
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;
            }
        }
コード例 #7
0
ファイル: EllipseContent.cs プロジェクト: 07101994/LottieUWP
        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;
        }
コード例 #8
0
        private static List <IContent> ContentsFromModels(LottieDrawable 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);
        }
コード例 #9
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;
        }
コード例 #10
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;
        }
コード例 #11
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);
        }
コード例 #12
0
        internal PolystarContent(LottieDrawable lottieDrawable, BaseLayer layer, PolystarShape polystarShape)
        {
            _lottieDrawable = lottieDrawable;

            Name                       = polystarShape.Name;
            _type                      = polystarShape.GetType();
            _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)
            {
                _outerRadiusAnimation.ValueChanged      += OnValueChanged;
                _outerRoundednessAnimation.ValueChanged += OnValueChanged;
            }
        }
コード例 #13
0
        public KeyPathTest()
        {
            var task = CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                _lottieDrawable = new LottieDrawable();

                try
                {
                    LottieComposition composition = LottieComposition.Factory.FromJsonSync(new JsonReader(new StringReader(Fixtures.Squares)));
                    _lottieDrawable.SetComposition(composition);
                }
                catch (IOException e)
                {
                    throw new ArgumentException(e.Message, e);
                }
            }).AsTask();

            task.Wait();
        }
コード例 #14
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var localDir = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");

            var file = await localDir.GetFileAsync("test.json");

            var json = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8);

            await LottieView.SetAnimationFromJsonAsync(json, "test");

            var compositionResult = await LottieCompositionFactory.FromJsonString(json, "test");

            if (compositionResult.Value != null)
            {
                LottieDrawable.SetComposition(compositionResult.Value);
                LottieDrawable.RepeatCount = -1;
                LottieDrawable.PlayAnimation();
            }

            LottieView.PlayAnimation();
        }
コード例 #15
0
        internal BaseLayer(LottieDrawable lottieDrawable, Layer layerModel)
        {
            LottieDrawable              = lottieDrawable;
            LayerModel                  = layerModel;
            _drawTraceName              = layerModel.Name + ".Draw";
            _contentPaint.Alpha         = 255;
            _clearPaint.Xfermode        = new PorterDuffXfermode(PorterDuff.Mode.Clear);
            _addMaskPaint.Xfermode      = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            _subtractMaskPaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstOut);
            if (layerModel.GetMatteType() == Layer.MatteType.Invert)
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstOut);
            }
            else
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            }

            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();
        }
コード例 #16
0
ファイル: TextLayer.cs プロジェクト: HHChaos/LottieUwpTest2
        internal TextLayer(LottieDrawable 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);
            }
        }
コード例 #17
0
        internal BaseLayer(LottieDrawable lottieDrawable, Layer layerModel)
        {
            LottieDrawable       = lottieDrawable;
            LayerModel           = layerModel;
            _drawTraceName       = layerModel.Name + ".Draw";
            _clearPaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.Clear);
            _maskPaint.Xfermode  = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            if (layerModel.GetMatteType() == Layer.MatteType.Invert)
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstOut);
            }
            else
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            }

            Transform = layerModel.Transform.CreateAnimation();
            Transform.ValueChanged += OnValueChanged;
            Transform.AddAnimationsToLayer(this);

            if (layerModel.Masks != null && layerModel.Masks.Count > 0)
            {
                _mask = new MaskKeyframeAnimation(layerModel.Masks);
                foreach (var animation in _mask.MaskAnimations)
                {
                    AddAnimation(animation);
                    animation.ValueChanged += OnValueChanged;
                }
                foreach (var animation in _mask.OpacityAnimations)
                {
                    AddAnimation(animation);
                    animation.ValueChanged += OnValueChanged;
                }
            }
            SetupInOutAnimations();
        }
コード例 #18
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var localDir = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");

            var file = await localDir.GetFileAsync("test.json");

            var json = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8);

            _drawForCanvas = new LottieDrawable();

            await LottieView.SetAnimationFromJsonAsync(json);

            var composition = await LottieComposition.Factory.FromJsonStringAsync(json);

            LottieDrawable.SetComposition(composition);
            LottieDrawable.RepeatCount = -1;
            _drawForCanvas.SetComposition(composition);
            _drawForCanvas.RepeatCount = -1;
            _inited = true;

            LottieView.PlayAnimation();
            LottieDrawable.PlayAnimation();
            _drawForCanvas.PlayAnimation();
        }
コード例 #19
0
        internal GradientFillContent(LottieDrawable lottieDrawable, BaseLayer layer, GradientFill fill)
        {
            Name            = fill.Name;
            _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);
        }
コード例 #20
0
 public LottieValueAnimator(LottieDrawable lottieDrawable)
 {
     this.lottieDrawable = lottieDrawable;
 }
コード例 #21
0
 internal ImageLayer(LottieDrawable lottieDrawable, Layer layerModel, float density) : base(lottieDrawable, layerModel)
 {
     _density = density;
 }
コード例 #22
0
 public IContent ToContent(LottieDrawable drawable, BaseLayer layer)
 {
     return(null);
 }
コード例 #23
0
ファイル: CircleShape.cs プロジェクト: HHChaos/LottieUwpTest2
 public IContent ToContent(LottieDrawable drawable, BaseLayer layer)
 {
     return(new EllipseContent(drawable, layer, this));
 }
コード例 #24
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;
                // 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;
                }
            }
        }
コード例 #25
0
 internal ContentGroup(LottieDrawable lottieDrawable, BaseLayer layer, ShapeGroup shapeGroup)
     : this(lottieDrawable, layer, shapeGroup.Name,
            ContentsFromModels(lottieDrawable, layer, shapeGroup.Items),
            FindTransform(shapeGroup.Items))
 {
 }
コード例 #26
0
 internal NullLayer(LottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel)
 {
 }
コード例 #27
0
ファイル: GradientFill.cs プロジェクト: 07101994/LottieUWP
 public IContent ToContent(LottieDrawable drawable, BaseLayer layer)
 {
     return(new GradientFillContent(drawable, layer, this));
 }
コード例 #28
0
 public IContent ToContent(LottieDrawable drawable, BaseLayer layer)
 {
     return(new PolystarContent(drawable, layer, this));
 }
コード例 #29
0
 public IContent ToContent(LottieDrawable drawable, BaseLayer layer)
 {
     return(new TrimPathContent(layer, this));
 }
コード例 #30
0
 internal ImageLayer(LottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel)
 {
 }