~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

iOS: a list read again keeps each item's like and reveal with it

Open chadtmiller.com wants to merge into main from chadtmiller.com/hud:ios/remembered-state
ios/HUDKit/Sources/HUDKit/Parts/ActionButton.swift+2−1
@@ -95,7 +95,8 @@ struct ActionButton: View {
.accessibilityLabel(shown.map { "\(name), \(JSON.write($0))" } ?? name)
.accessibilityAddTraits(ran.done ? .isSelected : [])
.accessibilityHint(ran.made != nil ? "Tap to undo" : "")
.onAppear { ran = view.memory.get(key) { Ran(done: existing != nil, made: existing) } }
// Its place in a list holds another item once the list is read again.
.onChange(of: key, initial: true) { ran = view.memory.get(key) { Ran(done: existing != nil, made: existing) } }
.alert("This view isn't one of HUD's own", isPresented: Binding(get: { confirming != nil }, set: { if !$0 { confirming = nil } })) {
Button(label) {
if let call = confirming { send(.write(call)) }
ios/HUDKit/Sources/HUDKit/Parts/TextBody.swift+1−1
@@ -67,7 +67,7 @@ struct Clamped: View {
.foregroundStyle(.accent)
}
}
.onAppear { open = view.memory.get(key) { false } }
.onChange(of: key, initial: true) { open = view.memory.get(key) { false } }
}
}
ios/HUDKit/Sources/HUDKit/Tree/ResolvedBlocks.swift+2−2
@@ -96,7 +96,7 @@ struct ResolvedRichBlocks: View {
.foregroundStyle(.accent)
}
}
.onAppear { open = view.memory.get(key) { false } }
.onChange(of: key, initial: true) { open = view.memory.get(key) { false } }
} else {
content
}
@@ -393,7 +393,7 @@ private struct DetailsBlock: View {
ResolvedBlocks(blocks: block["blocks"]?.array ?? [], look: look)
}
}
.onAppear { open = view.memory.get(key) { block["expanded"] == .bool(true) } }
.onChange(of: key, initial: true) { open = view.memory.get(key) { block["expanded"] == .bool(true) } }
}
}
ios/HUDKit/Sources/HUDKit/Tree/ResolvedMedia.swift+29−25
@@ -284,35 +284,39 @@ struct ResolvedContentWarning: View {
@Environment(\.viewContext) private var view
@State private var revealed = false
private var key: String { "warning:\(node["p"]?["key"]?.string ?? "")" }
var body: some View {
let p = node["p"] ?? .object([:])
let labels = p["labels"]?.array?.compactMap(\.string) ?? []
let key = "warning:\(p["key"]?.string ?? "")"
if labels.isEmpty || revealed {
ResolvedChildren(node: node)
} else {
VStack(spacing: Space.s1) {
Text("Content warning")
.font(.subheadline.weight(.semibold))
.foregroundStyle(HUDColor(.onNotice, or: .orange))
Text(labels.joined(separator: ", "))
.font(.footnote)
.multilineTextAlignment(.center)
Button("Show") {
revealed = true
view.memory.set(key, true)
let labels = node["p"]?["labels"]?.array?.compactMap(\.string) ?? []
Group {
if labels.isEmpty || revealed {
ResolvedChildren(node: node)
} else {
VStack(spacing: Space.s1) {
Text("Content warning")
.font(.subheadline.weight(.semibold))
.foregroundStyle(HUDColor(.onNotice, or: .orange))
Text(labels.joined(separator: ", "))
.font(.footnote)
.multilineTextAlignment(.center)
Button("Show") {
revealed = true
view.memory.set(key, true)
}
.buttonStyle(.bordered)
.tint(HUDColor.accent)
.padding(.top, Space.s2)
}
.buttonStyle(.bordered)
.tint(HUDColor.accent)
.padding(.top, Space.s2)
.frame(maxWidth: .infinity)
.padding(.vertical, Space.s5)
.padding(.horizontal, Space.s4)
.background(HUDColor(.notice, or: Color.orange.opacity(0.12)), in: .rect(cornerRadius: 12, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(HUDColor(.border, or: Color.orange.opacity(0.4))))
}
.frame(maxWidth: .infinity)
.padding(.vertical, Space.s5)
.padding(.horizontal, Space.s4)
.background(HUDColor(.notice, or: Color.orange.opacity(0.12)), in: .rect(cornerRadius: 12, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(HUDColor(.border, or: Color.orange.opacity(0.4))))
.onAppear { revealed = view.memory.get(key) { false } }
}
// Revealed, it is kept so; another item's warning in its place (the
// list read again) is hidden until that one is revealed.
.onChange(of: key, initial: true) { revealed = view.memory.get(key) { false } }
}
}