Skip to content

Update the example to support macOS. Use List to display both WebImage and AnimatedImage #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Pods/

# SwiftPM
.build
.swiftpm
7 changes: 0 additions & 7 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

This file was deleted.

1 change: 1 addition & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ use_frameworks!
target 'SDWebImageSwiftUIDemo' do
platform :ios, '13.0'
pod 'SDWebImageSwiftUI', :path => '../'
pod 'SDWebImageWebPCoder'
end
31 changes: 24 additions & 7 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -27,6 +28,7 @@
320CDC3422FADB45007CF858 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
320CDC3722FADB45007CF858 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
320CDC3922FADB45007CF858 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
326B0D702345C01900D28269 /* DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailView.swift; sourceTree = "<group>"; };
3E9F8B5F06960FFFBD1A5F99 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -173,7 +176,6 @@
TargetAttributes = {
320CDC2822FADB44007CF858 = {
CreatedOnToolsVersion = 11.0;
ProvisioningStyle = Automatic;
};
};
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -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";
};
Expand Down
4 changes: 4 additions & 0 deletions Example/SDWebImageSwiftUIDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

import UIKit
import SDWebImage
import SDWebImageWebPCoder

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -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
}

Expand Down
71 changes: 61 additions & 10 deletions Example/SDWebImageSwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions Example/SDWebImageSwiftUIDemo/DetailView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of the SDWebImage package.
* (c) DreamPiggy <lizhuoli1126@126.com>
*
* 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
5 changes: 5 additions & 0 deletions Example/SDWebImageSwiftUIDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Binary file removed Example/Screenshot/1.jpg
Binary file not shown.
Binary file added Example/Screenshot/Demo-iOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Example/Screenshot/Demo-macOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<img src='https://raw.githubusercontent.com/SDWebImage/SDWebImageSwiftUI/master/Example/Screenshot/Demo-iOS.png' width=960 />

+ macOS Demo

<img src='https://raw.githubusercontent.com/SDWebImage/SDWebImageSwiftUI/master/Example/Screenshot/Demo-macOS.png' width=960 />

## Author

Expand Down