Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building for Mac in Xcode #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Layout/Alignment.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct Alignment {
public var horizontal: HorizontalAlignment
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Layout/EdgeInsets.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct EdgeInsets: Equatable {
public var top: CGFloat
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Layout/ViewDimensions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct ViewDimensions {
public var width: CGFloat {
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/LocalizedStringKey.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if canImport(Foundation)
public struct LocalizedStringKey {
internal var key: String
private var hasFormatting: Bool = false
Expand All @@ -10,3 +11,4 @@ public struct LocalizedStringKey {
self.key = value
}
}
#endif
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct PaddingModifier: ViewModifier {
static let defaultPadding: CGFloat = 8
Expand Down
8 changes: 8 additions & 0 deletions Sources/OpenSwiftUI/Views/Color.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public class AnyColorBox {
}
Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/Font.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

extension View {
public func font(_ font: Font?) -> some View {
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/HStack.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct HStack<Content>: View where Content: View {
public typealias Body = Never
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/HStackLayout.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct _HStackLayout {
public var alignment: VerticalAlignment
Expand Down
6 changes: 6 additions & 0 deletions Sources/OpenSwiftUI/Views/Image.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct Image: Equatable {
public var _provider: AnyImageProviderBox
Expand Down Expand Up @@ -26,6 +30,7 @@ extension Image: View {
}
}

#if canImport(Foundation)
extension Image {
public init(_ name: String, bundle: Foundation.Bundle? = nil) {
fatalError()
Expand All @@ -40,3 +45,4 @@ extension Image {
fatalError()
}
}
#endif
6 changes: 6 additions & 0 deletions Sources/OpenSwiftUI/Views/Picker.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public protocol PickerStyle {
static func _makeView<SelectionValue>(value: _GraphValue<_PickerValue<Self, SelectionValue>>, inputs: _ViewInputs) -> _ViewOutputs where SelectionValue: Hashable
Expand Down Expand Up @@ -69,11 +73,13 @@ public struct Picker<Label, SelectionValue, Content>: View where Label: View, Se
}

extension Picker where Label == Text {
#if canImport(Foundation)
public init(_ titleKey: LocalizedStringKey, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content) {
self.selection = selection
self.label = Text(titleKey)
self.content = content()
}
#endif

public init<S>(_ title: S, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content) where S: StringProtocol {
self.selection = selection
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/Shape.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public protocol Shape: Animatable, View {
func path(in rect: CGRect) -> Path
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/ShapeView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct _ShapeView<Content, Style>: View where Content: Shape, Style: ShapeStyle {
public var body: Never {
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/Shapes/Angle.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct Angle {
public var radians: Double
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/Shapes/Circle.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct Circle: Shape {
public func path(in rect: CGRect) -> Path {
Expand Down
5 changes: 2 additions & 3 deletions Sources/OpenSwiftUI/Views/Shapes/Path.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#if canImport(Foundation)
import Foundation
#if os(Linux)
import CoreGraphicsShim
#else
import CoreGraphics
import CoreGraphicsShim
#endif

internal struct FixedRoundedRect: Equatable {
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct Rectangle: Shape {
public func path(in rect: CGRect) -> Path {
Expand Down
6 changes: 6 additions & 0 deletions Sources/OpenSwiftUI/Views/Stepper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(_ title: S, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol {
self.label = Text(title)
Expand All @@ -44,20 +46,24 @@ extension Stepper where Label == Text {
self.onEditingChanged = onEditingChanged
}

#if canImport(Foundation)
public init<V>(_ titleKey: LocalizedStringKey, value: Binding<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable {
self.label = Text(titleKey)
self.onEditingChanged = onEditingChanged
}
#endif

@_disfavoredOverload public init<S, V>(_ title: S, value: Binding<V>, 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<V>(_ titleKey: LocalizedStringKey, value: Binding<V>, in bounds: ClosedRange<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable {
self.label = Text(titleKey)
self.onEditingChanged = onEditingChanged
}
#endif

@_disfavoredOverload public init<S, V>(_ title: S, value: Binding<V>, in bounds: ClosedRange<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol, V: Strideable {
self.label = Text(title)
Expand Down
6 changes: 6 additions & 0 deletions Sources/OpenSwiftUI/Views/Text.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public class AnyTextStorage<Storage: StringProtocol> {
public var storage: Storage
Expand Down Expand Up @@ -64,9 +68,11 @@ public struct Text: View, Equatable {
self._storage = .anyTextStorage(AnyTextStorage<String>(storage: String(content)))
}

#if canImport(Foundation)
public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil) {
self._storage = .anyTextStorage(AnyTextStorage<String>(storage: key.key))
}
#endif

private init(verbatim content: String, modifiers: [Modifier] = []) {
self._storage = .verbatim(content)
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Views/Toggle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ extension Toggle where Label == ToggleStyleConfiguration.Label {
}

extension Toggle where Label == Text {
#if canImport(Foundation)
public init(_ titleKey: LocalizedStringKey, isOn: Binding<Bool>) {
fatalError()
}
#endif

public init<S>(_ title: S, isOn: Binding<Bool>) where S: StringProtocol {
fatalError()
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/VStack.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct VStack<Content>: View where Content: View {
public typealias Body = Never
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Views/VStackLayout.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if canImport(Foundation)
import Foundation
#else
import CoreGraphicsShim
#endif

public struct _VStackLayout {
public var alignment: HorizontalAlignment
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenSwiftUITests/OpenSwiftUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down