๐Ÿ“ฆ airbnb / lottie-ios

๐Ÿ“„ SolidLayerModel.swift ยท 64 lines
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
60
61
62
63
64//
//  SolidLayer.swift
//  lottie-swift
//
//  Created by Brandon Withrow on 1/8/19.
//

// MARK: - SolidLayerModel

/// A layer that holds a solid color.
final class SolidLayerModel: LayerModel {

  // MARK: Lifecycle

  required init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: SolidLayerModel.CodingKeys.self)
    colorHex = try container.decode(String.self, forKey: .colorHex)
    width = try container.decode(Double.self, forKey: .width)
    height = try container.decode(Double.self, forKey: .height)
    try super.init(from: decoder)
  }

  required init(dictionary: [String: Any]) throws {
    colorHex = try dictionary.value(for: CodingKeys.colorHex)
    width = try dictionary.value(for: CodingKeys.width)
    height = try dictionary.value(for: CodingKeys.height)
    try super.init(dictionary: dictionary)
  }

  // MARK: Internal

  /// The color of the solid in Hex // Change to value provider.
  let colorHex: String

  /// The Width of the color layer
  let width: Double

  /// The height of the color layer
  let height: Double

  override func encode(to encoder: Encoder) throws {
    try super.encode(to: encoder)
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(colorHex, forKey: .colorHex)
    try container.encode(width, forKey: .width)
    try container.encode(height, forKey: .height)
  }

  // MARK: Private

  private enum CodingKeys: String, CodingKey {
    case colorHex = "sc"
    case width = "sw"
    case height = "sh"
  }
}

// MARK: @unchecked Sendable

/// `SolidLayerModel` inherits `@unchecked Sendable` from `LayerModel` and
/// we need to restate that here to avoid a warning in Xcode 16
// swiftlint:disable:next no_unchecked_sendable
extension SolidLayerModel: @unchecked Sendable { }