diff --git a/.gitignore b/.gitignore index d502957..8a29ab6 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ Pods/ # SwiftPM .build +.swiftpm diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Example/Podfile b/Example/Podfile index c1e58ae..f29b93f 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -3,4 +3,5 @@ use_frameworks! target 'SDWebImageSwiftUIDemo' do platform :ios, '13.0' pod 'SDWebImageSwiftUI', :path => '../' + pod 'SDWebImageWebPCoder' end diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 9a39619..48f7a25 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,25 +1,42 @@ PODS: - - SDWebImage (5.1.0): - - SDWebImage/Core (= 5.1.0) - - SDWebImage/Core (5.1.0) - - SDWebImageSwiftUI (0.1.1): + - libwebp (1.0.3): + - libwebp/demux (= 1.0.3) + - libwebp/mux (= 1.0.3) + - libwebp/webp (= 1.0.3) + - libwebp/demux (1.0.3): + - libwebp/webp + - libwebp/mux (1.0.3): + - libwebp/demux + - libwebp/webp (1.0.3) + - SDWebImage (5.2.2): + - SDWebImage/Core (= 5.2.2) + - SDWebImage/Core (5.2.2) + - SDWebImageSwiftUI (0.1.2): - SDWebImage (~> 5.1) + - SDWebImageWebPCoder (0.2.5): + - libwebp (~> 1.0) + - SDWebImage/Core (~> 5.0) DEPENDENCIES: - SDWebImageSwiftUI (from `../`) + - SDWebImageWebPCoder SPEC REPOS: https://github.com/cocoapods/specs.git: + - libwebp - SDWebImage + - SDWebImageWebPCoder EXTERNAL SOURCES: SDWebImageSwiftUI: :path: "../" SPEC CHECKSUMS: - SDWebImage: fb387001955223213dde14bc08c8b73f371f8d8f - SDWebImageSwiftUI: fa0b13b16a92985532cd13931b88aea4ff7efb0b + libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e + SDWebImage: 5fcdb02cc35e05fc35791ec514b191d27189f872 + SDWebImageSwiftUI: 1026ac69b616d77b3ecb5b34e5b977ca9a165d5f + SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987 -PODFILE CHECKSUM: 146734166216dd8fc1597433cc675999454ed4b2 +PODFILE CHECKSUM: c85d310339d014183658205b527a83237d24f8f2 COCOAPODS: 1.7.5 diff --git a/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj b/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj index 8d44b1a..c9c7147 100644 --- a/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj +++ b/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 320CDC3222FADB45007CF858 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 320CDC3122FADB45007CF858 /* Assets.xcassets */; }; 320CDC3522FADB45007CF858 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 320CDC3422FADB45007CF858 /* Preview Assets.xcassets */; }; 320CDC3822FADB45007CF858 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 320CDC3622FADB45007CF858 /* LaunchScreen.storyboard */; }; + 326B0D712345C01900D28269 /* DetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326B0D702345C01900D28269 /* DetailView.swift */; }; CECA1658ECBAF54E3FF3EF58 /* Pods_SDWebImageSwiftUIDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A371F81C3B5BD6972F7A0E2 /* Pods_SDWebImageSwiftUIDemo.framework */; }; /* End PBXBuildFile section */ @@ -27,6 +28,7 @@ 320CDC3422FADB45007CF858 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 320CDC3722FADB45007CF858 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 320CDC3922FADB45007CF858 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 326B0D702345C01900D28269 /* DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailView.swift; sourceTree = ""; }; 3E9F8B5F06960FFFBD1A5F99 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 4A371F81C3B5BD6972F7A0E2 /* Pods_SDWebImageSwiftUIDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageSwiftUIDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 54859B427E0A79E823713963 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; @@ -67,6 +69,7 @@ 320CDC2B22FADB44007CF858 /* AppDelegate.swift */, 320CDC2D22FADB44007CF858 /* SceneDelegate.swift */, 320CDC2F22FADB44007CF858 /* ContentView.swift */, + 326B0D702345C01900D28269 /* DetailView.swift */, 320CDC3122FADB45007CF858 /* Assets.xcassets */, 320CDC3622FADB45007CF858 /* LaunchScreen.storyboard */, 320CDC3922FADB45007CF858 /* Info.plist */, @@ -173,7 +176,6 @@ TargetAttributes = { 320CDC2822FADB44007CF858 = { CreatedOnToolsVersion = 11.0; - ProvisioningStyle = Automatic; }; }; }; @@ -219,11 +221,15 @@ "${PODS_ROOT}/Target Support Files/Pods-SDWebImageSwiftUIDemo/Pods-SDWebImageSwiftUIDemo-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework", "${BUILT_PRODUCTS_DIR}/SDWebImageSwiftUI/SDWebImageSwiftUI.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageWebPCoder/SDWebImageWebPCoder.framework", + "${BUILT_PRODUCTS_DIR}/libwebp/libwebp.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageSwiftUI.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageWebPCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -260,6 +266,7 @@ buildActionMask = 2147483647; files = ( 320CDC2C22FADB44007CF858 /* AppDelegate.swift in Sources */, + 326B0D712345C01900D28269 /* DetailView.swift in Sources */, 320CDC2E22FADB44007CF858 /* SceneDelegate.swift in Sources */, 320CDC3022FADB44007CF858 /* ContentView.swift in Sources */, ); @@ -292,9 +299,10 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_IDENTITY = ""; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_ASSET_PATHS = "SDWebImageSwiftUIDemo/Preview\\ Content"; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = SDWebImageSwiftUIDemo/Info.plist; @@ -304,6 +312,9 @@ MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.dreampiggy.SDWebImageSwiftUIDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SUPPORTS_MACCATALYST = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -323,8 +334,9 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_IDENTITY = ""; DEVELOPMENT_ASSET_PATHS = "SDWebImageSwiftUIDemo/Preview\\ Content"; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = SDWebImageSwiftUIDemo/Info.plist; @@ -333,6 +345,9 @@ MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.dreampiggy.SDWebImageSwiftUIDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SUPPORTS_MACCATALYST = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/Example/SDWebImageSwiftUIDemo/AppDelegate.swift b/Example/SDWebImageSwiftUIDemo/AppDelegate.swift index 1a4cd6a..012514a 100644 --- a/Example/SDWebImageSwiftUIDemo/AppDelegate.swift +++ b/Example/SDWebImageSwiftUIDemo/AppDelegate.swift @@ -7,6 +7,8 @@ */ import UIKit +import SDWebImage +import SDWebImageWebPCoder @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -15,6 +17,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + // Add WebP support + SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared) return true } diff --git a/Example/SDWebImageSwiftUIDemo/ContentView.swift b/Example/SDWebImageSwiftUIDemo/ContentView.swift index 3bf40fa..23233c1 100644 --- a/Example/SDWebImageSwiftUIDemo/ContentView.swift +++ b/Example/SDWebImageSwiftUIDemo/ContentView.swift @@ -7,23 +7,74 @@ */ import SwiftUI +import SDWebImage import SDWebImageSwiftUI +extension String : Identifiable { + public typealias ID = Int + public var id: Int { + self.hashValue + } +} + +let imageURLs = [ + "http://assets.sbnation.com/assets/2512203/dogflops.gif", + "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif", + "http://apng.onevcat.com/assets/elephant.png", + "http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp", + "http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp", + "http://littlesvr.ca/apng/images/SteamEngine.webp", + "http://littlesvr.ca/apng/images/world-cup-2014-42.webp", + "https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp", + "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic", + "https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic", + "https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png", + "http://via.placeholder.com/200x200.jpg"] + struct ContentView: View { - var url: URL? + @State var animated: Bool = false var body: some View { - VStack { - WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")) - .resizable() - .scaledToFit() - .frame(width: CGFloat(300), height: CGFloat(300), alignment: .center) - AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"), options: [.progressiveLoad]) - .resizable() - .scaledToFill() - .frame(width: CGFloat(400), height: CGFloat(300), alignment: .center) + NavigationView { + List(imageURLs) { url in + NavigationLink(destination: DetailView(url: url, animated: self.animated)) { + HStack { + if self.animated { + AnimatedImage(url: URL(string:url)) + .resizable() + .scaledToFit() + .frame(width: CGFloat(100), height: CGFloat(100), alignment: .center) + } else { + WebImage(url: URL(string:url)) + .resizable() + .scaledToFit() + .frame(width: CGFloat(100), height: CGFloat(100), alignment: .center) + } + Text(url) + } + } + } + .navigationBarTitle(animated ? "AnimatedImage" : "WebImage") + .navigationBarItems(leading: + Button(action: { self.reloadCache() }) { + Text("Reload") + }, trailing: + Button(action: { self.switchView() }) { + Text("Switch") + } + ) } } + + func reloadCache() { + SDImageCache.shared.clearMemory() + SDImageCache.shared.clearDisk(onCompletion: nil) + } + + func switchView() { + SDImageCache.shared.clearMemory() + animated.toggle() + } } #if DEBUG diff --git a/Example/SDWebImageSwiftUIDemo/DetailView.swift b/Example/SDWebImageSwiftUIDemo/DetailView.swift new file mode 100644 index 0000000..3b41f8a --- /dev/null +++ b/Example/SDWebImageSwiftUIDemo/DetailView.swift @@ -0,0 +1,37 @@ +/* +* This file is part of the SDWebImage package. +* (c) DreamPiggy +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +import SwiftUI +import SDWebImageSwiftUI + +struct DetailView: View { + let url: String + let animated: Bool + + var body: some View { + Group { + if animated { + AnimatedImage(url: URL(string:url), options: [.progressiveLoad]) + .resizable() + .scaledToFit() + } else { + WebImage(url: URL(string:url), options: [.progressiveLoad]) + .resizable() + .scaledToFit() + } + } + } +} + +#if DEBUG +struct DetailView_Previews: PreviewProvider { + static var previews: some View { + DetailView(url: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic", animated: false) + } +} +#endif diff --git a/Example/SDWebImageSwiftUIDemo/Info.plist b/Example/SDWebImageSwiftUIDemo/Info.plist index e8bb4c6..1e9963e 100644 --- a/Example/SDWebImageSwiftUIDemo/Info.plist +++ b/Example/SDWebImageSwiftUIDemo/Info.plist @@ -20,6 +20,11 @@ 1 LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/Example/Screenshot/1.jpg b/Example/Screenshot/1.jpg deleted file mode 100644 index 9c33328..0000000 Binary files a/Example/Screenshot/1.jpg and /dev/null differ diff --git a/Example/Screenshot/Demo-iOS.png b/Example/Screenshot/Demo-iOS.png new file mode 100644 index 0000000..be919ad Binary files /dev/null and b/Example/Screenshot/Demo-iOS.png differ diff --git a/Example/Screenshot/Demo-macOS.png b/Example/Screenshot/Demo-macOS.png new file mode 100644 index 0000000..6345ece Binary files /dev/null and b/Example/Screenshot/Demo-macOS.png differ diff --git a/Package.resolved b/Package.resolved index 77db8b3..8c1e392 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/SDWebImage/SDWebImage.git", "state": { "branch": null, - "revision": "9c1682e37bf3486daccd313fcbcd7fd90a2064f4", - "version": "5.2.0" + "revision": "39ecbe51de1455c56e877397b9838a7f8fafd71a", + "version": "5.2.2" } } ] diff --git a/README.md b/README.md index 7320530..9bacde3 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,17 @@ cd Example pod install ``` -Then open the Xcode Workspace to run the demo application. +Then open the Xcode Workspace to run the demo application. You can run it on iOS and macOS. ## Screenshot -![](Example/Screenshot/1.jpg) ++ iOS Demo + + + ++ macOS Demo + + ## Author