Skip to content

Commit be8e2c9

Browse files
authored
Merge pull request #83 from SDWebImage/release_1.0
Release 1.0
2 parents b32d3ca + 202174d commit be8e2c9

File tree

15 files changed

+73
-55
lines changed

15 files changed

+73
-55
lines changed

Example/SDWebImageSwiftUIDemo-macOS/AppDelegate.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4545
options.insert(.avoidDecodeImage)
4646
} else {
4747
// WebImage supports bitmap rendering only
48-
context?[.svgPrefersBitmap] = true
49-
context?[.pdfPrefersBitmap] = true
48+
context?[.imageThumbnailPixelSize] = CGSize.zero
5049
}
5150
return SDWebImageOptionsResult(options: options, context: context)
5251
}

Example/SDWebImageSwiftUIDemo-tvOS/AppDelegate.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5353
options.insert(.avoidDecodeImage)
5454
} else {
5555
// WebImage supports bitmap rendering only
56-
context?[.svgPrefersBitmap] = true
57-
context?[.pdfPrefersBitmap] = true
56+
context?[.imageThumbnailPixelSize] = CGSize.zero
5857
}
5958
return SDWebImageOptionsResult(options: options, context: context)
6059
}

Example/SDWebImageSwiftUIDemo-watchOS WatchKit Extension/ExtensionDelegate.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
2424
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
2525
var context = context
2626
// WebImage supports bitmap rendering only
27-
context?[.svgPrefersBitmap] = true
28-
context?[.pdfPrefersBitmap] = true
27+
context?[.imageThumbnailPixelSize] = CGSize.zero
2928
return SDWebImageOptionsResult(options: options, context: context)
3029
}
3130
}

Example/SDWebImageSwiftUIDemo/AppDelegate.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3232
options.insert(.avoidDecodeImage)
3333
} else {
3434
// WebImage supports bitmap rendering only
35-
context?[.svgPrefersBitmap] = true
36-
context?[.pdfPrefersBitmap] = true
35+
context?[.imageThumbnailPixelSize] = CGSize.zero
3736
}
3837
return SDWebImageOptionsResult(options: options, context: context)
3938
}

Example/SDWebImageSwiftUIDemo/ContentView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import SDWebImageSwiftUI
1212

1313
class UserSettings: ObservableObject {
1414
// Some environment configuration
15+
#if os(tvOS)
1516
@Published var editMode: EditMode = .inactive
1617
@Published var zoomed: Bool = false
18+
#endif
1719
}
1820

1921
#if os(watchOS)

