Esempio n. 1
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;
                }
            }
        }