-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
LayerModel+makeAnimationLayer.swift
59 lines (45 loc) · 1.81 KB
/
LayerModel+makeAnimationLayer.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Created by Cal Stephens on 12/20/21.
// Copyright © 2021 Airbnb Inc. All rights reserved.
// MARK: - LayerContext
/// Context available when constructing an `AnimationLayer`
struct LayerContext {
let animation: LottieAnimation
let imageProvider: AnimationImageProvider
let textProvider: AnimationKeypathTextProvider
let fontProvider: AnimationFontProvider
let compatibilityTracker: CompatibilityTracker
var layerName: String
func forLayer(_ layer: LayerModel) -> LayerContext {
var context = self
context.layerName = layer.name
return context
}
}
// MARK: - LayerModel + makeAnimationLayer
extension LayerModel {
/// Constructs an `AnimationLayer` / `CALayer` that represents this `LayerModel`
func makeAnimationLayer(context: LayerContext) throws -> BaseCompositionLayer? {
let context = context.forLayer(self)
if hidden {
return TransformLayer(layerModel: self)
}
switch (type, self) {
case (.precomp, let preCompLayerModel as PreCompLayerModel):
let preCompLayer = PreCompLayer(preCompLayer: preCompLayerModel)
try preCompLayer.setup(context: context)
return preCompLayer
case (.solid, let solidLayerModel as SolidLayerModel):
return SolidLayer(solidLayerModel)
case (.shape, let shapeLayerModel as ShapeLayerModel):
return try ShapeLayer(shapeLayer: shapeLayerModel, context: context)
case (.image, let imageLayerModel as ImageLayerModel):
return ImageLayer(imageLayer: imageLayerModel, context: context)
case (.text, let textLayerModel as TextLayerModel):
return try TextLayer(textLayerModel: textLayerModel, context: context)
case (.null, _):
return TransformLayer(layerModel: self)
case (.unknown, _), (.precomp, _), (.solid, _), (.image, _), (.shape, _), (.text, _):
return nil
}
}
}