Example/SDWebImageSwiftUIDemo/Espera.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ public struct StretchLoadingView: View {
194194

195195
public struct StretchProgressView: View {
196196

197-
@Binding public var progress: CGFloat
197+
@Binding public var progress: Double
198198

199199
public var body: some View {
200-
StretchyShape(progress: Double(progress), mode: .stretchy)
200+
StretchyShape(progress: progress, mode: .stretchy)
201201
.frame(width: 140, height: 10)
202202
}
203203
}

README.md

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ SDWebImageSwiftUI is a SwiftUI image loading framework, which based on [SDWebIma
1414

1515
It brings all your favorite features from SDWebImage, like async image loading, memory/disk caching, animated image playback and performances.
1616

17+
The framework provide the different View structs, which API match the SwiftUI framework guideline. If you're familiar with `Image`, you'll find it easy to use `WebImage` and `AnimatedImage`.
18+
1719
## Features
1820

1921
Since SDWebImageSwiftUI is built on top of SDWebImage, it provide both the out-of-box features as well as advanced powerful features you may want in real world Apps. Check our [Wiki](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage) when you need:
@@ -34,9 +36,9 @@ Besides all these features, we do optimization for SwiftUI, like Binding, View M
3436

3537
This framework is under heavily development, it's recommended to use [the latest release](https://github.com/SDWebImage/SDWebImageSwiftUI/releases) as much as possible (including SDWebImage dependency).
3638

37-
The v1.0.0 version is now **on beta**, all the previous users are recommended to use, test and report issues. We need you feedback to drive the future development. The official version may released in February.
39+
The v1.0.0 version is now **released**, which provide all the function above, with the stable API, fully documentation and unit test.
3840

39-
The v1.0.0 version provide all the function above, with the stable API, fully documentation and unit test. This framework follows [Semantic Versioning](https://semver.org/).
41+
This framework follows [Semantic Versioning](https://semver.org/). Each source-break API changes will bump to a major version.
4042

4143
## Contribution
4244

@@ -78,10 +80,6 @@ SDWebImageSwiftUI is available through [Swift Package Manager](https://swift.org
7880

7981
For App integration, you should using Xcode 11 or higher, to add this package to your App target. To do this, check [Adding Package Dependencies to Your App](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app?language=objc) about the step by step tutorial using Xcode.
8082

81-
Note for any pre-release version like 1.0.0 beta, you should use the `Exact` dependency, or the `Range` dependency. Using `Up to next Major` does not resolve the pre-release version.
82-
83-
![](https://user-images.githubusercontent.com/6919743/73805686-5451c180-4802-11ea-9b72-d082ad315bfc.png)
84-
8583
+ For downstream framework
8684

8785
For downstream framework author, you should create a `Package.swift` file into your git repo, then add the following line to mark your framework dependent our SDWebImageSwiftUI.
@@ -94,16 +92,6 @@ let package = Package(
9492
)
9593
```
9694

97-
Note for any pre-release version like 1.0.0 beta, you should use the SwiftPM [prereleaseIdentifiers](https://developer.apple.com/documentation/swift_packages/version/2878264-prereleaseidentifiers) API to specify it. The default `from:` does not resolve the pre-release version.
98-
99-
```swift
100-
let package = Package(
101-
dependencies: [
102-
.package(url: "https://github.com/SDWebImage/SDWebImageSwiftUI.git", from: Version(1, 0, 0, prereleaseIdentifiers: ["-beta"])))
103-
],
104-
)
105-
```
106-
10795
## Usage
10896

10997
### Using `WebImage` to load network image
@@ -113,7 +101,7 @@ let package = Package(
113101
- [x] Supports success/failure/progress changes event for custom handling
114102
- [x] Supports indicator with activity/progress indicator and customization
115103
- [x] Supports built-in animation and transition, powered by SwiftUI
116-
- [x] Supports animated image as well! (from v0.9.0)
104+
- [x] Supports animated image as well!
117105

118106
```swift
119107
var body: some View {
@@ -135,17 +123,17 @@ var body: some View {
135123
}
136124
```
137125

138-
Note: This `WebImage` using `Image` for internal implementation, which is the best compatible for SwiftUI layout and animation system. In previous version, `WebImage` supports static image format only, because unlike `UIImageView` in UIKit, SwiftUI's `Image` does not support animated image or vector image.
126+
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.
139127

140-
Note: From v0.9.0, `WebImage` supports animated image as well! You can use `.animated()` to start animation. This is done by using the native SwiftUI rendering system and SDWebImage's powerful [Animated Player](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-player-530). The `WebImage` animated image provide common use case, so it's still recommend to use `AnimatedImage` for advanced controls like progressive animation rendering.
128+
Note: The `WebImage` animation provide common use case, so it's still recommend to use `AnimatedImage` for advanced controls like progressive animation rendering.
141129

142130
```swift
143131
var body: some View {
144-
WebImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"), isAnimating: $isAnimating)) // Animation Control in 1.0.0, supports dynamic changes
132+
WebImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"), isAnimating: $isAnimating)) // Animation Control, supports dynamic changes
145133
// The initial value of binding should be true (or you can use `.animatedImageClass` context option and pass `SDAnimatedImage`)
146134
.customLoopCount(1) // Custom loop count
147135
.playbackRate(2.0) // Playback speed rate
148-
// In 1.0.0, `WebImage` supports advanced control just like `AnimatedImage`, but without the progressive animation support
136+
// `WebImage` supports advanced control just like `AnimatedImage`, but without the progressive animation support
149137
}
150138
```
151139

@@ -190,17 +178,13 @@ var body: some View {
190178

191179
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, some advanced SwiftUI layout and animation system may not work as expected. You may need UIKit/AppKit and Core Animation to modify the native view.
192180

193-
Note: From v0.9.0, `AnimatedImage` on watchOS drop the supports on watchOS, because of using hacks and private APIs. For watchOS user, choose `WebImage` instead.
194-
195-
Note: From v0.8.0, `AnimatedImage` on watchOS support all features the same as iOS/tvOS/macOS, including Animated WebP rendering, runloop mode, pausable, purgeable, playback rate, etc. It use the SDWebImage's [Animated Player](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-player-530), which is the same backend engine for iOS/tvOS/macOS's Animated ImageView.
196-
197181
### Which View to choose
198182

199183
Why we have two different View types here, is because of current SwiftUI limit. But we're aimed to provide best solution for all use cases.
200184

201185
If you don't need animated image, prefer to use `WebImage` firstly. Which behaves the seamless as built-in SwiftUI View. If SwiftUI works, it works.
202186

203-
If you need simple animated image, use v0.9.0 above with `WebImage`. Which provide the basic animated image support. But it does not support progressive animation rendering, playback rate, etc.
187+
If you need simple animated image, use `WebImage`. Which provide the basic animated image support. But it does not support progressive animation rendering, playback rate, etc.
204188

205189
If you need powerful animated image, `AnimatedImage` is the one to choose. Remember it supports static image as well, you don't need to check the format, just use as it.
206190

@@ -289,25 +273,55 @@ NavigationView {
289273

290274
#### Using for backward deployment and weak linking SwiftUI
291275

292-
SDWebImageSwiftUI from v0.10.0, supports to use when your App Target has a deployment target version less than iOS 13/macOS 10.15/tvOS 13/watchOS 6. Which will weak linking of SwiftUI(Combine) to allows writing code with available check at runtime.
276+
SDWebImageSwiftUI supports to use when your App Target has a deployment target version less than iOS 13/macOS 10.15/tvOS 13/watchOS 6. Which will weak linking of SwiftUI(Combine) to allows writing code with available check at runtime.
293277

294278
To use backward deployment, you have to do the follow things:
295279

296-
+ Add `-weak_framework SwiftUI -weak_framework Combine` in your App Target's `Other Linker Flags` build setting
280+
##### Add weak linking framework
297281

298-
You should notice that all the third party SwiftUI frameworks should have this build setting as well, not only just SDWebImageSwiftUI (we already added in v0.10.0). Or when running on iOS 12 device, it will trigger the runtime dyld error on startup.
282+
Add `-weak_framework SwiftUI -weak_framework Combine` in your App Target's `Other Linker Flags` build setting. You can also do this using Xcode's `Optional Framework` checkbox, there have the same effect.
299283

300-
+ Use CocoaPods or Carthage (SwiftPM does not support weak linking nor backward deployment currently)
284+
You should notice that all the third party SwiftUI frameworks should have this build setting as well, not only just SDWebImageSwiftUI. Or when running on iOS 12 device, it will trigger the runtime dyld error on startup.
301285

302-
For Carthage user, the built binary framework will use [Library Evolution](https://swift.org/blog/abi-stability-and-more/) to support for backward deployment.
286+
##### Backward deployment on iOS 12.1-
303287

304-
For CocoaPods user, you can skip the platform version validation in Podfile with:
288+
For deployment target version below iOS 12.2 (The first version which Swift 5 Runtime bundled in iOS system), you have to change the min deployment target version of SDWebImageSwiftUI. This may take some side effect on compiler's optimization and trigger massive warnings for some frameworks.
289+
290+
However, for iOS 12.2+, you can still keep the min deployment target version to iOS 13, no extra warnings or performance slow down for iOS 13 client.
291+
292+
Because Swift use the min deployment target version to detect whether to link the App bundled Swift runtime, or the System built-in one (`/usr/lib/swift/libswiftCore.dylib`).
293+
294+
+ For CocoaPods user, you can change the min deployment target version in the Podfile via post installer:
295+
296+
```ruby
297+
post_install do |installer|
298+
installer.pods_project.targets.each do |target|
299+
target.build_configurations.each do |config|
300+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' # version you need
301+
end
302+
end
303+
end
304+
```
305+
306+
+ For Carthage user, you can use `carthage update --no-build` to download the dependency, then change the Xcode Project's deployment target version and build the binary framework.
307+
308+
+ For SwiftPM user, you have to use the local dependency (with the Git submodule) to change the deployment target version.
309+
310+
##### Backward deployment on iOS 12.2+
311+
312+
+ For Carthage user, the built binary framework will use [Library Evolution](https://swift.org/blog/abi-stability-and-more/) to support for backward deployment.
313+
314+
+ For CocoaPods user, you can skip the platform version validation in Podfile with:
305315

306316
```ruby
307317
platform :ios, '13.0' # This does not effect your App Target's deployment target version, just a hint for CocoaPods
308318
```
319+
320+
+ For SwiftPM user, SwiftPM does not support weak linking nor Library Evolution, so it can not deployment to iOS 12+ user without changing the min deployment target.
309321

310-
+ Add **all the SwiftUI code** with the available annotation and runtime check, like this:
322+
##### Add available annotation
323+
324+
Add **all the SwiftUI code** with the available annotation and runtime check, like this:
311325

312326
```swift
313327
// AppDelegate.swift

SDWebImageSwiftUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SDWebImageSwiftUI'
11-
s.version = '1.0.0-beta3'
11+
s.version = '1.0.0'
1212
s.summary = 'SwiftUI Image loading and Animation framework powered by SDWebImage'
1313

1414
s.description = <<-DESC

SDWebImageSwiftUI.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@
820820
3211F84C23DE984D00FC757F /* Debug */ = {
821821
isa = XCBuildConfiguration;
822822
buildSettings = {
823+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
823824
CODE_SIGN_STYLE = Automatic;
824825
FRAMEWORK_SEARCH_PATHS = (
825826
"$(inherited)",
@@ -841,6 +842,7 @@
841842
3211F84D23DE984D00FC757F /* Release */ = {
842843
isa = XCBuildConfiguration;
843844
buildSettings = {
845+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
844846
CODE_SIGN_STYLE = Automatic;
845847
FRAMEWORK_SEARCH_PATHS = (
846848
"$(inherited)",
@@ -862,6 +864,7 @@
862864
321C1D4423DEC17D009CF62A /* Debug */ = {
863865
isa = XCBuildConfiguration;
864866
buildSettings = {
867+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
865868
CODE_SIGN_STYLE = Automatic;
866869
COMBINE_HIDPI_IMAGES = YES;
867870
FRAMEWORK_SEARCH_PATHS = (
@@ -884,6 +887,7 @@
884887
321C1D4523DEC17D009CF62A /* Release */ = {
885888
isa = XCBuildConfiguration;
886889
buildSettings = {
890+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
887891
CODE_SIGN_STYLE = Automatic;
888892
COMBINE_HIDPI_IMAGES = YES;
889893
FRAMEWORK_SEARCH_PATHS = (
@@ -906,6 +910,7 @@
906910
321C1D5323DEC185009CF62A /* Debug */ = {
907911
isa = XCBuildConfiguration;
908912
buildSettings = {
913+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
909914
CODE_SIGN_STYLE = Automatic;
910915
FRAMEWORK_SEARCH_PATHS = (
911916
"$(inherited)",
@@ -928,6 +933,7 @@
928933
321C1D5423DEC185009CF62A /* Release */ = {
929934
isa = XCBuildConfiguration;
930935
buildSettings = {
936+
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
931937
CODE_SIGN_STYLE = Automatic;
932938
FRAMEWORK_SEARCH_PATHS = (
933939
"$(inherited)",

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SDWebImage
1313
class ImageManager : ObservableObject {
1414
@Published var image: PlatformImage? // loaded image, note when progressive loading, this will published multiple times with different partial image
1515
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
16-
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding
16+
@Published var progress: Double = 0 // network progress, should only be used for indicator binding
1717

1818
var manager: SDWebImageManager
1919
weak var currentOperation: SDWebImageOperation? = nil
@@ -49,9 +49,9 @@ class ImageManager : ObservableObject {
4949
guard let self = self else {
5050
return
5151
}
52-
let progress: CGFloat
52+
let progress: Double
5353
if (expectedSize > 0) {
54-
progress = CGFloat(receivedSize) / CGFloat(expectedSize)
54+
progress = Double(receivedSize) / Double(expectedSize)
5555
} else {
5656
progress = 0
5757
}

0 commit comments

Comments
 (0)