Skip to content

Commit 3b94874

Browse files
committed
2.9.0
1 parent f5cd5a7 commit 3b94874

12 files changed

Lines changed: 1019 additions & 140 deletions

File tree

.github/workflows/swift.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
- name: Build for visionOS
3434
run: xcodebuild -scheme Engine -destination 'generic/platform=visionOS Simulator' build
3535
- name: Test for macOS
36-
run: xcodebuild -scheme EngineTests -destination 'platform=macOS' test
36+
run: xcodebuild -scheme Engine-Package -destination 'platform=macOS' -skip-testing EngineTestsBenchmarks test
3737
- name: Test for iOS
38-
run: xcodebuild -scheme EngineTests -destination 'platform=iOS Simulator,name=iPhone 16' test
38+
run: xcodebuild -scheme Engine-Package -destination 'platform=iOS Simulator,name=iPhone 16' -skip-testing EngineTestsBenchmarks test
3939
build-26:
4040
runs-on: macos-latest
4141
steps:
@@ -59,6 +59,6 @@ jobs:
5959
- name: Build for visionOS
6060
run: xcodebuild -scheme Engine -destination 'generic/platform=visionOS Simulator' build
6161
- name: Test for macOS
62-
run: xcodebuild -scheme EngineTests -destination 'platform=macOS' test
62+
run: xcodebuild -scheme Engine-Package -destination 'platform=macOS' -skip-testing EngineTestsBenchmarks test
6363
- name: Test for iOS
64-
run: xcodebuild -scheme EngineTests -destination 'platform=iOS Simulator,name=iPhone 17' test
64+
run: xcodebuild -scheme Engine-Package -destination 'platform=iOS Simulator,name=iPhone 17' -skip-testing EngineTestsBenchmarks test

Sources/Engine/Sources/IsNilTransform.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Sources/Engine/Sources/IsNotNilTransform.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Sources/Engine/Sources/Optional+Extensions.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ extension Optional {
3030
}
3131
}
3232

