Update the WebImage to defaults animatable

This commit is contained in:
DreamPiggy 2021-02-23 14:47:51 +08:00
parent 74d142deca
commit 25a9b46cd0
2 changed files with 25 additions and 4 deletions

View File

@ -57,6 +57,27 @@ All issue reports, feature requests, contributions, and GitHub stars are welcome
+ watchOS 6+
+ Swift 5.1+
## SwiftUI 2.0 Compatibility
iOS 14(macOS 11) introduce the SwiftUI 2.0, which keep the most API compatible, but changes many internal behaviors, which breaks the SDWebImageSwiftUI's function.
From v1.6.0, we adopt SwiftUI 2.0 and iOS 14(macOS 11)'s behavior.You can use `WebImage` and `AnimatedImage` inside the new `LazyVStack`.
```swift
var body: some View {
ScrollView {
LazyVStack {
ForEach(urls, id: \.self) { url in
AnimatedImage(url: url)
}
}
}
}
```
Note: However, many differences behavior between iOS 13/14's is hard to fixup. Due to maintain issue, in the future v2.0.0, we will drop the iOS 13 supports and always match SwiftUI 2.0's behavior.
## Installation
#### Swift Package Manager
@ -128,9 +149,7 @@ var body: some View {
}
```
Note: This `WebImage` using `Image` for internal implementation, which is the best compatible for SwiftUI layout and animation system. But unlike SwiftUI's `Image` which does not support animated image or vector image, `WebImage` supports animated image as well.
Note: The `WebImage` animation provide common use case, so it's still recommend to use `AnimatedImage` for advanced controls like progressive animation rendering.
Note: This `WebImage` using `Image` for internal implementation, which is the best compatible for SwiftUI layout and animation system. But unlike SwiftUI's `Image` which does not support animated image or vector image, `WebImage` supports animated image as well (by defaults from v1.6.0)
```swift
@State var isAnimating: Bool = true
@ -143,6 +162,8 @@ var body: some View {
}
```
Note: The `WebImage` animation provide common use case, so it's still recommend to use `AnimatedImage` for advanced controls like progressive animation rendering, or vector image rendering. In a word, `WebImage` can render animated image, but not always the best choice.
### Using `AnimatedImage` to play animation
- [x] Supports network image as well as local data and bundle image

View File

@ -34,7 +34,7 @@ public struct WebImage : View {
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
/// - Parameter context: A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
self.init(url: url, options: options, context: context, isAnimating: .constant(false))
self.init(url: url, options: options, context: context, isAnimating: .constant(true))
}
/// Create a web image with url, placeholder, custom options and context. Optional can support animated image using Binding.