Update the readme demo code to use swifty syntax
This commit is contained in:
parent
2b1ac930c9
commit
3a0995b791
|
@ -94,11 +94,11 @@ struct ContentView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.onDelete(perform: { (indexSet) in
|
||||
indexSet.forEach { (index) in
|
||||
.onDelete { indexSet in
|
||||
indexSet.forEach { index in
|
||||
self.imageURLs.remove(at: index)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,25 +53,25 @@ struct DetailView: View {
|
|||
HStack {
|
||||
if animated {
|
||||
AnimatedImage(url: URL(string:url), options: [.progressiveLoad], isAnimating: $isAnimating)
|
||||
.onProgress(perform: { (receivedSize, expectedSize) in
|
||||
.onProgress { receivedSize, expectedSize in
|
||||
// SwiftUI engine itself ensure the main queue dispatch
|
||||
if (expectedSize >= 0) {
|
||||
if (expectedSize > 0) {
|
||||
self.progress = CGFloat(receivedSize) / CGFloat(expectedSize)
|
||||
} else {
|
||||
self.progress = 1
|
||||
}
|
||||
})
|
||||
}
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
} else {
|
||||
WebImage(url: URL(string:url), options: [.progressiveLoad])
|
||||
.onProgress(perform: { (receivedSize, expectedSize) in
|
||||
if (expectedSize >= 0) {
|
||||
.onProgress { receivedSize, expectedSize in
|
||||
if (expectedSize > 0) {
|
||||
self.progress = CGFloat(receivedSize) / CGFloat(expectedSize)
|
||||
} else {
|
||||
self.progress = 1
|
||||
}
|
||||
})
|
||||
}
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
}
|
||||
|
|
|
@ -71,9 +71,9 @@ Note: Unlike `UIImageView` in UIKit, SwiftUI's `Image` does not support animatio
|
|||
```swift
|
||||
var body: some View {
|
||||
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"))
|
||||
.onSuccess(perform: { (image, cacheType) in
|
||||
.onSuccess { image, cacheType in
|
||||
// Success
|
||||
})
|
||||
}
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 300, height: 300, alignment: .center)
|
||||
|
@ -87,9 +87,9 @@ var body: some View {
|
|||
Group {
|
||||
// Network
|
||||
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"))
|
||||
.onFailure(perform: { (error) in
|
||||
.onFailure { error in
|
||||
// Error
|
||||
})
|
||||
}
|
||||
.scaledToFit()
|
||||
// Data
|
||||
AnimatedImage(data: try! Data(contentsOf: URL(fileURLWithPath: "/tmp/foo.webp")))
|
||||
|
|
Loading…
Reference in New Issue