33+
extension Optional where Wrapped == String {
34+
35+
@usableFromInline
36+
var value: String {
37+
get {
38+
switch self {
39+
case .none:
40+
return ""
41+
case .some(let wrapped):
42+
return wrapped
43+
}
44+
}
45+
set {
46+
self = newValue.isEmpty ? .none : .some(newValue)
47+
}
48+
}
49+
}
50+
3351
extension Hashable {
3452

3553
@usableFromInline
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// Copyright (c) Nathan Tannar
3+
//
4+
5+
import SwiftUI
6+
7+
extension Binding {
8+
9+
/// A ``BindingTransform`` that transforms the value to `true` when `nil`
10+
@inlinable
11+
public func isNil<Wrapped>() -> Binding<Bool> where Optional<Wrapped> == Value {
12+
self[keyPath: \.isNone]
13+
}
14+
15+
/// A ``BindingTransform`` that transforms the value to `true` when `.some`
16+
@inlinable
17+
public func isNotNil<Wrapped>() -> Binding<Bool> where Optional<Wrapped> == Value {
18+
self[keyPath: \.isNotNone]
19+
}
20+
}
21+
22+
extension Binding where Value == Optional<String> {
23+
24+
/// A ``BindingTransform`` that transforms a `nil` `String` to an empty string, and an empty `String` to `nil`
25+
@inlinable
26+
public func value() -> Binding<String> {
27+
self[keyPath: \.value]
28+
}
29+
}
30+
31+
// MARK: - Previews
32+
33+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
34+
struct OptionalTransform_Previews: PreviewProvider {
35+
static var previews: some View {
36+
IsNilPreview()
37+
IsNotNilPreview()
38+
}
39+
40+
struct IsNilPreview: View {
41+
@State var value: String?
42+
@State var update = 0
43+
44+
var body: some View {
45+
VStack {
46+
ToggleView(isNil: $value.isNil())
47+
48+
if let value {
49+
Text(value)
50+
}
51+
52+
Button {
53+
value = "Hello, World"
54+
} label: {
55+
Text("Add Text")
56+
}
57+
58+
Button {
59+
update += 1
60+
} label: {
61+
Text("Render Update \(update)")
62+
}
63+
}
64+
}
65+
66+
struct ToggleView: View {
67+
@Binding var isNil: Bool
68+
var body: some View {
69+
Self._printChanges()
70+
return Toggle(isOn: $isNil) { EmptyView() }
71+
.labelsHidden()
72+
}
73+
}
74+
}
75+
76+
struct IsNotNilPreview: View {
77+
@State var value: String?
78+
@State var update = 0
79+
80+
var body: some View {
81+
VStack {
82+
ToggleView(isNotNil: $value.isNotNil())
83+
84+
if let value {
85+
Text(value)
86+
}
87+
88+
Button {
89+
value = "Hello, World"
90+
} label: {
91+
Text("Add Text")
92+
}
93+
94+
Button {
95+
update += 1
96+
} label: {
97+
Text("Render Update \(update)")
98+
}
99+
}
100+
}
101+
102+
struct ToggleView: View {
103+
@Binding var isNotNil: Bool
104+
var body: some View {
105+
Self._printChanges()
106+
return Toggle(isOn: $isNotNil) { EmptyView() }
107+
.labelsHidden()
108+
}
109+
}
110+
}
111+
}

Sources/Engine/Sources/UnevenRectangle.swift renamed to Sources/Engine/Sources/RoundedCornersRectangle.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import SwiftUI
1010
@available(tvOS, introduced: 13.0, deprecated: 100000.0, message: "Please use the built in UnevenRoundedRectangle")
1111
@available(watchOS, introduced: 6.0, deprecated: 100000.0, message: "Please use the built in UnevenRoundedRectangle")
1212
@available(visionOS, introduced: 1.0, deprecated: 100000.0, message: "Please use the built in UnevenRoundedRectangle")
13-
public struct UnevenRoundedRectangle: Shape {
13+
public struct RoundedCornersRectangle: Shape {
1414

1515
public var topLeadingRadius: CGFloat
1616
public var bottomLeadingRadius: CGFloat
1717
public var topTrailingRadius: CGFloat
1818
public var bottomTrailingRadius: CGFloat
1919
public var style: RoundedCornerStyle
2020

21-
@_disfavoredOverload
2221
@inlinable
2322
public init(
2423
topLeadingRadius: CGFloat = 0,
@@ -92,15 +91,15 @@ public struct UnevenRoundedRectangle: Shape {
9291

9392
// MARK: - Previews
9493

95-
struct UnevenRoundedRectangle_Previews: PreviewProvider {
94+
struct RoundedCornersRectangle_Previews: PreviewProvider {
9695
static var previews: some View {
9796
VStack {
98-
UnevenRoundedRectangle(topLeadingRadius: 12, bottomLeadingRadius: 0, bottomTrailingRadius: 12, topTrailingRadius: 0)
97+
RoundedCornersRectangle(topLeadingRadius: 12, bottomLeadingRadius: 0, bottomTrailingRadius: 12, topTrailingRadius: 0)
9998
.fill(Color.blue)
10099
.frame(height: 50)
101100

102101
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
103-
SwiftUI.UnevenRoundedRectangle(topLeadingRadius: 12, bottomLeadingRadius: 0, bottomTrailingRadius: 12, topTrailingRadius: 0)
102+
UnevenRoundedRectangle(topLeadingRadius: 12, bottomLeadingRadius: 0, bottomTrailingRadius: 12, topTrailingRadius: 0)
104103
.fill(Color.blue)
105104
.frame(height: 50)
106105
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Copyright (c) Nathan Tannar
3+
//
4+
5+
import Foundation
6+
7+
@attached(member, names: arbitrary)
8+
public macro EnumKeyPaths() = #externalMacro(module: "EngineMacrosCore", type: "EnumKeyPathMacro")

Sources/EngineMacrosCore/EngineMacrosCore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SwiftSyntaxMacros
88
@main
99
struct EngineMacrosCore: CompilerPlugin {
1010
let providingMacros: [Macro.Type] = [
11-
StyledViewMacro.self
11+
StyledViewMacro.self,
12+
EnumKeyPathsMacro.self,
1213
]
1314
}

0 commit comments

Comments
 (0)