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

Fixes for LVN Core API changes #22

Merged
merged 14 commits into from
Dec 26, 2024
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ permissions:

jobs:
test:
runs-on: macos-14
runs-on: macos-15
steps:
- uses: actions/checkout@v2
- name: Setup Xcode Version
shell: bash
run: |
sudo xcode-select --switch /Applications/Xcode_15.4.app
sudo xcode-select --switch /Applications/Xcode_16.2.app
- uses: irgaly/xcode-cache@v1
with:
key: xcode-cache-deriveddata-${{ github.workflow }}
restore-keys: xcode-cache-deriveddata-${{ github.workflow }}-
- name: Build for iOS
shell: bash
run: |
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=iOS Simulator,name=iPhone 15 Pro" -skipMacroValidation -skipPackagePluginValidation
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=iOS Simulator,name=iPhone 16 Pro" -skipMacroValidation -skipPackagePluginValidation
- name: Build for macOS
shell: bash
run: |
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=macOS" -skipMacroValidation -skipPackagePluginValidation
- name: Build for watchOS
shell: bash
run: |
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=watchOS Simulator,name=Apple Watch Series 9 (45mm)" -skipMacroValidation -skipPackagePluginValidation
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=watchOS Simulator,name=Apple Watch Series 10 (46mm)" -skipMacroValidation -skipPackagePluginValidation
- name: Build for tvOS
shell: bash
run: |
xcodebuild -scheme LiveViewNativeLiveForm -destination "name=Any tvOS Device" -skipMacroValidation -skipPackagePluginValidation
xcodebuild -scheme LiveViewNativeLiveForm -destination "platform=tvOS Simulator,name=Apple TV" -skipMacroValidation -skipPackagePluginValidation
86 changes: 86 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"pins" : [
{
"identity" : "liveview-client-swiftui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/liveview-native/liveview-client-swiftui.git",
"state" : {
"revision" : "94676fce9fdfabc6b24fdf942ef874cdaac8ed5e",
"version" : "0.4.0-rc.0"
}
},
{
"identity" : "liveview-native-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/liveview-native/liveview-native-core",
"state" : {
"revision" : "369503f39d7f257ac3361a1b7104ab14015c721c",
"version" : "0.4.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms",
"state" : {
"revision" : "4c3ea81f81f0a25d0470188459c6d4bf20cf2f97",
"version" : "1.0.3"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "bc92c4b27f9a84bfb498cdbfdf35d5a357e9161f",
"version" : "1.5.6"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
"identity" : "swift-parsing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-parsing",
"state" : {
"revision" : "a0e7d73f462c1c38c59dc40a3969ac40cea42950",
"version" : "0.13.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "a3f634d1a409c7979cabc0a71b3f26ffa9fc8af1",
"version" : "1.4.3"
}
}
],
"version" : 2
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -18,7 +18,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/liveview-native/liveview-client-swiftui.git", from: "0.4.0-rc.0"),
.package(url: "https://github.com/liveview-native/liveview-client-swiftui.git", from: "0.4.0-rc.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
50 changes: 50 additions & 0 deletions swiftui/Sources/LiveViewNativeLiveForm/LiveButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// LiveSubmitButton.swift
// LiveViewNativeLiveForm
//
// Created by Shadowfacts on 2/27/23.
//

import SwiftUI
@_spi(LiveForm) import LiveViewNative

/// A button that submits a live form.
///
/// Use the same customization options as ``LiveViewNative.Button``.
///
/// ## Attributes
/// - `after-submit`: An action to perform after the form is submitted. Supported actions:
/// - `clear`: clears all values from the form
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
@LiveElement
struct LiveButton<Root: RootRegistry>: View {
@LiveElementIgnored
@Environment(\.formModel)
private var formModel

private var type: String = "button"

@LiveElementIgnored
private var overrideType: String? = nil

init(type: String? = nil) {
self.overrideType = type
}

public var body: some View {
switch overrideType ?? type {
case "submit":
LiveViewNative.Button<Root>(action: {
Task { try await formModel?.sendSubmitEvent() }
})
case "reset":
LiveViewNative.Button<Root>(action: {
formModel?.clear()
})
default:
LiveViewNative.Button<Root>()
}
}
}
7 changes: 4 additions & 3 deletions swiftui/Sources/LiveViewNativeLiveForm/LiveForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ struct LiveForm<Root: RootRegistry>: View {
await $liveElement.context.coordinator.session.reconnect(
url: url,
httpMethod: method,
httpBody: body.data(using: .utf8)
httpBody: body.data(using: .utf8),
headers: ["Content-Type": "application/x-www-form-urlencoded"]
)
}
}

/// Collects all ``LiveHiddenField`` elements, and sets their values into the form model.
private func updateHiddenFields() {
for child in $liveElement.element.depthFirstChildren() {
guard case let .element(element) = child.data,
element.tag == "LiveHiddenField",
guard case let .nodeElement(element) = child.data(),
element.name.name == "LiveHiddenField",
let name = element.attributes.first(where: { $0.name == "name" })?.value,
let value = element.attributes.first(where: { $0.name == "value" })?.value
else { continue }
Expand Down
12 changes: 10 additions & 2 deletions swiftui/Sources/LiveViewNativeLiveForm/LiveFormRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import LiveViewNative
import LiveViewNativeStylesheet
import SwiftUI
import OSLog

let logger = Logger(subsystem: "LiveViewNative", category: "LiveForm")

public extension Addons {
/// This registry provides the Live Form elements.
Expand All @@ -24,20 +27,25 @@ public extension Addons {
/// )
/// ```
@Addon
public struct LiveForm<Root: RootRegistry> {
struct LiveForm<Root: RootRegistry> {
public enum TagName: String {
case liveForm = "LiveForm"
case liveButton = "LiveButton"
case liveSubmitButton = "LiveSubmitButton"
case liveHiddenField = "LiveHiddenField"
}

@ViewBuilder
@MainActor
public static func lookup(_ name: TagName, element: ElementNode) -> some View {
switch name {
case .liveForm:
LiveViewNativeLiveForm.LiveForm<Root>()
case .liveButton:
LiveButton<Root>()
case .liveSubmitButton:
LiveSubmitButton<Root>()
let _ = logger.warning("`<LiveSubmitButton>` is deprecated. Use `<LiveButton type=\"submit\">` instead.")
LiveButton<Root>(type: "submit")
case .liveHiddenField:
LiveHiddenField()
}
Expand Down
50 changes: 0 additions & 50 deletions swiftui/Sources/LiveViewNativeLiveForm/LiveSubmitButton.swift

This file was deleted.

Loading