Skip to content

Instantly share code, notes, and snippets.

@Aakashcs
Created July 16, 2020 00:16
Show Gist options
  • Save Aakashcs/412ecb75eff3c17b1d56243b7119987c to your computer and use it in GitHub Desktop.
Save Aakashcs/412ecb75eff3c17b1d56243b7119987c to your computer and use it in GitHub Desktop.
Gif Loading View in Swift UI
struct LoadingView: UIViewRepresentable {
@Environment(\.colorScheme) var colorScheme
func makeUIView(context: Context) -> GIFImageView {
let gifImageView = GIFImageView()
gifImageView.animate(withGIFNamed: colorScheme == .light ? "loader-black" : "loader-white") {
print("It's animating!")
}
return gifImageView
}
func updateUIView(_ view: GIFImageView, context: Context) {
}
}
class GIFImageView: UIImageView, GIFAnimatable {
public lazy var animator: Animator? = {
return Animator(withDelegate: self)
}()
override public func display(_ layer: CALayer) {
updateImageIfNeeded()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment