|
| 1 | +// |
| 2 | +// SwiftUI.Color.swift |
| 3 | +// OpenSwiftUIBridge |
| 4 | + |
| 5 | +#if canImport(SwiftUI) |
| 6 | +public import SwiftUI |
| 7 | +public import OpenSwiftUI |
| 8 | + |
| 9 | +// MARK: Color + Bridgeable |
| 10 | + |
| 11 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 12 | +extension SwiftUI.Color: Bridgeable { |
| 13 | + public typealias Counterpart = OpenSwiftUI.Color |
| 14 | + |
| 15 | + public init(_ counterpart: Counterpart) { |
| 16 | + self.init(OpenSwiftUIColor2SwiftUIColorAdapter(base: counterpart)) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 21 | +extension OpenSwiftUI.Color: Bridgeable { |
| 22 | + public typealias Counterpart = SwiftUI.Color |
| 23 | + |
| 24 | + public init(_ counterpart: Counterpart) { |
| 25 | + self.init(SwiftUIColor2OpenSwiftUIColorAdapter(base: counterpart)) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 30 | +private struct OpenSwiftUIColor2SwiftUIColorAdapter: Hashable, SwiftUI.ShapeStyle { |
| 31 | + private let base: OpenSwiftUI.Color |
| 32 | + |
| 33 | + init(base: OpenSwiftUI.Color) { |
| 34 | + self.base = base |
| 35 | + } |
| 36 | + |
| 37 | + public typealias Resolved = SwiftUI.Color.Resolved |
| 38 | + |
| 39 | + public func resolve(in environment: SwiftUI.EnvironmentValues) -> SwiftUI.Color.Resolved { |
| 40 | + .init(base.resolve(in: .init(environment))) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 45 | +private struct SwiftUIColor2OpenSwiftUIColorAdapter: Hashable, OpenSwiftUI.ShapeStyle { |
| 46 | + private let base: SwiftUI.Color |
| 47 | + |
| 48 | + init(base: SwiftUI.Color) { |
| 49 | + self.base = base |
| 50 | + } |
| 51 | + |
| 52 | + public typealias Resolved = OpenSwiftUI.Color.Resolved |
| 53 | + |
| 54 | + public func resolve(in environment: OpenSwiftUI.EnvironmentValues) -> OpenSwiftUI.Color.Resolved { |
| 55 | + .init(base.resolve(in: .init(environment))) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// MARK: - Color.Resolved + Bridgeable |
| 60 | + |
| 61 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 62 | +extension SwiftUI.Color.Resolved: Bridgeable { |
| 63 | + public typealias Counterpart = OpenSwiftUI.Color.Resolved |
| 64 | + |
| 65 | + public init(_ counterpart: Counterpart) { |
| 66 | + self.init(colorSpace: .sRGBLinear, red: counterpart.linearRed, green: counterpart.linearGreen, blue: counterpart.linearBlue) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) |
| 71 | +extension OpenSwiftUI.Color.Resolved: Bridgeable { |
| 72 | + public typealias Counterpart = SwiftUI.Color.Resolved |
| 73 | + |
| 74 | + public init(_ counterpart: Counterpart) { |
| 75 | + self.init(colorSpace: .sRGBLinear, red: counterpart.linearRed, green: counterpart.linearGreen, blue: counterpart.linearBlue) |
| 76 | + } |
| 77 | +} |
| 78 | +#endif |
0 commit comments