Skip to content

Commit 67f6e20

Browse files
authored
Merge pull request #267 from SDWebImage/feature/visionOS
(Part 1) Support compile for visionOS (no package manager support)
2 parents 5622af5 + 15990ac commit 67f6e20

File tree

29 files changed

+910
-526
lines changed

29 files changed

+910
-526
lines changed

.github/workflows/CI.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ permissions:
1414
jobs:
1515
Pods:
1616
name: Cocoapods Lint
17-
runs-on: macos-11
17+
runs-on: macos-12
1818
env:
19-
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
19+
DEVELOPER_DIR: /Applications/Xcode_14.1.app
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v2
@@ -34,9 +34,9 @@ jobs:
3434
3535
Demo:
3636
name: Run Demo
37-
runs-on: macos-11
37+
runs-on: macos-12
3838
env:
39-
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
39+
DEVELOPER_DIR: /Applications/Xcode_14.1.app
4040
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
4141
OSXSCHEME: SDWebImageSwiftUIDemo-macOS
4242
iOSSCHEME: SDWebImageSwiftUIDemo
@@ -45,7 +45,7 @@ jobs:
4545
strategy:
4646
matrix:
4747
iosDestination: ["name=iPhone 13 Pro"]
48-
tvOSDestination: ["name=Apple TV 4K"]
48+
tvOSDestination: ["name=Apple TV"]
4949
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 - 45mm"]
5050
macOSDestination: ["platform=macOS"]
5151
macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"]
@@ -92,9 +92,9 @@ jobs:
9292
9393
Test:
9494
name: Unit Test
95-
runs-on: macos-11
95+
runs-on: macos-12
9696
env:
97-
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
97+
DEVELOPER_DIR: /Applications/Xcode_14.1.app
9898
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
9999
OSXSCHEME: SDWebImageSwiftUITests macOS
100100
iOSSCHEME: SDWebImageSwiftUITests
@@ -154,9 +154,9 @@ jobs:
154154
155155
Build:
156156
name: Build Library
157-
runs-on: macos-11
157+
runs-on: macos-12
158158
env:
159-
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
159+
DEVELOPER_DIR: /Applications/Xcode_14.1.app
160160
PROJECT_NAME: SDWebImageSwiftUI.xcodeproj
161161
OSXSCHEME: SDWebImageSwiftUI macOS
162162
iOSSCHEME: SDWebImageSwiftUI

Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj

Lines changed: 449 additions & 446 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
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>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of the SDWebImage package.
3+
* (c) DreamPiggy <[email protected]>
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+
import SDWebImageWebPCoder
13+
import SDWebImageSVGCoder
14+
import SDWebImagePDFCoder
15+
16+
// no changes in your AppDelegate class
17+
class AppDelegate: NSObject, UIApplicationDelegate {
18+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
19+
// Add WebP/SVG/PDF support
20+
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
21+
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
22+
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
23+
// Dynamic check to support vector format for both WebImage/AnimatedImage
24+
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
25+
var options = options
26+
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
27+
// AnimatedImage supports vector rendering, should not force decode
28+
options.insert(.avoidDecodeImage)
29+
}
30+
return SDWebImageOptionsResult(options: options, context: context)
31+
}
32+
return true
33+
}
34+
}
35+
36+
@main
37+
struct SDWebImageSwiftUIDemo: App {
38+
// inject into SwiftUI life-cycle via adaptor
39+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
40+
41+
var body: some Scene {
42+
WindowGroup {
43+
ContentView()
44+
}
45+
}
46+
}
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+
}
Lines changed: 17 additions & 0 deletions
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
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>
Lines changed: 6 additions & 0 deletions
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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct ContentView: View {
9595
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
9696
HStack {
9797
if self.animated {
98-
#if os(macOS) || os(iOS) || os(tvOS)
98+
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
9999
AnimatedImage(url: URL(string:url), isAnimating: .constant(true))
100100
.onViewUpdate { view, context in
101101
#if os(macOS)
@@ -140,6 +140,20 @@ struct ContentView: View {
140140

141141

142142
var body: some View {
143+
#if os(visionOS)
144+
return NavigationView {
145+
contentView()
146+
.navigationBarTitle(animated ? "AnimatedImage" : "WebImage")
147+
.navigationBarItems(leading:
148+
Button(action: { self.reloadCache() }) {
149+
Text("Reload")
150+
}, trailing:
151+
Button(action: { self.switchView() }) {
152+
Text("Switch")
153+
}
154+
)
155+
}
156+
#endif
143157
#if os(iOS)
144158
return NavigationView {
145159
contentView()

Example/SDWebImageSwiftUIDemo/DetailView.swift

Lines changed: 3 additions & 3 deletions
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)

0 commit comments

Comments
 (0)