Skip to content

Fix macOS build #151

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

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import PackageDescription
let package = Package(
name: "LiveViewNative",
platforms: [
.iOS("16.0")
.iOS("16.0"),
.macOS("13.0"),
.watchOS("9.0"),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveViewNative/BuiltinRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ struct BuiltinRegistry {
ProgressView(element: element, context: context)
case "divider":
Divider()
#if os(iOS)
case "edit-button":
EditButton()
#endif
case "toggle":
Toggle(element: element, context: context)
#if !os(watchOS)
case "menu":
Menu(element: element, context: context)
#endif
case "slider":
Slider(element: element, context: context)
case "phx-form":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ struct ListRowSeparatorModifier: ViewModifier, Decodable, Equatable {
}

func body(content: Content) -> some View {
#if !os(watchOS)
content.listRowSeparator(visibility, edges: edges)
#else
content
#endif
}

private enum CodingKeys: String, CodingKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Carson Katri on 1/19/23.
//

#if !os(watchOS)
import SwiftUI

struct Menu<R: CustomRegistry>: View {
Expand Down Expand Up @@ -43,3 +43,4 @@ fileprivate extension View {
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ private extension SwiftUI.List {
switch element.attributeValue(for: "style") {
case nil, "plain":
self.listStyle(.plain)
#if os(iOS)
case "grouped":
self.listStyle(.grouped)
case "inset-grouped":
self.listStyle(.insetGrouped)
#endif
default:
fatalError("Invalid list style '\(element.attributeValue(for: "name")!)'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ struct SecureField<R: CustomRegistry>: TextFieldProtocol {
.focused($isFocused)
.applyTextFieldStyle(textFieldStyle)
.applyAutocorrectionDisabled(disableAutocorrection)
#if os(iOS) || os(tvOS)
.textInputAutocapitalization(autocapitalization)
.applyKeyboardType(keyboard)
#endif
.applySubmitLabel(submitLabel)
.onChange(of: isFocused, perform: handleFocus)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ struct TextField<R: CustomRegistry>: TextFieldProtocol {
.focused($isFocused)
.applyTextFieldStyle(textFieldStyle)
.applyAutocorrectionDisabled(disableAutocorrection)
#if !os(macOS)
.textInputAutocapitalization(autocapitalization)
#endif
#if os(iOS) || os(tvOS)
.applyKeyboardType(keyboard)
#endif
.applySubmitLabel(submitLabel)
.onChange(of: isFocused, perform: handleFocus)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extension TextFieldProtocol {
}
}

#if !os(macOS)
var autocapitalization: TextInputAutocapitalization? {
switch element.attributeValue(for: "autocapitalization") {
case "sentences":
Expand All @@ -105,7 +106,9 @@ extension TextFieldProtocol {
return nil
}
}
#endif

#if os(iOS) || os(tvOS)
var keyboard: UIKeyboardType? {
switch element.attributeValue(for: "keyboard") {
case "ascii-capable":
Expand Down Expand Up @@ -134,6 +137,7 @@ extension TextFieldProtocol {
return nil
}
}
#endif

var submitLabel: SubmitLabel? {
switch element.attributeValue(for: "submit-label") {
Expand Down Expand Up @@ -164,8 +168,12 @@ extension TextFieldProtocol {
enum TextFieldStyle: String {
case automatic
case plain
#if !os(watchOS)
case roundedBorder = "rounded-border"
#endif
#if os(macOS)
case squareBorder = "square-border"
#endif
}

extension View {
Expand All @@ -176,14 +184,14 @@ extension View {
self.textFieldStyle(.automatic)
case .plain:
self.textFieldStyle(.plain)
#if !os(watchOS)
case .roundedBorder:
self.textFieldStyle(.roundedBorder)
#endif
#if os(macOS)
case .squareBorder:
#if os(macOS)
self.textFieldStyle(.squareBorder)
#else
self
#endif
#endif
}
}

Expand All @@ -196,6 +204,7 @@ extension View {
}
}

#if os(iOS) || os(tvOS)
@ViewBuilder
func applyKeyboardType(_ keyboardType: UIKeyboardType?) -> some View {
if let keyboardType {
Expand All @@ -204,6 +213,7 @@ extension View {
self
}
}
#endif

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