Browse Source

【VisionPro适配】适配VisionOS

xcbosa mbp16 1 year ago
parent
commit
52c25a8666

+ 5 - 1
Source/Charts/Utils/Platform+Accessibility.swift

@@ -11,7 +11,7 @@
 
 import Foundation
 
-#if os(iOS) || os(tvOS)
+#if os(iOS) || os(tvOS) || os(visionOS)
 import UIKit
 
 internal func accessibilityPostLayoutChangedNotification(withElement element: Any? = nil)
@@ -62,7 +62,11 @@ open class NSUIAccessibilityElement: UIAccessibilityElement
         set
         {
             guard let containerView = containerView else { return }
+            #if os(visionOS)
+            super.accessibilityFrame = containerView.frame
+            #else
             super.accessibilityFrame = containerView.convert(newValue, to: UIScreen.main.coordinateSpace)
+            #endif
         }
     }
 }

+ 65 - 0
Source/Charts/Utils/Platform.swift

@@ -1,8 +1,73 @@
 import Foundation
 
+public class VisionOSScreen: NSObject {
+    
+    public static let main = VisionOSScreen()
+    
+}
+
 /** This file provides a thin abstraction layer atop of UIKit (iOS, tvOS) and Cocoa (OS X). The two APIs are very much 
 alike, and for the chart library's usage of the APIs it is often sufficient to typealias one to the other. The NSUI*
 types are aliased to either their UI* implementation (on iOS) or their NS* implementation (on OS X). */
+#if os(visionOS)
+import UIKit
+
+public typealias ParagraphStyle = NSParagraphStyle
+public typealias MutableParagraphStyle = NSMutableParagraphStyle
+public typealias TextAlignment = NSTextAlignment
+public typealias NSUIFont = UIFont
+public typealias NSUIImage = UIImage
+public typealias NSUIScrollView = UIScrollView
+public typealias NSUIScreen = VisionOSScreen
+public typealias NSUIDisplayLink = CADisplayLink
+
+extension NSUIColor
+{
+    var nsuirgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)? {
+        var red: CGFloat = 0
+        var green: CGFloat = 0
+        var blue: CGFloat = 0
+        var alpha: CGFloat = 0
+
+        guard getRed(&red, green: &green, blue: &blue, alpha: &alpha) else {
+            return nil
+        }
+
+        return (red: red, green: green, blue: blue, alpha: alpha)
+    }
+}
+
+open class NSUIView: UIView
+{
+    @objc var nsuiLayer: CALayer?
+    {
+        return self.layer
+    }
+}
+
+extension UIScrollView
+{
+    @objc var nsuiIsScrollEnabled: Bool
+    {
+        get { return isScrollEnabled }
+        set { isScrollEnabled = newValue }
+    }
+}
+
+extension VisionOSScreen
+{
+    @objc final var nsuiScale: CGFloat
+    {
+        return 1
+    }
+}
+
+func NSUIMainScreen() -> NSUIScreen?
+{
+    return NSUIScreen.main
+}
+#endif
+
 #if os(iOS) || os(tvOS)
 	import UIKit