Skip to content

Commit 8db6e44

Browse files
authored
Merge pull request #151 from liveviewnative/macos
Fix macOS build
2 parents a2a18c2 + 5124af6 commit 8db6e44

File tree

12 files changed

+112
-58
lines changed

12 files changed

+112
-58
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ jobs:
1414
shell: bash
1515
run: |
1616
sudo xcode-select --switch /Applications/Xcode_14.2.app
17-
xcodebuild test -scheme LiveViewNative -sdk iphonesimulator16.2 -destination "OS=16.2,name=iPhone 14 Pro"
17+
xcodebuild test -scheme LiveViewNative -sdk iphonesimulator16.2 -destination "OS=16.2,name=iPhone 14 Pro"
18+
- name: Build for macOS
19+
shell: bash
20+
run: |
21+
xcodebuild -scheme LiveViewNative -sdk macosx13.1 -destination "platform=macOS"
22+
- name: Build for watchOS
23+
shell: bash
24+
run: |
25+
xcodebuild -scheme LiveViewNative -sdk watchsimulator9.1 -destination "OS=9.1,name=Apple Watch Series 8 (45mm)"

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import PackageDescription
66
let package = Package(
77
name: "LiveViewNative",
88
platforms: [
9-
.iOS("16.0")
9+
.iOS("16.0"),
10+
.macOS("13.0"),
11+
.watchOS("9.0"),
1012
],
1113
products: [
1214
// Products define the executables and libraries a package produces, and make them visible to other packages.
@@ -32,7 +34,8 @@ let package = Package(
3234
]),
3335
.testTarget(
3436
name: "LiveViewNativeTests",
35-
dependencies: ["LiveViewNative"]),
37+
dependencies: ["LiveViewNative"]
38+
),
3639
.testTarget(
3740
name: "RenderingTests",
3841
dependencies: ["LiveViewNative"]

Sources/LiveViewNative/BuiltinRegistry.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ struct BuiltinRegistry {
5858
ProgressView(element: element, context: context)
5959
case "divider":
6060
Divider()
61+
#if os(iOS)
6162
case "edit-button":
6263
EditButton()
64+
#endif
6365
case "toggle":
6466
Toggle(element: element, context: context)
67+
#if !os(watchOS)
6568
case "menu":
6669
Menu(element: element, context: context)
70+
#endif
6771
case "slider":
6872
Slider(element: element, context: context)
6973
case "phx-form":

Sources/LiveViewNative/Modifiers/ListRowSeparatorModifier.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ struct ListRowSeparatorModifier: ViewModifier, Decodable, Equatable {
5555
}
5656

5757
func body(content: Content) -> some View {
58+
#if !os(watchOS)
5859
content.listRowSeparator(visibility, edges: edges)
60+
#else
61+
content
62+
#endif
5963
}
6064

6165
private enum CodingKeys: String, CodingKey {

Sources/LiveViewNative/Views/Controls and Indicators/Menus/Menu.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by Carson Katri on 1/19/23.
66
//
7-
7+
#if !os(watchOS)
88
import SwiftUI
99

1010
struct Menu<R: CustomRegistry>: View {
@@ -43,3 +43,4 @@ fileprivate extension View {
4343
}
4444
}
4545
}
46+
#endif

Sources/LiveViewNative/Views/Layout Containers/Collection Containers/List.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ private extension SwiftUI.List {
4545
switch element.attributeValue(for: "style") {
4646
case nil, "plain":
4747
self.listStyle(.plain)
48+
#if os(iOS)
4849
case "grouped":
4950
self.listStyle(.grouped)
5051
case "inset-grouped":
5152
self.listStyle(.insetGrouped)
53+
#endif
5254
default:
5355
fatalError("Invalid list style '\(element.attributeValue(for: "name")!)'")
5456
}

Sources/LiveViewNative/Views/Text Input and Output/SecureField.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ struct SecureField<R: CustomRegistry>: TextFieldProtocol {
2626
.focused($isFocused)
2727
.applyTextFieldStyle(textFieldStyle)
2828
.applyAutocorrectionDisabled(disableAutocorrection)
29+
#if os(iOS) || os(tvOS)
2930
.textInputAutocapitalization(autocapitalization)
3031
.applyKeyboardType(keyboard)
32+
#endif
3133
.applySubmitLabel(submitLabel)
3234
.onChange(of: isFocused, perform: handleFocus)
3335
}

Sources/LiveViewNative/Views/Text Input and Output/TextField.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ struct TextField<R: CustomRegistry>: TextFieldProtocol {
2222
.focused($isFocused)
2323
.applyTextFieldStyle(textFieldStyle)
2424
.applyAutocorrectionDisabled(disableAutocorrection)
25+
#if !os(macOS)
2526
.textInputAutocapitalization(autocapitalization)
27+
#endif
28+
#if os(iOS) || os(tvOS)
2629
.applyKeyboardType(keyboard)
30+
#endif
2731
.applySubmitLabel(submitLabel)
2832
.onChange(of: isFocused, perform: handleFocus)
2933
}

Sources/LiveViewNative/Views/Text Input and Output/TextFieldProtocol.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ extension TextFieldProtocol {
9191
}
9292
}
9393

94+
#if !os(macOS)
9495
var autocapitalization: TextInputAutocapitalization? {
9596
switch element.attributeValue(for: "autocapitalization") {
9697
case "sentences":
@@ -105,7 +106,9 @@ extension TextFieldProtocol {
105106
return nil
106107
}
107108
}
109+
#endif
108110

111+
#if os(iOS) || os(tvOS)
109112
var keyboard: UIKeyboardType? {
110113
switch element.attributeValue(for: "keyboard") {
111114
case "ascii-capable":
@@ -134,6 +137,7 @@ extension TextFieldProtocol {
134137
return nil
135138
}
136139
}
140+
#endif
137141

138142
var submitLabel: SubmitLabel? {
139143
switch element.attributeValue(for: "submit-label") {
@@ -164,8 +168,12 @@ extension TextFieldProtocol {
164168
enum TextFieldStyle: String {
165169
case automatic
166170
case plain
171+
#if !os(watchOS)
167172
case roundedBorder = "rounded-border"
173+
#endif
174+
#if os(macOS)
168175
case squareBorder = "square-border"
176+
#endif
169177
}
170178

171179
extension View {
@@ -176,14 +184,14 @@ extension View {
176184
self.textFieldStyle(.automatic)
177185
case .plain:
178186
self.textFieldStyle(.plain)
187+
#if !os(watchOS)
179188
case .roundedBorder:
180189
self.textFieldStyle(.roundedBorder)
190+
#endif
191+
#if os(macOS)
181192
case .squareBorder:
182-
#if os(macOS)
183193
self.textFieldStyle(.squareBorder)
184-
#else
185-
self
186-
#endif
194+
#endif
187195
}
188196
}
189197

@@ -196,6 +204,7 @@ extension View {
196204
}
197205
}
198206

207+
#if os(iOS) || os(tvOS)
199208
@ViewBuilder
200209
func applyKeyboardType(_ keyboardType: UIKeyboardType?) -> some View {
201210
if let keyboardType {
@@ -204,6 +213,7 @@ extension View {
204213
self
205214
}
206215
}
216+
#endif
207217

208218
@ViewBuilder
209219
func applySubmitLabel(_ submitLabel: SubmitLabel?) -> some View {

0 commit comments

Comments
 (0)