lottie-ios 4.4.1 → 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.github/workflows/main.yml +5 -0
  2. package/Lottie.xcodeproj/project.pbxproj +40 -44
  3. package/Lottie.xcworkspace/xcuserdata/calstephens.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  4. package/Lottie.xcworkspace/xcuserdata/calstephens.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +18 -0
  5. package/Package.swift +1 -1
  6. package/README.md +1 -1
  7. package/Rakefile +5 -12
  8. package/Sources/Private/EmbeddedLibraries/EpoxyCore/README.md +3 -4
  9. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/EpoxySwiftUIIntrinsicContentSizeInvalidator.swift +0 -1
  10. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/EpoxySwiftUILayoutMargins.swift +0 -4
  11. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/EpoxyableView+SwiftUIView.swift +0 -4
  12. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift +0 -4
  13. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift +0 -1
  14. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/SwiftUIView.swift +0 -4
  15. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/UIView+SwiftUIView.swift +0 -1
  16. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/UIViewConfiguringSwiftUIView.swift +0 -2
  17. package/Sources/Private/EmbeddedLibraries/EpoxyCore/Views/ViewType.swift +0 -4
  18. package/Sources/Private/MainThread/LayerContainers/Utility/CoreTextRenderLayer.swift +0 -1
  19. package/Sources/Private/Model/DotLottie/DotLottieUtils.swift +3 -5
  20. package/Sources/Private/Utility/Extensions/DataExtension.swift +5 -8
  21. package/Sources/Private/Utility/Extensions/MathKit.swift +2 -2
  22. package/Sources/Private/Utility/Helpers/Binding+Map.swift +0 -1
  23. package/Sources/Private/Utility/Helpers/View+ValueChanged.swift +15 -2
  24. package/Sources/Public/Animation/LottieAnimationHelpers.swift +0 -1
  25. package/Sources/Public/Animation/LottieView.swift +11 -8
  26. package/Sources/Public/Controls/LottieButton.swift +0 -1
  27. package/Sources/Public/Controls/LottieSwitch.swift +0 -1
  28. package/Sources/Public/Controls/LottieViewType.swift +1 -1
  29. package/Sources/Public/DotLottie/DotLottieFileHelpers.swift +0 -5
  30. package/Sources/Public/iOS/LottieAnimationViewBase.swift +1 -5
  31. package/Version.xcconfig +6 -0
  32. package/lottie-ios.podspec +5 -4
  33. package/package.json +1 -1
  34. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/EpoxySwiftUIHostingController.swift +0 -46
  35. package/Sources/Private/EmbeddedLibraries/EpoxyCore/SwiftUI/EpoxySwiftUIHostingView.swift +0 -389
@@ -12,7 +12,6 @@ import SwiftUI
12
12
  ///
13
13
  /// Includes an optional generic `Storage` value, which can be used to compare old and new values
14
14
  /// across state changes to prevent redundant view updates.
15
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
16
15
  struct SwiftUIView<Content: ViewType, Storage>: MeasuringViewRepresentable,
17
16
  UIViewConfiguringSwiftUIView
