Skip to content

Instantly share code, notes, and snippets.

@navsing
Created January 6, 2023 21:09
Show Gist options
  • Save navsing/ddc7184149b36c1689e2058b3a492fcf to your computer and use it in GitHub Desktop.
Save navsing/ddc7184149b36c1689e2058b3a492fcf to your computer and use it in GitHub Desktop.
import SwiftUI
import Lottie
struct LottieView: UIViewRepresentable {
let animationView = AnimationView()
var lottieFile = ""
func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
let view = UIView()
let animation = Animation.named(filename)
animationView.animation = animation
animationView.contentMode = .scaleAspectFit
animationView.loopMode = .loop
animationView.play()
animationView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(animationView)
NSLayoutConstraint.activate([
animationView.heightAnchor.constraint(equalTo: view.heightAnchor),
animationView.widthAnchor.constraint(equalTo: view.widthAnchor)
])
return view
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment