Skip to content

(Part 1) Support compile for visionOS (no package manager support) #267

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 8 commits into from
Sep 2, 2023
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
18 changes: 9 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ permissions:
jobs:
Pods:
name: Cocoapods Lint
runs-on: macos-11
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
DEVELOPER_DIR: /Applications/Xcode_14.1.app
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -34,9 +34,9 @@ jobs:

Demo:
name: Run Demo
runs-on: macos-11
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
DEVELOPER_DIR: /Applications/Xcode_14.1.app
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
OSXSCHEME: SDWebImageSwiftUIDemo-macOS
iOSSCHEME: SDWebImageSwiftUIDemo
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
matrix:
iosDestination: ["name=iPhone 13 Pro"]
tvOSDestination: ["name=Apple TV 4K"]
tvOSDestination: ["name=Apple TV"]
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 - 45mm"]
macOSDestination: ["platform=macOS"]
macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"]
Expand Down Expand Up @@ -92,9 +92,9 @@ jobs:

Test:
name: Unit Test
runs-on: macos-11
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
DEVELOPER_DIR: /Applications/Xcode_14.1.app
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
OSXSCHEME: SDWebImageSwiftUITests macOS
iOSSCHEME: SDWebImageSwiftUITests
Expand Down Expand Up @@ -154,9 +154,9 @@ jobs:

Build:
name: Build Library
runs-on: macos-11
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
DEVELOPER_DIR: /Applications/Xcode_14.1.app
PROJECT_NAME: SDWebImageSwiftUI.xcodeproj
OSXSCHEME: SDWebImageSwiftUI macOS
iOSSCHEME: SDWebImageSwiftUI
Expand Down
895 changes: 449 additions & 446 deletions Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "32D5D15F2A445B250098BDFC"
BuildableName = "SDWebImageSwiftUIDemo-visionOS.app"
BlueprintName = "SDWebImageSwiftUIDemo-visionOS"
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
46 changes: 46 additions & 0 deletions Example/SDWebImageSwiftUIDemo-visionOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 UIKit
import SDWebImage
import SDWebImageWebPCoder
import SDWebImageSVGCoder
import SDWebImagePDFCoder

// no changes in your AppDelegate class
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Add WebP/SVG/PDF support
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support vector format for both WebImage/AnimatedImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var options = options
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering, should not force decode
options.insert(.avoidDecodeImage)
}
return SDWebImageOptionsResult(options: options, context: context)
}
return true
}
}

@main
struct SDWebImageSwiftUIDemo: App {
// inject into SwiftUI life-cycle via adaptor
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.solidimagestacklayer"
},
{
"filename" : "Middle.solidimagestacklayer"
},
{
"filename" : "Back.solidimagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
11 changes: 11 additions & 0 deletions Example/SDWebImageSwiftUIDemo-visionOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
16 changes: 15 additions & 1 deletion Example/SDWebImageSwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct ContentView: View {
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
HStack {
if self.animated {
#if os(macOS) || os(iOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
AnimatedImage(url: URL(string:url), isAnimating: .constant(true))
.onViewUpdate { view, context in
#if os(macOS)
Expand Down Expand Up @@ -140,6 +140,20 @@ struct ContentView: View {


var body: some View {
#if os(visionOS)
return NavigationView {
contentView()
.navigationBarTitle(animated ? "AnimatedImage" : "WebImage")
.navigationBarItems(leading:
Button(action: { self.reloadCache() }) {
Text("Reload")
}, trailing:
Button(action: { self.switchView() }) {
Text("Switch")
}
)
}
#endif
#if os(iOS)
return NavigationView {
contentView()
Expand Down
6 changes: 3 additions & 3 deletions Example/SDWebImageSwiftUIDemo/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct DetailView: View {

var body: some View {
VStack {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
zoomView()
.navigationBarItems(trailing: Button(isAnimating ? "Stop" : "Start") {
self.isAnimating.toggle()
Expand All @@ -62,7 +62,7 @@ struct DetailView: View {
}

func zoomView() -> some View {
#if os(macOS) || os(iOS)
#if os(macOS) || os(iOS) || os(visionOS)
return contentView()
.scaleEffect(self.scale)
.gesture(MagnificationGesture(minimumScaleDelta: 0.1).onChanged { value in
Expand Down Expand Up @@ -94,7 +94,7 @@ struct DetailView: View {
func contentView() -> some View {
HStack {
if animated {
#if os(macOS) || os(iOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
AnimatedImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder], isAnimating: $isAnimating)
.resizable()
.placeholder(.wifiExclamationmark)
Expand Down
Loading