diff --git a/Sources/OpenSwiftUI/Layout/Alignment.swift b/Sources/OpenSwiftUI/Layout/Alignment.swift index 5246970..69770bc 100644 --- a/Sources/OpenSwiftUI/Layout/Alignment.swift +++ b/Sources/OpenSwiftUI/Layout/Alignment.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct Alignment { public var horizontal: HorizontalAlignment diff --git a/Sources/OpenSwiftUI/Layout/EdgeInsets.swift b/Sources/OpenSwiftUI/Layout/EdgeInsets.swift index ba39327..62617f7 100644 --- a/Sources/OpenSwiftUI/Layout/EdgeInsets.swift +++ b/Sources/OpenSwiftUI/Layout/EdgeInsets.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct EdgeInsets: Equatable { public var top: CGFloat diff --git a/Sources/OpenSwiftUI/Layout/ViewDimensions.swift b/Sources/OpenSwiftUI/Layout/ViewDimensions.swift index e5a037d..4f6fc98 100644 --- a/Sources/OpenSwiftUI/Layout/ViewDimensions.swift +++ b/Sources/OpenSwiftUI/Layout/ViewDimensions.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct ViewDimensions { public var width: CGFloat { diff --git a/Sources/OpenSwiftUI/LocalizedStringKey.swift b/Sources/OpenSwiftUI/LocalizedStringKey.swift index a744aa5..a7473b2 100644 --- a/Sources/OpenSwiftUI/LocalizedStringKey.swift +++ b/Sources/OpenSwiftUI/LocalizedStringKey.swift @@ -1,3 +1,4 @@ +#if canImport(Foundation) public struct LocalizedStringKey { internal var key: String private var hasFormatting: Bool = false @@ -10,3 +11,4 @@ public struct LocalizedStringKey { self.key = value } } +#endif diff --git a/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift b/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift index f316058..711b7b5 100644 --- a/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift +++ b/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct PaddingModifier: ViewModifier { static let defaultPadding: CGFloat = 8 diff --git a/Sources/OpenSwiftUI/Views/Color.swift b/Sources/OpenSwiftUI/Views/Color.swift index 1c1d4c2..22b4ab6 100644 --- a/Sources/OpenSwiftUI/Views/Color.swift +++ b/Sources/OpenSwiftUI/Views/Color.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public class AnyColorBox { } @@ -60,7 +64,11 @@ public class DisplayP3: AnyColorBox { extension Double { fileprivate var hexString: String { + #if canImport(Foundation) return String(format: "%02X", Int((self * 255).rounded())) + #else + fatalError("Not Implemented.") + #endif } } diff --git a/Sources/OpenSwiftUI/Views/Font.swift b/Sources/OpenSwiftUI/Views/Font.swift index 3de6045..56b7bc4 100644 --- a/Sources/OpenSwiftUI/Views/Font.swift +++ b/Sources/OpenSwiftUI/Views/Font.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif extension View { public func font(_ font: Font?) -> some View { diff --git a/Sources/OpenSwiftUI/Views/HStack.swift b/Sources/OpenSwiftUI/Views/HStack.swift index fa4dddb..8692146 100644 --- a/Sources/OpenSwiftUI/Views/HStack.swift +++ b/Sources/OpenSwiftUI/Views/HStack.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct HStack: View where Content: View { public typealias Body = Never diff --git a/Sources/OpenSwiftUI/Views/HStackLayout.swift b/Sources/OpenSwiftUI/Views/HStackLayout.swift index 17bfc92..63441f6 100644 --- a/Sources/OpenSwiftUI/Views/HStackLayout.swift +++ b/Sources/OpenSwiftUI/Views/HStackLayout.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct _HStackLayout { public var alignment: VerticalAlignment diff --git a/Sources/OpenSwiftUI/Views/Image.swift b/Sources/OpenSwiftUI/Views/Image.swift index 5022288..cb98499 100644 --- a/Sources/OpenSwiftUI/Views/Image.swift +++ b/Sources/OpenSwiftUI/Views/Image.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct Image: Equatable { public var _provider: AnyImageProviderBox @@ -26,6 +30,7 @@ extension Image: View { } } +#if canImport(Foundation) extension Image { public init(_ name: String, bundle: Foundation.Bundle? = nil) { fatalError() @@ -40,3 +45,4 @@ extension Image { fatalError() } } +#endif diff --git a/Sources/OpenSwiftUI/Views/Picker.swift b/Sources/OpenSwiftUI/Views/Picker.swift index bc4a99c..2368356 100644 --- a/Sources/OpenSwiftUI/Views/Picker.swift +++ b/Sources/OpenSwiftUI/Views/Picker.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public protocol PickerStyle { static func _makeView(value: _GraphValue<_PickerValue>, inputs: _ViewInputs) -> _ViewOutputs where SelectionValue: Hashable @@ -69,11 +73,13 @@ public struct Picker: View where Label: View, Se } extension Picker where Label == Text { + #if canImport(Foundation) public init(_ titleKey: LocalizedStringKey, selection: Binding, @ViewBuilder content: () -> Content) { self.selection = selection self.label = Text(titleKey) self.content = content() } + #endif public init(_ title: S, selection: Binding, @ViewBuilder content: () -> Content) where S: StringProtocol { self.selection = selection diff --git a/Sources/OpenSwiftUI/Views/Shape.swift b/Sources/OpenSwiftUI/Views/Shape.swift index d3205e1..9b57efa 100644 --- a/Sources/OpenSwiftUI/Views/Shape.swift +++ b/Sources/OpenSwiftUI/Views/Shape.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public protocol Shape: Animatable, View { func path(in rect: CGRect) -> Path diff --git a/Sources/OpenSwiftUI/Views/ShapeView.swift b/Sources/OpenSwiftUI/Views/ShapeView.swift index ce1ce60..fc80892 100644 --- a/Sources/OpenSwiftUI/Views/ShapeView.swift +++ b/Sources/OpenSwiftUI/Views/ShapeView.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct _ShapeView: View where Content: Shape, Style: ShapeStyle { public var body: Never { diff --git a/Sources/OpenSwiftUI/Views/Shapes/Angle.swift b/Sources/OpenSwiftUI/Views/Shapes/Angle.swift index 7c40717..ad4bfd5 100644 --- a/Sources/OpenSwiftUI/Views/Shapes/Angle.swift +++ b/Sources/OpenSwiftUI/Views/Shapes/Angle.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct Angle { public var radians: Double diff --git a/Sources/OpenSwiftUI/Views/Shapes/Circle.swift b/Sources/OpenSwiftUI/Views/Shapes/Circle.swift index 4cba5b4..2e7d55d 100644 --- a/Sources/OpenSwiftUI/Views/Shapes/Circle.swift +++ b/Sources/OpenSwiftUI/Views/Shapes/Circle.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct Circle: Shape { public func path(in rect: CGRect) -> Path { diff --git a/Sources/OpenSwiftUI/Views/Shapes/Path.swift b/Sources/OpenSwiftUI/Views/Shapes/Path.swift index fdecc16..d798846 100644 --- a/Sources/OpenSwiftUI/Views/Shapes/Path.swift +++ b/Sources/OpenSwiftUI/Views/Shapes/Path.swift @@ -1,8 +1,7 @@ +#if canImport(Foundation) import Foundation -#if os(Linux) -import CoreGraphicsShim #else -import CoreGraphics +import CoreGraphicsShim #endif internal struct FixedRoundedRect: Equatable { diff --git a/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift b/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift index 093e870..59029fa 100644 --- a/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift +++ b/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct Rectangle: Shape { public func path(in rect: CGRect) -> Path { diff --git a/Sources/OpenSwiftUI/Views/Stepper.swift b/Sources/OpenSwiftUI/Views/Stepper.swift index e9d7d2e..63e84a0 100644 --- a/Sources/OpenSwiftUI/Views/Stepper.swift +++ b/Sources/OpenSwiftUI/Views/Stepper.swift @@ -30,12 +30,14 @@ extension Stepper { } extension Stepper where Label == Text { + #if canImport(Foundation) public init(_ titleKey: LocalizedStringKey, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in }) { self.label = Text(titleKey) self.onIncrement = onIncrement self.onDecrement = onDecrement self.onEditingChanged = onEditingChanged } + #endif @_disfavoredOverload public init(_ title: S, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol { self.label = Text(title) @@ -44,20 +46,24 @@ extension Stepper where Label == Text { self.onEditingChanged = onEditingChanged } + #if canImport(Foundation) public init(_ titleKey: LocalizedStringKey, value: Binding, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable { self.label = Text(titleKey) self.onEditingChanged = onEditingChanged } + #endif @_disfavoredOverload public init(_ title: S, value: Binding, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol, V: Strideable { self.label = Text(title) self.onEditingChanged = onEditingChanged } + #if canImport(Foundation) public init(_ titleKey: LocalizedStringKey, value: Binding, in bounds: ClosedRange, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable { self.label = Text(titleKey) self.onEditingChanged = onEditingChanged } + #endif @_disfavoredOverload public init(_ title: S, value: Binding, in bounds: ClosedRange, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol, V: Strideable { self.label = Text(title) diff --git a/Sources/OpenSwiftUI/Views/Text.swift b/Sources/OpenSwiftUI/Views/Text.swift index 5459325..e8b7aa2 100644 --- a/Sources/OpenSwiftUI/Views/Text.swift +++ b/Sources/OpenSwiftUI/Views/Text.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public class AnyTextStorage { public var storage: Storage @@ -64,9 +68,11 @@ public struct Text: View, Equatable { self._storage = .anyTextStorage(AnyTextStorage(storage: String(content))) } + #if canImport(Foundation) public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil) { self._storage = .anyTextStorage(AnyTextStorage(storage: key.key)) } + #endif private init(verbatim content: String, modifiers: [Modifier] = []) { self._storage = .verbatim(content) diff --git a/Sources/OpenSwiftUI/Views/Toggle.swift b/Sources/OpenSwiftUI/Views/Toggle.swift index ced4a3e..9623031 100644 --- a/Sources/OpenSwiftUI/Views/Toggle.swift +++ b/Sources/OpenSwiftUI/Views/Toggle.swift @@ -20,9 +20,11 @@ extension Toggle where Label == ToggleStyleConfiguration.Label { } extension Toggle where Label == Text { + #if canImport(Foundation) public init(_ titleKey: LocalizedStringKey, isOn: Binding) { fatalError() } + #endif public init(_ title: S, isOn: Binding) where S: StringProtocol { fatalError() diff --git a/Sources/OpenSwiftUI/Views/VStack.swift b/Sources/OpenSwiftUI/Views/VStack.swift index 3c8be84..21ccb30 100644 --- a/Sources/OpenSwiftUI/Views/VStack.swift +++ b/Sources/OpenSwiftUI/Views/VStack.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct VStack: View where Content: View { public typealias Body = Never diff --git a/Sources/OpenSwiftUI/Views/VStackLayout.swift b/Sources/OpenSwiftUI/Views/VStackLayout.swift index c047497..dd123dd 100644 --- a/Sources/OpenSwiftUI/Views/VStackLayout.swift +++ b/Sources/OpenSwiftUI/Views/VStackLayout.swift @@ -1,4 +1,8 @@ +#if canImport(Foundation) import Foundation +#else +import CoreGraphicsShim +#endif public struct _VStackLayout { public var alignment: HorizontalAlignment diff --git a/Tests/OpenSwiftUITests/OpenSwiftUITests.swift b/Tests/OpenSwiftUITests/OpenSwiftUITests.swift index 0658af0..8d70a71 100644 --- a/Tests/OpenSwiftUITests/OpenSwiftUITests.swift +++ b/Tests/OpenSwiftUITests/OpenSwiftUITests.swift @@ -3,12 +3,12 @@ import XCTest final class OpenSwiftUITests: XCTestCase { func testExample() { - let body = VStack { + let _ = VStack { Text("Hello") Text("World") } - let body = HStack { + let _ = HStack { if true { Text("Hello") }