Created
January 6, 2023 21:09
-
-
Save navsing/ddc7184149b36c1689e2058b3a492fcf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
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