Added visionOS support
Add visionOS Demo The scale using traitCollection.displayScale
This commit is contained in:
parent
e837c37d45
commit
2d4839a195
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,6 @@
|
|||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:SDWebImageSwiftUI.xcodeproj">
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
|
|
@ -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>
|
|
@ -54,10 +54,8 @@
|
|||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<RemoteRunnable
|
||||
runnableDebuggingMode = "2"
|
||||
BundleIdentifier = "com.apple.Carousel"
|
||||
RemotePath = "/SDWebImageSwiftUIDemo-watchOS WatchKit App">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
|
||||
|
@ -65,7 +63,7 @@
|
|||
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
|
||||
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
|
||||
</BuildableReference>
|
||||
</RemoteRunnable>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
|
@ -73,10 +71,8 @@
|
|||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<RemoteRunnable
|
||||
runnableDebuggingMode = "2"
|
||||
BundleIdentifier = "com.apple.Carousel"
|
||||
RemotePath = "/SDWebImageSwiftUIDemo-watchOS WatchKit App">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
|
||||
|
@ -84,16 +80,7 @@
|
|||
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
|
||||
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
|
||||
</BuildableReference>
|
||||
</RemoteRunnable>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "32E529362348A0DD00EA46FF"
|
||||
BuildableName = "SDWebImageSwiftUIDemo-watchOS WatchKit App.app"
|
||||
BlueprintName = "SDWebImageSwiftUIDemo-watchOS WatchKit App"
|
||||
ReferencedContainer = "container:SDWebImageSwiftUI.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
// 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(SDImageAWebPCoder.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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "reality",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"layers" : [
|
||||
{
|
||||
"filename" : "Front.solidimagestacklayer"
|
||||
},
|
||||
{
|
||||
"filename" : "Middle.solidimagestacklayer"
|
||||
},
|
||||
{
|
||||
"filename" : "Back.solidimagestacklayer"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "reality",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "reality",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -112,7 +112,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)
|
||||
|
@ -157,6 +157,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()
|
||||
|
|
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
|
|
@ -403,8 +403,6 @@
|
|||
Base,
|
||||
);
|
||||
mainGroup = 32C43DC222FD540D00BE87F5;
|
||||
packageReferences = (
|
||||
);
|
||||
productRefGroup = 32C43DCD22FD540D00BE87F5 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
|
|
|
@ -4,7 +4,4 @@
|
|||
<FileRef
|
||||
location = "group:Example/SDWebImageSwiftUI.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Pods/Pods.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import SwiftUI
|
||||
import SDWebImage
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(macOS)
|
||||
#if !os(watchOS)
|
||||
|
||||
/// A coordinator object used for `AnimatedImage`native view bridge for UIKit/AppKit.
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
|
@ -183,7 +183,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
|
|||
|
||||
#if os(macOS)
|
||||
public typealias NSViewType = AnimatedImageViewWrapper
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
public typealias UIViewType = AnimatedImageViewWrapper
|
||||
#endif
|
||||
|
||||
|
@ -205,7 +205,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
|
|||
public static func dismantleNSView(_ nsView: AnimatedImageViewWrapper, coordinator: Coordinator) {
|
||||
dismantleView(nsView, coordinator: coordinator)
|
||||
}
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
public func makeUIView(context: Context) -> AnimatedImageViewWrapper {
|
||||
makeView(context: context)
|
||||
}
|
||||
|
@ -373,14 +373,14 @@ public struct AnimatedImage : PlatformViewRepresentable {
|
|||
// AspectRatio && ContentMode
|
||||
#if os(macOS)
|
||||
let contentMode: NSImageScaling
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
let contentMode: UIView.ContentMode
|
||||
#endif
|
||||
if let _ = imageLayout.aspectRatio {
|
||||
// If `aspectRatio` is not `nil`, always scale to fill and SwiftUI will layout the container with custom aspect ratio.
|
||||
#if os(macOS)
|
||||
contentMode = .scaleAxesIndependently
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
contentMode = .scaleToFill
|
||||
#endif
|
||||
} else {
|
||||
|
@ -391,20 +391,20 @@ public struct AnimatedImage : PlatformViewRepresentable {
|
|||
// Actually, NSImageView have no `.aspectFill` unlike UIImageView, only `CALayerContentsGravity.resizeAspectFill` have the same concept
|
||||
// However, using `.scaleProportionallyUpOrDown`, SwiftUI still layout the HostingView correctly, so this is OK
|
||||
contentMode = .scaleProportionallyUpOrDown
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
contentMode = .scaleAspectFill
|
||||
#endif
|
||||
case .fit:
|
||||
#if os(macOS)
|
||||
contentMode = .scaleProportionallyUpOrDown
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
contentMode = .scaleAspectFit
|
||||
#endif
|
||||
case .none:
|
||||
// If `contentMode` is not set at all, using scale to fill as SwiftUI default value
|
||||
#if os(macOS)
|
||||
contentMode = .scaleAxesIndependently
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
contentMode = .scaleToFill
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ extension PlatformImage {
|
|||
static var empty = PlatformImage()
|
||||
}
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(watchOS)
|
||||
#if !os(macOS)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
extension PlatformImage.Orientation {
|
||||
@inlinable var toSwiftUI: Image.Orientation {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import Foundation
|
||||
import SDWebImage
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(macOS)
|
||||
#if !os(watchOS)
|
||||
|
||||
/// Use wrapper to solve tne `UIImageView`/`NSImageView` frame size become image size issue (SwiftUI's Bug)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
#if os(macOS) || os(iOS) || os(tvOS)
|
||||
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
|
||||
/// An activity indicator (system style)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public struct ActivityIndicator: PlatformViewRepresentable {
|
||||
|
@ -26,11 +26,11 @@ public struct ActivityIndicator: PlatformViewRepresentable {
|
|||
|
||||
#if os(macOS)
|
||||
public typealias NSViewType = NSProgressIndicator
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
public typealias UIViewType = UIActivityIndicatorView
|
||||
#endif
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
public func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
|
||||
let activityStyle: UIActivityIndicatorView.Style
|
||||
switch style {
|
||||
|
|
|
@ -58,7 +58,7 @@ public struct IndicatorViewModifier<T> : ViewModifier where T : View {
|
|||
}
|
||||
}
|
||||
|
||||
#if os(macOS) || os(iOS) || os(tvOS)
|
||||
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
extension Indicator where T == ActivityIndicator {
|
||||
/// Activity Indicator
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
#if os(macOS) || os(iOS) || os(tvOS)
|
||||
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS)
|
||||
/// A progress bar indicator (system style)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public struct ProgressIndicator: PlatformViewRepresentable {
|
||||
|
@ -29,11 +29,11 @@ public struct ProgressIndicator: PlatformViewRepresentable {
|
|||
|
||||
#if os(macOS)
|
||||
public typealias NSViewType = ProgressIndicatorWrapper
|
||||
#elseif os(iOS) || os(tvOS)
|
||||
#else
|
||||
public typealias UIViewType = ProgressIndicatorWrapper
|
||||
#endif
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
public func makeUIView(context: UIViewRepresentableContext<ProgressIndicator>) -> ProgressIndicatorWrapper {
|
||||
let progressStyle: UIProgressView.Style
|
||||
switch style {
|
||||
|
|
|
@ -22,7 +22,7 @@ public typealias PlatformImage = UIImage
|
|||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public typealias PlatformView = NSView
|
||||
#endif
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public typealias PlatformView = UIView
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@ public typealias PlatformView = WKInterfaceObject
|
|||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public typealias PlatformViewRepresentable = NSViewRepresentable
|
||||
#endif
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public typealias PlatformViewRepresentable = UIViewRepresentable
|
||||
#endif
|
||||
|
@ -50,7 +50,7 @@ extension NSViewRepresentable {
|
|||
typealias PlatformViewType = NSViewType
|
||||
}
|
||||
#endif
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
extension UIViewRepresentable {
|
||||
typealias PlatformViewType = UIViewType
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(macOS)
|
||||
#if !os(watchOS)
|
||||
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
struct PlatformAppear: PlatformViewRepresentable {
|
||||
let appearAction: () -> Void
|
||||
let disappearAction: () -> Void
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(iOS) || os(tvOS) || os(visionOS)
|
||||
func makeUIView(context: Context) -> some UIView {
|
||||
let view = PlatformAppearView()
|
||||
view.appearAction = appearAction
|
||||
|
|
|
@ -64,10 +64,10 @@ public struct WebImage : View {
|
|||
@ObservedObject var indicatorStatus : IndicatorStatus
|
||||
|
||||
// FIXME: Use SwiftUI StateObject and remove onPlatformAppear once drop iOS 13 support
|
||||
@Backport.StateObject var imagePlayer = ImagePlayer()
|
||||
@StateObject var imagePlayer = ImagePlayer()
|
||||
|
||||
// FIXME: Use SwiftUI StateObject and remove onPlatformAppear once drop iOS 13 support
|
||||
@Backport.StateObject var imageManager : ImageManager
|
||||
@StateObject var imageManager : ImageManager
|
||||
|
||||
/// Create a web image with url, placeholder, custom options and context. Optional can support animated image using Binding.
|
||||
/// - Parameter url: The image url
|
||||
|
@ -89,7 +89,7 @@ public struct WebImage : View {
|
|||
imageModel.context = context
|
||||
_imageModel = ObservedObject(wrappedValue: imageModel)
|
||||
let imageManager = ImageManager()
|
||||
_imageManager = Backport.StateObject(wrappedValue: imageManager)
|
||||
_imageManager = StateObject(wrappedValue: imageManager)
|
||||
_indicatorStatus = ObservedObject(wrappedValue: imageManager.indicatorStatus)
|
||||
}
|
||||
|
||||
|
@ -160,9 +160,11 @@ public struct WebImage : View {
|
|||
// ensure CGImage is nil
|
||||
if image.cgImage == nil {
|
||||
// draw vector into bitmap with the screen scale (behavior like AppKit)
|
||||
#if os(iOS) || os(tvOS)
|
||||
#if os(visionOS)
|
||||
let scale = UITraitCollection.current.displayScale
|
||||
#elseif os(iOS) || os(tvOS) || os(visionOS)
|
||||
let scale = UIScreen.main.scale
|
||||
#else
|
||||
#elseif os(watchOS)
|
||||
let scale = WKInterfaceDevice.current().screenScale
|
||||
#endif
|
||||
UIGraphicsBeginImageContextWithOptions(image.size, false, scale)
|
||||
|
|
Loading…
Reference in New Issue