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

Add OPENSWIFTUI_TARGET_RELEASE support #97

Merged
merged 2 commits into from
Jun 27, 2024
Merged
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
62 changes: 54 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,64 @@ let development = envEnable("OPENSWIFTUI_DEVELOPMENT", default: false)
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"

let releaseVersion = Context.environment["OPENSWIFTUI_TARGET_RELEASE"].flatMap { Int($0) } ?? 2021
let platforms: [SupportedPlatform] = switch releaseVersion {
case 2023:
[
.iOS(.v17),
.macOS(.v14),
.macCatalyst(.v17),
.tvOS(.v17),
.watchOS(.v9),
.visionOS(.v1),
]
case 2022:
[
.iOS(.v16),
.macOS(.v13),
.macCatalyst(.v16),
.tvOS(.v16),
.watchOS(.v8),
]
case 2021:
[
.iOS(.v15),
.macOS(.v12),
.macCatalyst(.v15),
.tvOS(.v15),
.watchOS(.v7),
]
default:
[
.iOS(.v13),
.macOS(.v10_15),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v7), // WKApplicationMain is available for watchOS 7.0+
.visionOS(.v1),
]
}

var sharedSwiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
]

switch releaseVersion {
case 2023:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2023_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
case 2022:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
case 2021:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
default:
break
}

let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv && development)
if warningsAsErrorsCondition {
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
Expand Down Expand Up @@ -78,14 +131,7 @@ let includePath = SDKPath.appending("/usr/lib/swift_static")

let package = Package(
name: "OpenSwiftUI",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v7), // WKApplicationMain is available for watchOS 7.0+
.visionOS(.v1),
],
platforms: platforms,
products: [
.library(name: "OpenSwiftUI", targets: ["OpenSwiftUI", "OpenSwiftUIExtension"]),
],
Expand Down
29 changes: 29 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/ForegroundStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@frozen
public struct ForegroundStyle: ShapeStyle {
@inlinable
public init() {}

public static func _makeView<S>(view: _GraphValue<_ShapeView<S, ForegroundStyle>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape {
fatalError("TODO")
}
}

#if OPENSWIFTUI_SUPPORT_2021_API

extension ForegroundStyle {
public func _apply(to shape: inout _ShapeStyle_Shape) {
fatalError("TODO")
}

public static func _apply(to type: inout _ShapeStyle_ShapeType) {
fatalError("TODO")
}
}

extension ShapeStyle where Self == ForegroundStyle {
@_alwaysEmitIntoClient
public static var foreground: ForegroundStyle {
.init()
}
}
#endif
25 changes: 25 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/Rectangle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

/// A rectangular shape aligned inside the frame of the view containing it.
@frozen
public struct Rectangle: Shape {
public func path(in rect: CGRect) -> Path {
fatalError("TODO")
}

/// Creates a new rectangle shape.
@inlinable
public init() {}

public typealias AnimatableData = EmptyAnimatableData

public typealias Body = _ShapeView<Rectangle, ForegroundStyle>
}


extension Shape where Self == Rectangle {
/// A rectangular shape aligned inside the frame of the view containing it.
public static var rect: Rectangle {
Rectangle()
}
}
51 changes: 51 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/Shape.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Shape.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

import Foundation

/// A 2D shape that you can use when drawing a view.
///
/// Shapes without an explicit fill or stroke get a default fill based on the
/// foreground color.
///
/// You can define shapes in relation to an implicit frame of reference, such as
/// the natural size of the view that contains it. Alternatively, you can define
/// shapes in terms of absolute coordinates.
public protocol Shape: Animatable, View {
/// Describes this shape as a path within a rectangular frame of reference.
///
/// - Parameter rect: The frame of reference for describing this shape.
///
/// - Returns: A path that describes this shape.
func path(in rect: CGRect) -> Path

#if OPENSWIFTUI_SUPPORT_2021_API
/// An indication of how to style a shape.
///
/// OpenSwiftUI looks at a shape's role when deciding how to apply a
/// ``ShapeStyle`` at render time. The ``Shape`` protocol provides a
/// default implementation with a value of ``ShapeRole/fill``. If you
/// create a composite shape, you can provide an override of this property
/// to return another value, if appropriate.
static var role: ShapeRole { get }
#endif
}

extension Shape {
public var body: _ShapeView<Self, ForegroundStyle> {
_ShapeView(shape: self, style: ForegroundStyle())
}
}

#if OPENSWIFTUI_SUPPORT_2021_API

extension Shape {
public static var role: ShapeRole {
.fill
}
}
#endif
27 changes: 27 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/ShapeRole.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ShapeRole.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: Complete

#if OPENSWIFTUI_SUPPORT_2021_API

/// Ways of styling a shape.
public enum ShapeRole: Sendable {
/// Indicates to the shape's style that SwiftUI fills the shape.
case fill

/// Indicates to the shape's style that SwiftUI applies a stroke to
/// the shape's path.
case stroke

/// Indicates to the shape's style that SwiftUI uses the shape as a
/// separator.
case separator
}

extension ShapeRole: Equatable {}
extension ShapeRole: Hashable {}

#endif
38 changes: 38 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/ShapeStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public protocol ShapeStyle {
@available(*, deprecated, message: "obsolete")
static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S : Shape

#if OPENSWIFTUI_SUPPORT_2021_API
func _apply(to shape: inout _ShapeStyle_Shape)

static func _apply(to type: inout _ShapeStyle_ShapeType)
#endif
}


#if OPENSWIFTUI_SUPPORT_2021_API

public struct _ShapeStyle_Shape {
// TODO
}

public struct _ShapeStyle_ShapeType {
// TODO
}

extension ShapeStyle {
public static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape {
fatalError("TODO")
}

public func _apply(to shape: inout _ShapeStyle_Shape) {
fatalError("TODO")
}

public static func _apply(to type: inout _ShapeStyle_ShapeType) {
fatalError("TODO")
}
}


#endif
20 changes: 20 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/ShapeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@frozen
public struct _ShapeView<Content, Style>: PrimitiveView where Content : Shape, Style: ShapeStyle {
public var shape: Content
public var style: Style
public var fillStyle: FillStyle

@inlinable
public init(shape: Content, style: Style, fillStyle: FillStyle = FillStyle()) {
self.shape = shape
self.style = style
self.fillStyle = fillStyle
}


public static func _makeView(view: _GraphValue<_ShapeView<Content, Style>>, inputs: _ViewInputs) -> _ViewOutputs {
fatalError("TODO")
}

public typealias Body = Never
}
Loading