Skip to content

Commit

Permalink
Add LottieView.animationDidLoad API (airbnb#2172)
Browse files Browse the repository at this point in the history
  • Loading branch information
calda authored and Igor Moroz committed May 22, 2024
1 parent d2e5a90 commit ccd3ffb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion Example/Example/AnimationPreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import SwiftUI

// MARK: - AnimationPreviewView

/// TODO: Implement functionality from UIKit `AnimationPreviewViewController`
struct AnimationPreviewView: View {

// MARK: Lifecycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "080DEF612A95707B00BE2D96"
BuildableName = "Lottie_visionOS.framework"
BuildableName = "Lottie.framework"
BlueprintName = "Lottie-visionOS"
ReferencedContainer = "container:Lottie.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -50,7 +50,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "080DEF612A95707B00BE2D96"
BuildableName = "Lottie_visionOS.framework"
BuildableName = "Lottie.framework"
BlueprintName = "Lottie-visionOS"
ReferencedContainer = "container:Lottie.xcodeproj">
</BuildableReference>
Expand Down
13 changes: 12 additions & 1 deletion Sources/Public/Animation/LottieView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
ZStack {
if let animationSource = animationSource {
LottieAnimationView.swiftUIView {
LottieAnimationView(
defer { animationDidLoad?(animationSource) }
return LottieAnimationView(
animationSource: animationSource,
imageProvider: imageProvider,
textProvider: textProvider,
Expand All @@ -132,6 +133,7 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
// prohibitive to do so on every state update.
if animationSource.animation !== context.view.animation {
context.view.loadAnimation(animationSource)
animationDidLoad?(animationSource)
}

if
Expand Down Expand Up @@ -190,6 +192,14 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
return copy
}

/// Returns a copy of this view with the given closure that is called whenever the
/// `LottieAnimationSource` provided via `init` is loaded and applied to the underlying `LottieAnimationView`.
public func animationDidLoad(_ animationDidLoad: @escaping (LottieAnimationSource) -> Void) -> Self {
var copy = self
copy.animationDidLoad = animationDidLoad
return copy
}

/// Returns a copy of this view with the given `LottieCompletionBlock` that is called
/// when an animation finishes playing.
public func animationDidFinish(_ animationCompletionHandler: LottieCompletionBlock?) -> Self {
Expand Down Expand Up @@ -406,6 +416,7 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
private var playbackMode: LottiePlaybackMode?
private var reloadAnimationTrigger: AnyEquatable?
private var loadAnimation: (() async throws -> LottieAnimationSource?)?
private var animationDidLoad: ((LottieAnimationSource) -> Void)?
private var animationCompletionHandler: LottieCompletionBlock?
private var showPlaceholderWhileReloading = false
private var imageProvider: AnimationImageProvider?
Expand Down

0 comments on commit ccd3ffb

Please sign in to comment.