Files
punktfunk/clients/apple/Sources/PunktfunkClient/AddHostSheet.swift
T
enricobuehler 9e57a5a1ff
ci / rust (push) Has been cancelled
fix(apple/tvOS): native form controls — pushed pickers, single-pill fields, centered values
The inline iOS form widgets fought the tvOS focus system at every turn: focused fields
showed nested pills, rows darkened oddly and grew on activation, the Compositor picker
was not even focusable, and prefilled fields (port, client name) floated their label
inside the pill, shoving the value off-center.

- Settings is now a fully tv-native screen: NO inline text entry — the stream mode is
  a preset picker (This TV native / 720p / 1080p / 4K, plus a Custom entry preserving
  a mode set on another platform) and both pickers use .navigationLink style (pushed
  selection lists, exactly like the system Settings app — and properly focusable; the
  cover wraps in a NavigationStack for the pushes).
- Where text entry is unavoidable (Add Host, PIN pairing), the fields keep their stock
  single-pill chrome (the grouped form style stays off tvOS — its row platters were
  one of the nested pills) and prefilled fields hide their floating label so values
  center vertically.
- All earlier row-clearing experiments reverted.

Verified by screenshot in the Apple TV simulator: Settings rows render as single
focus lozenges with chevrons; the Add Host pills are uniform with centered text.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 13:38:37 +02:00

60 lines
2.1 KiB
Swift

// "+" sheet: name (optional) + address + port a card in the hosts grid. The first
// actual connection runs the trust-on-first-use fingerprint prompt.
import SwiftUI
struct AddHostSheet: View {
@Environment(\.dismiss) private var dismiss
@State private var name = ""
@State private var address = ""
@State private var port = 9777
let onAdd: (StoredHost) -> Void
var body: some View {
VStack(spacing: 0) {
Form {
TextField("Name", text: $name, prompt: Text("Optional — e.g. Living Room"))
TextField("Address", text: $address, prompt: Text("IP or hostname"))
TextField("Port", value: $port, format: .number.grouping(.never))
#if os(tvOS)
// tvOS floats the label above a non-empty field INSIDE the pill,
// shoving the value off-center the field is always prefilled
// here, so drop the label there.
.labelsHidden()
#endif
}
#if !os(tvOS)
.formStyle(.grouped)
#endif
HStack {
Button("Cancel", role: .cancel) { dismiss() }
#if !os(tvOS)
.keyboardShortcut(.cancelAction)
#endif
Spacer()
Button("Add Host") {
onAdd(StoredHost(
name: name.trimmingCharacters(in: .whitespaces),
address: address.trimmingCharacters(in: .whitespaces),
port: UInt16(clamping: port)))
dismiss()
}
.buttonStyle(.borderedProminent)
#if !os(tvOS)
.keyboardShortcut(.defaultAction)
#endif
.disabled(address.trimmingCharacters(in: .whitespaces).isEmpty)
}
#if os(iOS)
.controlSize(.large)
#endif
.padding(16)
}
#if os(macOS)
.frame(width: 380)
.fixedSize(horizontal: false, vertical: true)
#endif
}
}