From 25a9b46cd00635f3d43da5d8ff952601a1ca93b1 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 23 Feb 2021 14:47:51 +0800 Subject: [PATCH] Update the WebImage to defaults animatable --- README.md | 27 +++++++++++++++++++++--- SDWebImageSwiftUI/Classes/WebImage.swift | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b74db79..c5fb01a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 5a3b916..5f04d1d 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -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.