A small library to help you embed asynchronous content beautifully in SwiftUI.
SNet is currently focused around one View:
SNetContent
This is used to wrap any remote content calls on the background thread and give your starting content a default value.
For example:
SNetContent(initialView: {
Image("loading")
}, request: {
sleep(3)
return UIImage(systemName: "tortoise")!
}) { img in
Image(uiImage: img!)
}
The SNetContent initializer has three properties:
- The initial view, what is rendered before the remote content is loaded.
- The request, the async code to be ran on appear (is automatically run on the background thread).
- The 'final' view, what is rendered after the remote call completes.
SNet also provides the SNetMicroContent
class, which wraps the existing SNetContent
but provides an input value that conforms to the generic type of the request's output:
SNetMicroContent(initialValue: UIImage(systemName: "pencil.and.outline")!, request: {
sleep(3)
return UIImage(systemName: "tortoise")!
}) { img in
Image(uiImage: img)
}
Finally, SNet also provides SNetImage
and SNetActivityIndicator
. They both work, but aren't too customizable (yet) :
SNetImage(url: URL.init(string: "https://www.locationOfMyImage.com/image.png")!)
.scaledToFit()
.frame(width: 300)
.animation(.easeIn)
ActivityIndicator(isAnimating: .constant(true), style: .large)
All SNet async views can be animated, simply add the animation modifier:
.animation(.easeIn)