Skip to content

Commit 2d4839a

Browse files
committed
Added visionOS support
Add visionOS Demo The scale using traitCollection.displayScale
1 parent e837c37 commit 2d4839a

File tree

28 files changed

+537
-506
lines changed

28 files changed

+537
-506
lines changed

Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj

+271-450
Large diffs are not rendered by default.

Example/SDWebImageSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1500"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
18+
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
19+
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
20+
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
shouldAutocreateTestPlan = "YES">
31+
</TestAction>
32+
<LaunchAction
33+
buildConfiguration = "Debug"
34+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
35+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
ignoresPersistentStateOnLaunch = "NO"
39+
debugDocumentVersioning = "YES"
40+
debugServiceExtension = "internal"
41+
allowLocationSimulation = "YES">
42+
<BuildableProductRunnable
43+
runnableDebuggingMode = "0">
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
47+
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
48+
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
49+
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
50+
</BuildableReference>
51+
</BuildableProductRunnable>
52+
</LaunchAction>
53+
<ProfileAction
54+
buildConfiguration = "Release"
55+
shouldUseLaunchSchemeArgsEnv = "YES"
56+
savedToolIdentifier = ""
57+
useCustomWorkingDirectory = "NO"
58+
debugDocumentVersioning = "YES">
59+
<BuildableProductRunnable
60+
runnableDebuggingMode = "0">
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
64+
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
65+
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
66+
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
67+
</BuildableReference>
68+
</BuildableProductRunnable>
69+
</ProfileAction>
70+
<AnalyzeAction
71+
buildConfiguration = "Debug">
72+
</AnalyzeAction>
73+
<ArchiveAction
74+
buildConfiguration = "Release"
75+
revealArchiveInOrganizer = "YES">
76+
</ArchiveAction>
77+
</Scheme>

Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme

