Преглед изворни кода

【VisionPro适配】适配VisionOS

xcbosa mbp16 пре 1 година
родитељ
комит
52c25a8666
2 измењених фајлова са 70 додато и 1 уклоњено
  1. 5 1
      Source/Charts/Utils/Platform+Accessibility.swift
  2. 65 0
      Source/Charts/Utils/Platform.swift

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

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

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

@@ -1,8 +1,73 @@
 import Foundation
 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 
 /** 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*
 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). */
 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)
 #if os(iOS) || os(tvOS)
 	import UIKit
 	import UIKit