18
17
  {
@@ -51,7 +50,6 @@ struct SwiftUIView<Content: ViewType, Storage>: MeasuringViewRepresentable,
51
50
 
52
51
  // MARK: UIViewRepresentable
53
52
 
54
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
55
53
  extension SwiftUIView {
56
54
  func makeCoordinator() -> Coordinator {
57
55
  Coordinator(storage: storage)
@@ -98,7 +96,6 @@ extension SwiftUIView {
98
96
 
99
97
  // MARK: SwiftUIView.ConfigurationContext
100
98
 
101
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
102
99
  extension SwiftUIView {
103
100
  /// The configuration context that's available to configure the `Content` view whenever the
104
101
  /// `updateUIView()` method is invoked via a configuration closure.
@@ -130,7 +127,6 @@ extension SwiftUIView {
130
127
 
131
128
  // MARK: SwiftUIView.Coordinator
132
129
 
133
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
134
130
  extension SwiftUIView {
135
131
  /// A coordinator that stores the `storage` associated with this view, enabling the old storage
136
132
  /// value to be accessed during the `updateUIView(…)`.
@@ -6,7 +6,6 @@ import SwiftUI
6
6
 
7
7
  // MARK: - ViewTypeProtocol + swiftUIView
8
8
 
9
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
10
9
  extension ViewTypeProtocol {
11
10
  /// Returns a SwiftUI `View` representing this `UIView`, constructed with the given `makeView`
12
11
  /// closure and sized with the given sizing configuration.
@@ -8,7 +8,6 @@ import SwiftUI
8
8
 
9
9
  /// A protocol describing a SwiftUI `View` that can configure its `UIView` content via an array of
10
10
  /// `configuration` closures.
11
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
12
11
  protocol UIViewConfiguringSwiftUIView: View {
13
12
  /// The context available to this configuration, which provides the `UIView` instance at a minimum
14
13
  /// but can include additional context as needed.
@@ -24,7 +23,6 @@ protocol UIViewConfiguringSwiftUIView: View {
24
23
 
25
24
  // MARK: Extensions
26
25
 
27
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
28
26
  extension UIViewConfiguringSwiftUIView {
29
27
  /// Returns a copy of this view updated to have the given closure applied to its represented view
30
28
  /// whenever it is updated via the `updateUIView(…)` method.
@@ -12,14 +12,12 @@ typealias ViewType = UIView
12
12
 
13
13
  /// The platform's SwiftUI view representable type.
14
14
  /// Either `UIViewRepresentable` on iOS/tvOS or `NSViewRepresentable` on macOS.
15
- @available(iOS 13.0, tvOS 13.0, *)
16
15
  typealias ViewRepresentableType = UIViewRepresentable
17
16
 
18
17
  /// The platform's layout constraint priority type.
19
18
  /// Either `UILayoutPriority` on iOS/tvOS or `NSLayoutConstraint.Priority` on macOS.
20
19
  typealias LayoutPriorityType = UILayoutPriority
21
20
 
22
- @available(iOS 13.0, tvOS 13.0, *)
23
21
  extension ViewRepresentableType {
24
22
  /// The platform's view type for `ViewRepresentableType`.
25
23
  /// Either `UIViewType` on iOS/tvOS or `NSViewType` on macOS.
@@ -35,14 +33,12 @@ typealias ViewType = NSView
35
33
 
36
34
  /// The platform's SwiftUI view representable type.
37
35
  /// Either `UIViewRepresentable` on iOS/tvOS, or `NSViewRepresentable` on macOS.
38
- @available(macOS 10.15, *)
39
36
  typealias ViewRepresentableType = NSViewRepresentable
40
37
 
41
38
  /// The platform's layout constraint priority type.
42
39
  /// Either `UILayoutPriority` on iOS/tvOS, or `NSLayoutConstraint.Priority` on macOS.
43
40
  typealias LayoutPriorityType = NSLayoutConstraint.Priority
44
41
 
45
- @available(macOS 10.15, *)
46
42
  extension ViewRepresentableType {
47
43
  /// The platform's view type for `ViewRepresentableType`.
48
44
  /// Either `UIViewType` on iOS/tvOS or `NSViewType` on macOS.
@@ -184,7 +184,6 @@ final class CoreTextRenderLayer: CALayer {
184
184
  private var needsContentUpdate = false
185
185
 
186
186
  // Draws Debug colors for the font alignment.
187
- @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
188
187
  private func drawDebug(_ ctx: CGContext) {
189
188
  if let font {
190
189
  let ascent = CTFontGetAscent(font)
@@ -15,10 +15,7 @@ enum DotLottieUtils {
15
15
 
16
16
  /// Temp folder to app directory
17
17
  static var tempDirectoryURL: URL {
18
- if #available(iOS 10.0, macOS 10.12, *) {
19
- return FileManager.default.temporaryDirectory
20
- }
21
- return URL(fileURLWithPath: NSTemporaryDirectory())
18
+ FileManager.default.temporaryDirectory
22
19
  }
23
20
  }
24
21
 
@@ -56,7 +53,8 @@ public enum DotLottieError: Error {
56
53
  case noDataLoaded
57
54
  /// Asset with this name was not found in the provided bundle.
58
55
  case assetNotFound(name: String, bundle: Bundle?)
59
- /// Animation loading from asset is not supported on macOS 10.10.
56
+ /// Animation loading from asset was not supported on macOS 10.10,
57
+ /// but this error is no longer used.
60
58
  case loadingFromAssetNotSupported
61
59
 
62
60
  @available(*, deprecated, message: "Unused")
@@ -22,15 +22,12 @@ extension Data {
22
22
  throw DotLottieError.assetNotFound(name: assetName, bundle: bundle)
23
23
  }
24
24
  #else
25
- if #available(macOS 10.11, *) {
26
- if let asset = NSDataAsset(name: assetName, bundle: bundle) {
27
- self = asset.data
28
- return
29
- } else {
30
- throw DotLottieError.assetNotFound(name: assetName, bundle: bundle)
31
- }
25
+ if let asset = NSDataAsset(name: assetName, bundle: bundle) {
26
+ self = asset.data
27
+ return
28
+ } else {
29
+ throw DotLottieError.assetNotFound(name: assetName, bundle: bundle)
32
30
  }
33
- throw DotLottieError.loadingFromAssetNotSupported
34
31
  #endif
35
32
  }
36
33
  }
@@ -272,12 +272,12 @@ extension CGPoint {
272
272
 
273
273
  /// Operator convenience to divide points with /
274
274
  static func / (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
275
- CGPoint(x: lhs.x / CGFloat(rhs), y: lhs.y / CGFloat(rhs))
275
+ CGPoint(x: lhs.x / rhs, y: lhs.y / rhs)
276
276
  }
277
277
 
278
278
  /// Operator convenience to multiply points with *
279
279
  static func * (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
280
- CGPoint(x: lhs.x * CGFloat(rhs), y: lhs.y * CGFloat(rhs))
280
+ CGPoint(x: lhs.x * rhs, y: lhs.y * rhs)
281
281
  }
282
282
 
283
283
  /// Operator convenience to add points with +
@@ -4,7 +4,6 @@
4
4
  #if canImport(SwiftUI)
5
5
  import SwiftUI
6
6
 
7
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
8
7
  extension Binding {
9
8
 
10
9
  /// Helper to transform a `Binding` from one `Value` type to another.
@@ -5,18 +5,31 @@
5
5
  import Combine
6
6
  import SwiftUI
7
7
 
8
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
9
8
  extension View {
10
9
  /// A backwards compatible wrapper for iOS 14 `onChange`
11
10
  @ViewBuilder
12
11
  func valueChanged<T: Equatable>(value: T, onChange: @escaping (T) -> Void) -> some View {
13
- if #available(iOS 14.0, *, macOS 11.0, tvOS 14.0) {
12
+ #if compiler(>=5.9)
13
+ if #available(iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, *) {
14
+ self.onChange(of: value) { _, newValue in
15
+ onChange(newValue)
16
+ }
17
+ } else if #available(iOS 14.0, macOS 11.0, tvOS 14.0, *) {
18
+ self.onChange(of: value, perform: onChange)
19
+ } else {
20
+ onReceive(Just(value)) { value in
21
+ onChange(value)
22
+ }
23
+ }
24
+ #else
25
+ if #available(iOS 14.0, macOS 11.0, tvOS 14.0, *) {
14
26
  self.onChange(of: value, perform: onChange)
15
27
  } else {
16
28
  onReceive(Just(value)) { value in
17
29
  onChange(value)
18
30
  }
19
31
  }
32
+ #endif
20
33
  }
21
34
  }
22
35
  #endif
@@ -171,7 +171,6 @@ extension LottieAnimation {
171
171
  /// - Parameter url: The url to load the animation from.
172
172
  /// - Parameter animationCache: A cache for holding loaded animations. Defaults to `LottieAnimationCache.shared`. Optional.
173
173
  ///
174
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
175
174
  public static func loadedFrom(
176
175
  url: URL,
177
176
  session: URLSession = .shared,
@@ -7,14 +7,13 @@ import SwiftUI
7
7
  // MARK: - LottieView
8
8
 
9
9
  /// A wrapper which exposes Lottie's `LottieAnimationView` to SwiftUI
10
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
11
10
  public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
12
11
 
13
12
  // MARK: Lifecycle
14
13
 
15
14
  /// Creates a `LottieView` that displays the given animation
16
15
  public init(animation: LottieAnimation?) where Placeholder == EmptyView {
17
- _animationSource = State(initialValue: animation.map(LottieAnimationSource.lottieAnimation))
16
+ localAnimation = animation.map(LottieAnimationSource.lottieAnimation)
18
17
  placeholder = nil
19
18
  }
20
19
 
@@ -29,7 +28,7 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
29
28
  /// }
30
29
  /// ```
31
30
  public init(dotLottieFile: DotLottieFile?) where Placeholder == EmptyView {
32
- _animationSource = State(initialValue: dotLottieFile.map(LottieAnimationSource.dotLottieFile))
31
+ localAnimation = dotLottieFile.map(LottieAnimationSource.dotLottieFile)
33
32
  placeholder = nil
34
33
  }
35
34
 
@@ -107,9 +106,9 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
107
106
  _ loadAnimation: @escaping () async throws -> LottieAnimationSource?,
108
107
  @ViewBuilder placeholder: @escaping () -> Placeholder)
109
108
  {
109
+ localAnimation = nil
110
110
  self.loadAnimation = loadAnimation
111
111
  self.placeholder = placeholder
112
- _animationSource = State(initialValue: nil)
113
112
  }
114
113
 
115
114
  // MARK: Public
@@ -454,7 +453,8 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
454
453
 
455
454
  // MARK: Private
456
455
 
457
- @State private var animationSource: LottieAnimationSource?
456
+ private let localAnimation: LottieAnimationSource?
457
+ @State private var remoteAnimation: LottieAnimationSource?
458
458
  private var playbackMode: LottiePlaybackMode?
459
459
  private var animationSpeed: Double?
460
460
  private var reloadAnimationTrigger: AnyEquatable?
@@ -474,12 +474,16 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
474
474
  imageProvider: AnimationImageProvider,
475
475
  imageProvidersAreEqual: (AnimationImageProvider, AnimationImageProvider) -> Bool)?
476
476
 
477
+ private var animationSource: LottieAnimationSource? {
478
+ localAnimation ?? remoteAnimation
479
+ }
480
+
477
481
  private func loadAnimationIfNecessary() {
478
482
  guard let loadAnimation else { return }
479
483
 
480
484
  Task {
481
485
  do {
482
- animationSource = try await loadAnimation()
486
+ remoteAnimation = try await loadAnimation()
483
487
  } catch {
484
488
  logger.warn("Failed to load asynchronous Lottie animation with error: \(error)")
485
489
  }
@@ -490,7 +494,7 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
490
494
  guard loadAnimation != nil else { return }
491
495
 
492
496
  if showPlaceholderWhileReloading {
493
- animationSource = nil
497
+ remoteAnimation = nil
494
498
  }
495
499
 
496
500
  loadAnimationIfNecessary()
@@ -564,7 +568,6 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
564
568
  }
565
569
  }
566
570
 
567
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
568
571
  extension View {
569
572
 
570
573
  /// The `.overlay` modifier that uses a `ViewBuilder` is available in iOS 15+, this helper function helps us to use the same API in older OSs
@@ -5,7 +5,6 @@
5
5
  import SwiftUI
6
6
 
7
7
  /// A wrapper which exposes Lottie's `AnimatedButton` to SwiftUI
8
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
9
8
  public struct LottieButton: UIViewConfiguringSwiftUIView {
10
9
 
11
10
  // MARK: Lifecycle
@@ -5,7 +5,6 @@
5
5
  import SwiftUI
6
6
 
7
7
  /// A wrapper which exposes Lottie's `AnimatedSwitch` to SwiftUI
8
- @available(iOS 13.0, tvOS 13.0, macOS 10.15, *)
9
8
  public struct LottieSwitch: UIViewConfiguringSwiftUIView {
10
9
 
11
10
  // MARK: Lifecycle
@@ -44,7 +44,7 @@ public enum LottieNSControlState: UInt, RawRepresentable {
44
44
  /// - `UIControl.Event` on iOS / tvOS and `LottieNSControlEvent` on macOS.
45
45
  public typealias LottieControlEvent = LottieNSControlEvent
46
46
 
47
- public struct LottieNSControlEvent: Equatable {
47
+ public struct LottieNSControlEvent: Equatable, Sendable {
48
48
 
49
49
  // MARK: Lifecycle
50
50
 
@@ -118,7 +118,6 @@ extension DotLottieFile {
118
118
  /// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
119
119
  /// - Parameter subdirectory: A subdirectory in the bundle in which the lottie is located. Optional.
120
120
  /// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
121
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
122
121
  public static func named(
123
122
  _ name: String,
124
123
  bundle: Bundle = Bundle.main,
@@ -165,7 +164,6 @@ extension DotLottieFile {
165
164
  /// Loads an DotLottie from a specific filepath.
166
165
  /// - Parameter filepath: The absolute filepath of the lottie to load. EG "/User/Me/starAnimation.lottie"
167
166
  /// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
168
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
169
167
  public static func loadedFrom(
170
168
  filepath: String,
171
169
  dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
@@ -204,7 +202,6 @@ extension DotLottieFile {
204
202
  /// - Parameter name: The name of the lottie file in the asset catalog. EG "StarAnimation"
205
203
  /// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
206
204
  /// - Parameter dotLottieCache: A cache for holding loaded lottie files. Defaults to `LRUDotLottieCache.sharedCache` Optional.
207
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
208
205
  public static func asset(
209
206
  named name: String,
210
207
  bundle: Bundle = Bundle.main,
@@ -270,7 +267,6 @@ extension DotLottieFile {
270
267
  ///
271
268
  /// - Parameter url: The url to load the animation from.
272
269
  /// - Parameter animationCache: A cache for holding loaded animations. Defaults to `LRUAnimationCache.sharedCache`. Optional.
273
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
274
270
  public static func loadedFrom(
275
271
  url: URL,
276
272
  session: URLSession = .shared,
@@ -354,7 +350,6 @@ extension DotLottieFile {
354
350
  /// - data: The data(`Foundation.Data`) object to load DotLottie from
355
351
  /// - filename: The name of the lottie file without the lottie extension. eg. "StarAnimation"
356
352
  /// - dispatchQueue: A dispatch queue used to load animations. Defaults to `DispatchQueue.global()`. Optional.
357
- @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
358
353
  public static func loadedFrom(
359
354
  data: Data,
360
355
  filename: String,
@@ -39,11 +39,7 @@ open class LottieAnimationViewBase: UIView {
39
39
 
40
40
  var screenScale: CGFloat {
41
41
  #if os(iOS) || os(tvOS)
42
- if #available(iOS 13.0, tvOS 13.0, *) {
43
- return max(UITraitCollection.current.displayScale, 1)
44
- } else {
45
- return UIScreen.main.scale
46
- }
42
+ max(UITraitCollection.current.displayScale, 1)
47
43
  #else // if os(visionOS)
48
44
  // We intentionally don't check `#if os(visionOS)`, because that emits
49
45
  // a warning when building on Xcode 14 and earlier.
@@ -0,0 +1,6 @@
1
+ // Created by Cal Stephens on 3/12/24.
2
+ // Copyright © 2024 Airbnb Inc. All rights reserved.
3
+
4
+ // The version numbers used when building Lottie.xcframework
5
+ MARKETING_VERSION = 4.4.2
6
+ CURRENT_PROJECT_VERSION = 442 // a three-digit representation of the marketing version, without dots.
@@ -8,7 +8,7 @@
8
8
 
9
9
  Pod::Spec.new do |s|
10
10
  s.name = 'lottie-ios'
11
- s.version = '4.4.1'
11
+ s.version = '4.4.2'
12
12
  s.summary = 'A library to render native animations from bodymovin json'
13
13
 
14
14
  s.description = <<-DESC
@@ -23,9 +23,10 @@ Lottie enables designers to create and ship beautiful animations without an engi
23
23
  s.source = { :git => 'https://github.com/airbnb/lottie-ios.git', :tag => s.version.to_s }
24
24
 
25
25
  s.swift_version = '5.7'
26
- s.ios.deployment_target = '11.0'
27
- s.osx.deployment_target = '10.12'
28
- s.tvos.deployment_target = '11.0'
26
+ s.ios.deployment_target = '13.0'
27
+ s.osx.deployment_target = '10.15'
28
+ s.tvos.deployment_target = '13.0'
29
+ s.visionos.deployment_target = "1.0"
29
30
 
30
31
  s.source_files = 'Sources/**/*.swift'
31
32
  s.resource_bundles = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lottie-ios",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "description": "Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with bodymovin and renders the vector animations natively on mobile and through React Native!",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,46 +0,0 @@
1
- // Created by eric_horacek on 10/8/21.
2
- // Copyright © 2021 Airbnb Inc. All rights reserved.
3
-
4
- #if canImport(SwiftUI) && !os(macOS)
5
- import SwiftUI
6
-
7
- // MARK: - EpoxySwiftUIUIHostingController
8
-
9
- /// A `UIHostingController` that hosts SwiftUI views within an Epoxy container, e.g. an Epoxy
10
- /// `CollectionView`.
11
- ///
12
- /// Exposed internally to allow consumers to reason about these view controllers, e.g. to opt
13
- /// collection view cells out of automated view controller impression tracking.
14
- ///
15
- /// - SeeAlso: `EpoxySwiftUIHostingView`
16
- @available(iOS 13.0, tvOS 13.0, *)
17
- open class EpoxySwiftUIHostingController<Content: View>: UIHostingController<Content> {
18
-
19
- // MARK: Lifecycle
20
-
21
- /// Creates a `UIHostingController` that optionally ignores the `safeAreaInsets` when laying out
22
- /// its contained `RootView`.
23
- convenience init(rootView: Content, ignoreSafeArea: Bool) {
24
- self.init(rootView: rootView)
25
-
26
- // We unfortunately need to call a private API to disable the safe area. We can also accomplish
27
- // this by dynamically subclassing this view controller's view at runtime and overriding its
28
- // `safeAreaInsets` property and returning `.zero`. An implementation of that logic is
29
- // available in this file in the `2d28b3181cca50b89618b54836f7a9b6e36ea78e` commit if this API
30
- // no longer functions in future SwiftUI versions.
31
- _disableSafeArea = ignoreSafeArea
32
- }
33
-
34
- // MARK: Open
35
-
36
- open override func viewDidLoad() {
37
- super.viewDidLoad()
38
-
39
- // A `UIHostingController` has a system background color by default as it's typically used in
40
- // full-screen use cases. Since we're using this view controller to place SwiftUI views within
41
- // other view controllers we default the background color to clear so we can see the views
42
- // below, e.g. to draw highlight states in a `CollectionView`.
43
- view.backgroundColor = .clear
44
- }
45
- }
46
- #endif