Skip to content

Commit f4d379f

Browse files
authored
Add OPENSWIFTUI_TARGET_RELEASE support (#97)
* Add OPENSWIFTUI_TARGET_RELEASE support * Add Shape interface
1 parent 5f2867f commit f4d379f

File tree

7 files changed

+244
-8
lines changed

7 files changed

+244
-8
lines changed

Package.swift

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,64 @@ let development = envEnable("OPENSWIFTUI_DEVELOPMENT", default: false)
2323
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
2424
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"
2525

26+
let releaseVersion = Context.environment["OPENSWIFTUI_TARGET_RELEASE"].flatMap { Int($0) } ?? 2021
27+
let platforms: [SupportedPlatform] = switch releaseVersion {
28+
case 2023:
29+
[
30+
.iOS(.v17),
31+
.macOS(.v14),
32+
.macCatalyst(.v17),
33+
.tvOS(.v17),
34+
.watchOS(.v9),
35+
.visionOS(.v1),
36+
]
37+
case 2022:
38+
[
39+
.iOS(.v16),
40+
.macOS(.v13),
41+
.macCatalyst(.v16),
42+
.tvOS(.v16),
43+
.watchOS(.v8),
44+
]
45+
case 2021:
46+
[
47+
.iOS(.v15),
48+
.macOS(.v12),
49+
.macCatalyst(.v15),
50+
.tvOS(.v15),
51+
.watchOS(.v7),
52+
]
53+
default:
54+
[
55+
.iOS(.v13),
56+
.macOS(.v10_15),
57+
.macCatalyst(.v13),
58+
.tvOS(.v13),
59+
.watchOS(.v7), // WKApplicationMain is available for watchOS 7.0+
60+
.visionOS(.v1),
61+
]
62+
}
63+
2664
var sharedSwiftSettings: [SwiftSetting] = [
2765
.enableExperimentalFeature("AccessLevelOnImport"),
2866
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
67+
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
2968
]
3069

70+
switch releaseVersion {
71+
case 2023:
72+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2023_API"))
73+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
74+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
75+
case 2022:
76+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
77+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
78+
case 2021:
79+
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
80+
default:
81+
break
82+
}
83+
3184
let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv && development)
3285
if warningsAsErrorsCondition {
3386
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
@@ -78,14 +131,7 @@ let includePath = SDKPath.appending("/usr/lib/swift_static")
78131

79132
let package = Package(
80133
name: "OpenSwiftUI",
81-
platforms: [
82-
.iOS(.v13),
83-
.macOS(.v10_15),
84-
.macCatalyst(.v13),
85-
.tvOS(.v13),
86-
.watchOS(.v7), // WKApplicationMain is available for watchOS 7.0+
87-
.visionOS(.v1),
88-
],
134+
platforms: platforms,
89135
products: [
90136
.library(name: "OpenSwiftUI", targets: ["OpenSwiftUI", "OpenSwiftUIExtension"]),
91137
],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@frozen
2+
public struct ForegroundStyle: ShapeStyle {
3+
@inlinable
4+
public init() {}
5+
6+
public static func _makeView<S>(view: _GraphValue<_ShapeView<S, ForegroundStyle>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape {
7+
fatalError("TODO")
8+
}
9+
}
10+
11+
#if OPENSWIFTUI_SUPPORT_2021_API
12+
13+
extension ForegroundStyle {
14+
public func _apply(to shape: inout _ShapeStyle_Shape) {
15+
fatalError("TODO")
16+
}
17+
18+
public static func _apply(to type: inout _ShapeStyle_ShapeType) {
19+
fatalError("TODO")
20+
}
21+
}
22+
23+
extension ShapeStyle where Self == ForegroundStyle {
24+
@_alwaysEmitIntoClient
25+
public static var foreground: ForegroundStyle {
26+
.init()
27+
}
28+
}
29+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
3+
/// A rectangular shape aligned inside the frame of the view containing it.
4+
@frozen
5+
public struct Rectangle: Shape {
6+
public func path(in rect: CGRect) -> Path {
7+
fatalError("TODO")
8+
}
9+
10+
/// Creates a new rectangle shape.
11+
@inlinable
12+
public init() {}
13+
14+
public typealias AnimatableData = EmptyAnimatableData
15+
16+
public typealias Body = _ShapeView<Rectangle, ForegroundStyle>
17+
}
18+
19+
20+
extension Shape where Self == Rectangle {
21+
/// A rectangular shape aligned inside the frame of the view containing it.
22+
public static var rect: Rectangle {
23+
Rectangle()
24+
}
25+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// Shape.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: WIP
7+
8+
import Foundation
9+
10+
/// A 2D shape that you can use when drawing a view.
11+
///
12+
/// Shapes without an explicit fill or stroke get a default fill based on the
13+
/// foreground color.
14+
///
15+
/// You can define shapes in relation to an implicit frame of reference, such as
16+
/// the natural size of the view that contains it. Alternatively, you can define
17+
/// shapes in terms of absolute coordinates.
18+
public protocol Shape: Animatable, View {
19+
/// Describes this shape as a path within a rectangular frame of reference.
20+
///
21+
/// - Parameter rect: The frame of reference for describing this shape.
22+
///
23+
/// - Returns: A path that describes this shape.
24+
func path(in rect: CGRect) -> Path
25+
26+
#if OPENSWIFTUI_SUPPORT_2021_API
27+
/// An indication of how to style a shape.
28+
///
29+
/// OpenSwiftUI looks at a shape's role when deciding how to apply a
30+
/// ``ShapeStyle`` at render time. The ``Shape`` protocol provides a
31+
/// default implementation with a value of ``ShapeRole/fill``. If you
32+
/// create a composite shape, you can provide an override of this property
33+
/// to return another value, if appropriate.
34+
static var role: ShapeRole { get }
35+
#endif
36+
}
37+
38+
extension Shape {
39+
public var body: _ShapeView<Self, ForegroundStyle> {
40+
_ShapeView(shape: self, style: ForegroundStyle())
41+
}
42+
}
43+
44+
#if OPENSWIFTUI_SUPPORT_2021_API
45+
46+
extension Shape {
47+
public static var role: ShapeRole {
48+
.fill
49+
}
50+
}
51+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ShapeRole.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: Complete
7+
8+
#if OPENSWIFTUI_SUPPORT_2021_API
9+
10+
/// Ways of styling a shape.
11+
public enum ShapeRole: Sendable {
12+
/// Indicates to the shape's style that SwiftUI fills the shape.
13+
case fill
14+
15+
/// Indicates to the shape's style that SwiftUI applies a stroke to
16+
/// the shape's path.
17+
case stroke
18+
19+
/// Indicates to the shape's style that SwiftUI uses the shape as a
20+
/// separator.
21+
case separator
22+
}
23+
24+
extension ShapeRole: Equatable {}
25+
extension ShapeRole: Hashable {}
26+
27+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
public protocol ShapeStyle {
2+
@available(*, deprecated, message: "obsolete")
3+
static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S : Shape
4+
5+
#if OPENSWIFTUI_SUPPORT_2021_API
6+
func _apply(to shape: inout _ShapeStyle_Shape)
7+
8+
static func _apply(to type: inout _ShapeStyle_ShapeType)
9+
#endif
10+
}
11+
12+
13+
#if OPENSWIFTUI_SUPPORT_2021_API
14+
15+
public struct _ShapeStyle_Shape {
16+
// TODO
17+
}
18+
19+
public struct _ShapeStyle_ShapeType {
20+
// TODO
21+
}
22+
23+
extension ShapeStyle {
24+
public static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape {
25+
fatalError("TODO")
26+
}
27+
28+
public func _apply(to shape: inout _ShapeStyle_Shape) {
29+
fatalError("TODO")
30+
}
31+
32+
public static func _apply(to type: inout _ShapeStyle_ShapeType) {
33+
fatalError("TODO")
34+
}
35+
}
36+
37+
38+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@frozen
2+
public struct _ShapeView<Content, Style>: PrimitiveView where Content : Shape, Style: ShapeStyle {
3+
public var shape: Content
4+
public var style: Style
5+
public var fillStyle: FillStyle
6+
7+
@inlinable
8+
public init(shape: Content, style: Style, fillStyle: FillStyle = FillStyle()) {
9+
self.shape = shape
10+
self.style = style
11+
self.fillStyle = fillStyle
12+
}
13+
14+
15+
public static func _makeView(view: _GraphValue<_ShapeView<Content, Style>>, inputs: _ViewInputs) -> _ViewOutputs {
16+
fatalError("TODO")
17+
}
18+
19+
public typealias Body = Never
20+
}

0 commit comments

Comments
 (0)