Last active
August 17, 2020 21:18
-
-
Save pMalvasio/73184eb5142139cad9a92a7752fb2752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import Lottie | |
struct LottieView: UIViewRepresentable { | |
typealias UIViewType = UIView | |
var filename: String | |
func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView { | |
let view = UIView(frame: .zero) | |
let animationView = AnimationView() | |
let animation = Animation.named(filename) | |
animationView.animation = animation | |
animationView.contentMode = .scaleAspectFit | |
animationView.play() | |
animationView.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(animationView) | |
NSLayoutConstraint.activate([ | |
animationView.widthAnchor.constraint(equalTo: view.widthAnchor), | |
animationView.heightAnchor.constraint(equalTo: view.heightAnchor), | |
animationView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | |
animationView.centerYAnchor.constraint(equalTo: view.centerYAnchor) | |
]) | |
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