+6-19
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,33 @@
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
5656
allowLocationSimulation = "YES">
57-
<RemoteRunnable
58-
runnableDebuggingMode = "2"
59-
BundleIdentifier = "com.apple.Carousel"
60-
RemotePath = "/SDWebImageSwiftUIDemo-watchOS WatchKit App">
57+
<BuildableProductRunnable
58+
runnableDebuggingMode = "0">
6159
<BuildableReference
6260
BuildableIdentifier = "primary"
6361
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
6462
BuildableName = "SDWebImageSwiftUIDemo-watchOS WatchKit App.app"
6563
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
6664
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
6765
</BuildableReference>
68-
</RemoteRunnable>
66+
</BuildableProductRunnable>
6967
</LaunchAction>
7068
<ProfileAction
7169
buildConfiguration = "Release"
7270
shouldUseLaunchSchemeArgsEnv = "YES"
7371
savedToolIdentifier = ""
7472
useCustomWorkingDirectory = "NO"
7573
debugDocumentVersioning = "YES">
76-
<RemoteRunnable
77-
runnableDebuggingMode = "2"
78-
BundleIdentifier = "com.apple.Carousel"
79-
RemotePath = "/SDWebImageSwiftUIDemo-watchOS WatchKit App">
74+
<BuildableProductRunnable
75+
runnableDebuggingMode = "0">
8076
<BuildableReference
8177
BuildableIdentifier = "primary"
8278
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
8379
BuildableName = "SDWebImageSwiftUIDemo-watchOS WatchKit App.app"
8480
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
8581
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
8682
</BuildableReference>
87-
</RemoteRunnable>
88-
<MacroExpansion>
89-
<BuildableReference
90-
BuildableIdentifier = "primary"
91-
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
92-
BuildableName = "SDWebImageSwiftUIDemo-watchOS WatchKit App.app"
93-
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
94-
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
95-
</BuildableReference>
96-
</MacroExpansion>
83+
</BuildableProductRunnable>
9784
</ProfileAction>
9885
<AnalyzeAction
9986
buildConfiguration = "Debug">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the SDWebImage package.
3+
* (c) DreamPiggy <lizhuoli1126@126.com>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
import SwiftUI
10+
import UIKit
11+
import SDWebImage
12+
13+
// no changes in your AppDelegate class
14+
class AppDelegate: NSObject, UIApplicationDelegate {
15+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
16+
// Add WebP/SVG/PDF support
17+
SDImageCodersManager.shared.addCoder(SDImageAWebPCoder.shared)
18+
// Dynamic check to support vector format for both WebImage/AnimatedImage
19+
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
20+
var options = options
21+
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
22+
// AnimatedImage supports vector rendering, should not force decode
23+
options.insert(.avoidDecodeImage)
24+
}
25+
return SDWebImageOptionsResult(options: options, context: context)
26+
}
27+
return true
28+
}
29+
}
30+
31+
@main
32+
struct SDWebImageSwiftUIDemo: App {
33+
// inject into SwiftUI life-cycle via adaptor
34+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
35+
36+
var body: some Scene {
37+
WindowGroup {
38+
ContentView()
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "reality",
5+
"scale" : "2x"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
},
6+
"layers" : [
7+
{
8+
"filename" : "Front.solidimagestacklayer"
9+
},
10+
{
11+
"filename" : "Middle.solidimagestacklayer"
12+
},
13+
{
14+
"filename" : "Back.solidimagestacklayer"
15+
}
16+
]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "reality",
5+
"scale" : "2x"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "reality",
5+
"scale" : "2x"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSAppTransportSecurity</key>
6+
<dict>
7+
<key>NSAllowsArbitraryLoads</key>
8+
<true/>
9+
</dict>
10+
</dict>
11+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

Example/SDWebImageSwiftUIDemo/ContentView.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct ContentView: View {
112112
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
113113
HStack {
114114
if self.animated {
115-
#if os(macOS) || os(iOS) || os(tvOS)
115+
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
116116
AnimatedImage(url: URL(string:url), isAnimating: .constant(true))
117117
.onViewUpdate { view, context in
118118
#if os(macOS)
@@ -157,6 +157,20 @@ struct ContentView: View {
157157

158158

159159
var body: some View {
160+
#if os(visionOS)
161+
return NavigationView {
162+
contentView()
163+
.navigationBarTitle(animated ? "AnimatedImage" : "WebImage")
164+
.navigationBarItems(leading:
165+
Button(action: { self.reloadCache() }) {
166+
Text("Reload")
167+
}, trailing:
168+
Button(action: { self.switchView() }) {
169+
Text("Switch")
170+
}
171+
)
172+
}
173+
#endif
160174
#if os(iOS)
161175
return NavigationView {
162176
contentView()

Example/SDWebImageSwiftUIDemo/DetailView.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct DetailView: View {
4444

4545
var body: some View {
4646
VStack {
47-
#if os(iOS) || os(tvOS)
47+
#if os(iOS) || os(tvOS) || os(visionOS)
4848
zoomView()
4949
.navigationBarItems(trailing: Button(isAnimating ? "Stop" : "Start") {
5050
self.isAnimating.toggle()
@@ -62,7 +62,7 @@ struct DetailView: View {
6262
}
6363

6464
func zoomView() -> some View {
65-
#if os(macOS) || os(iOS)
65+
#if os(macOS) || os(iOS) || os(visionOS)
6666
return contentView()
6767
.scaleEffect(self.scale)
6868
.gesture(MagnificationGesture(minimumScaleDelta: 0.1).onChanged { value in
@@ -94,7 +94,7 @@ struct DetailView: View {
9494
func contentView() -> some View {
9595
HStack {
9696
if animated {
97-
#if os(macOS) || os(iOS) || os(tvOS)
97+
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
9898
AnimatedImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder], isAnimating: $isAnimating)
9999
.resizable()
100100
.placeholder(.wifiExclamationmark)

SDWebImageSwiftUI.xcodeproj/project.pbxproj

-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,6 @@
403403
Base,
404404
);
405405
mainGroup = 32C43DC222FD540D00BE87F5;
406-
packageReferences = (
407-
);
408406
productRefGroup = 32C43DCD22FD540D00BE87F5 /* Products */;
409407
projectDirPath = "";
410408
projectRoot = "";

SDWebImageSwiftUI.xcworkspace/contents.xcworkspacedata

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)