Created
July 16, 2020 00:16
-
-
Save Aakashcs/412ecb75eff3c17b1d56243b7119987c to your computer and use it in GitHub Desktop.
Gif Loading View in Swift UI
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
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