Update the readme with indicator and transition

This commit is contained in:
DreamPiggy 2019-10-26 03:47:28 +08:00
parent 5bcdaf697d
commit 896627d381
2 changed files with 13 additions and 5 deletions

View File

@ -102,6 +102,8 @@ struct ContentView: View {
.resizable()
.scaledToFit()
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
.animation(.easeInOut(duration: 0.5))
.transition(.opacity)
#else
WebImage(url: URL(string:url))
.resizable()

View File

@ -61,10 +61,11 @@ let package = Package(
### Using `WebImage` to load network image
- [x] Supports the placeholder and detail options control for image loading as SDWebImage.
- [x] Supports the success/failure/progress changes event for custom handling.
- [x] Supports the placeholder and detail options control for image loading as SDWebImage
- [x] Supports the success/failure/progress changes event for custom handling
- [x] Supports the indicator with activity/progress indicator and customization
Note: Unlike `UIImageView` in UIKit, SwiftUI's `Image` does not support animation. This `WebImage` using `Image` for internal implementation and supports static image format only.
Note: This `WebImage` using `Image` for internal implementation, which is the best compatible for SwiftUI layout and animation system. But it supports static image format only, because unlike `UIImageView` in UIKit, SwiftUI's `Image` does not support animation.
```swift
var body: some View {
@ -72,6 +73,9 @@ var body: some View {
.onSuccess { image, cacheType in
// Success
}
.indicator { isAnimating, _ in
ActivityIndicator(isAnimating) // Activity Indicator
}
.resizable()
.scaledToFit()
.frame(width: 300, height: 300, alignment: .center)
@ -88,6 +92,7 @@ var body: some View {
.onFailure { error in
// Error
}
.transition(.fade) // Fade Transition
.scaledToFit()
// Data
AnimatedImage(data: try! Data(contentsOf: URL(fileURLWithPath: "/tmp/foo.webp")))
@ -101,9 +106,10 @@ var body: some View {
- [x] Supports network image as well as local data and bundle image
- [x] Supports animation control using the SwiftUI Binding
- [x] Supports advanced control like loop count, incremental load, buffer size.
- [x] Supports indicator and transition powered by SDWebImage and CoreAnimation
- [x] Supports advanced control like loop count, incremental load, buffer size
Note: `AnimatedImage` supports both image url or image data for animated image format. Which use the SDWebImage's [Animated ImageView](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50) for internal implementation.
Note: `AnimatedImage` supports both image url or image data for animated image format. Which use the SDWebImage's [Animated ImageView](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50) for internal implementation. Pay attention that since this base on UIKit/AppKit representable, if you need advanced customized layout and animation, you need CoreAnimation to help.
Note: From v0.4.0, `AnimatedImage` supports watchOS as well. However, it's not backed by SDWebImage's [Animated ImageView](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50) like iOS/tvOS/macOS. It use some tricks and hacks because of the limitation on current Apple's API. It also use Image/IO decoding system, which means it supports GIF and APNG format only, but not external format like WebP.