0
2
next: More galleries from draws three across, without the gallery itself
Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.
next/views/grain-gallery-view.json+10−2
| @@ -54,7 +54,7 @@ | ||
"actor": { | ||
"$": "response.gallery.creator.did" | ||
}, | ||
"limit": 6 | ||
"limit": 7 | ||
} | ||
} | ||
], | ||
| @@ -916,7 +916,7 @@ | ||
"component": "Stack", | ||
"props": { | ||
"gap": "sm", | ||
"when": "joins.more.items" | ||
"when": "joins.more.items.1" | ||
}, | ||
"children": [ | ||
{ | ||
| @@ -933,6 +933,14 @@ | ||
"component": "Covers", | ||
"props": { | ||
"style": "tiles", | ||
"min": "sm", | ||
"columns": 3, | ||
"where": { | ||
"uri": { | ||
"$not": "response.gallery.uri" | ||
} | ||
}, | ||
"limit": 6, | ||
"items": { | ||
"$": "joins.more.items" | ||
}, | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Data/Result.swift+20−10
| @@ -117,17 +117,27 @@ public enum Drawn: Sendable { | ||
return ui["root"]?["c"]?.string == "Messages" | ||
} | ||
| ||
/// Whether what its tree draws first is a picture, gallery or map that | ||
/// bleeds (a place's map at the head of its feed): the app's screen then | ||
/// keeps no padding over it, so it meets the bar above, as the web does. | ||
public var leadsWithBleed: Bool { | ||
guard case .tree(let ui) = self else { return false } | ||
var node = ui["root"] | ||
while node?["c"]?.string == "Stack" { | ||
node = node?["k"]?.array?.first | ||
/// Whether what its tree draws first under a screen's navigation bar, | ||
/// its `Bar` lifted into that, is what bleeds: a picture, gallery or map | ||
/// with `bleed` (a place's map at the head of its feed), or tiles with no | ||
/// Select over them (a camera's feed). The app's screen then keeps no | ||
/// padding over it, so it meets the bar above, as the web does. | ||
public var leadsWithBleed: Bool { leads(lifted: true) } | ||
| ||
/// The same in a tile, which draws its `Bar` in its place. | ||
public var leadsTileWithBleed: Bool { leads(lifted: false) } | ||
| ||
private func leads(lifted: Bool) -> Bool { | ||
guard case .tree(let ui) = self, var node = ui["root"] else { return false } | ||
if lifted { node = ResolvedBar.lift(node).root } | ||
while node["c"]?.string == "Stack" { | ||
node = node["k"]?.array?.first ?? .null | ||
} | ||
switch node["c"]?.string { | ||
case "Image", "Gallery", "Map": return node["p"]?["bleed"] == .bool(true) | ||
case "Covers": return node["p"]?["style"]?.string == "tiles" && node["p"]?["select"] == nil | ||
default: return false | ||
} | ||
guard let c = node?["c"]?.string, ["Image", "Gallery", "Map"].contains(c) else { return false } | ||
return node?["p"]?["bleed"] == .bool(true) | ||
} | ||
| ||
/// This with a next page added: its page list's items grown and its | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Parts/ActionButton.swift+5−0
| @@ -248,6 +248,7 @@ struct ActionButton: View { | ||
var button = false | ||
var bar = false | ||
@Environment(\.viewContext) private var view | ||
@Environment(\.slideLike) private var slideLike | ||
@State private var run = ActionRun() | ||
| ||
/// Whether the app takes what a request does: an interaction or a | ||
| @@ -299,6 +300,10 @@ struct ActionButton: View { | ||
.accessibilityAddTraits(done ? .isSelected : []) | ||
.accessibilityHint(run.ran.made != nil ? "Tap to undo" : "") | ||
.onAppear { run.ran = ActionRun.remembered(spec, view) } | ||
// Named by the `Slides` it is over as what a double-tap runs (a story's ♡): run where not done yet, never undone so. | ||
.onChange(of: slideLike?.taps) { | ||
if let like = slideLike, like.label == spec.label, !run.ran.done { run.tap(spec, view) } | ||
} | ||
.actionAsks(run, spec, view) | ||
} | ||
| ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Parts/ComposeFields.swift+15−14
| @@ -42,18 +42,23 @@ struct ComposeFieldView: View { | ||
} | ||
} | ||
| ||
/// How many characters are left, near the limit (`max`, in graphemes); past it, in red. | ||
/// What is left of a text's or line's nearer limit (`ComposeField.room`): | ||
/// how much, below 0 past it, and whether it is near enough to say. | ||
struct ComposeRoom: Equatable { | ||
let left: Int | ||
let near: Bool | ||
} | ||
| ||
/// What is left of a text's or line's nearer limit, said near it; past it, in red. | ||
struct ComposeCounter: View { | ||
let count: Int | ||
let max: Int | ||
let room: ComposeRoom? | ||
| ||
var body: some View { | ||
let left = max - count | ||
if left <= Swift.max(10, max / 5) { | ||
Text("\(left)") | ||
if let room, room.near { | ||
Text("\(room.left)") | ||
.hudFont(.caption.monospacedDigit()) | ||
.foregroundStyle(left < 0 ? .red : .secondary) | ||
.accessibilityLabel(left < 0 ? "\(-left) characters too many" : "\(left) characters left") | ||
.foregroundStyle(room.left < 0 ? .red : .secondary) | ||
.accessibilityLabel(room.left < 0 ? "\(-room.left) too many" : "\(room.left) left") | ||
} | ||
} | ||
} | ||
| @@ -80,9 +85,7 @@ struct ComposeTextField: View { | ||
autofocus: autofocus | ||
) | ||
.frame(maxWidth: .infinity, minHeight: 96, alignment: .topLeading) | ||
if let max = field.max { | ||
ComposeCounter(count: text.count, max: max) | ||
} | ||
ComposeCounter(room: field.room(text)) | ||
} | ||
.task(id: field.p["suggest"] == nil ? nil : form.typing(name)) { await suggest() } | ||
} | ||
| @@ -240,9 +243,7 @@ struct ComposeLineField: View { | ||
.submitLabel(.next) | ||
.accessibilityLabel(field.spoken) | ||
Divider() | ||
if let max = field.max { | ||
ComposeCounter(count: (form.texts[name] ?? "").count, max: max) | ||
} | ||
ComposeCounter(room: field.room(form.texts[name] ?? "")) | ||
} | ||
.onAppear { if autofocus { focused = true } } | ||
} | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Parts/ComposeForm.swift+23−1
| @@ -24,7 +24,29 @@ struct ComposeField: Identifiable { | ||
var label: String? { p.str("label") } | ||
var required: Bool { p["required"] == .bool(true) } | ||
var placeholder: String? { p.str("placeholder") } | ||
/// A text's or line's graphemes at most, a photos field's photos, a langs field's languages. | ||
var max: Int? { p["max"]?.number.map { Int($0) } } | ||
/// A text's or line's UTF-8 bytes at most (its record's lexicon's `maxLength`). | ||
var maxBytes: Int? { p["maxBytes"]?.number.map { Int($0) } } | ||
| ||
/// What is left of a text's or line's limits once `text` is written | ||
/// (trimmed, as it is sent): of the one it has used the most of, `max` | ||
/// graphemes or `maxBytes` UTF-8 bytes (below 0 past it), and whether | ||
/// that is said, within the larger of 10 and a fifth of it; nil with no limit. | ||
func room(_ text: String) -> ComposeRoom? { | ||
let sent = text.trimmingCharacters(in: .whitespacesAndNewlines) | ||
var out: ComposeRoom? | ||
var share = Double.infinity | ||
for case let (limit?, used) in [(max, sent.count), (maxBytes, sent.utf8.count)] where limit > 0 { | ||
let left = limit - used | ||
if Double(left) / Double(limit) < share { | ||
share = Double(left) / Double(limit) | ||
out = ComposeRoom(left: left, near: left <= Swift.max(10, limit / 5)) | ||
} | ||
} | ||
return out | ||
} | ||
| ||
var min: Int { Int(p["min"]?.number ?? 0) } | ||
var options: [JSON] { p["options"]?.array ?? [] } | ||
/// What a text or line opens holding (an edit's: a profile's name). | ||
| @@ -318,7 +340,7 @@ struct ComposeSuggestion: Identifiable, Equatable { | ||
let value = value(field, given: given, uploads: uploads) | ||
if value != nil, field.kind == "text" || field.kind == "line" || field.kind == "photos" { any = true } | ||
if field.required && value == nil { return "\(field.label ?? field.name) is needed" } | ||
if let max = field.max, field.kind == "text" || field.kind == "line", (texts[field.name] ?? "").count > max { | ||
if field.kind == "text" || field.kind == "line", (field.room(texts[field.name] ?? "")?.left ?? 0) < 0 { | ||
return "Too long" | ||
} | ||
if field.kind == "photos", uploads { | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Tree/ResolvedSlides.swift+68−0
| @@ -30,6 +30,49 @@ import SwiftUI | ||
// own button (`slidesTrailing`); while one asks something (its menu open, | ||
// a dialog or sheet it opened up), the slide waits, as held. | ||
| ||
/// What a `Slides`' double-tap asks of a slide's own: the `Action` of | ||
/// `label`, each time `taps` grows. | ||
struct SlideLike: Equatable { | ||
var label: String | ||
var taps: Int | ||
} | ||
| ||
/// A heart where a double-tap was. | ||
struct Burst: Identifiable { | ||
let id: Int | ||
let at: CGPoint | ||
} | ||
| ||
/// A double-tap's heart: it pops up, holds, and fades, as Grain's does. | ||
private struct HeartBurst: View { | ||
struct Pop { | ||
var scale = 0.3 | ||
var opacity = 0.0 | ||
} | ||
| ||
var body: some View { | ||
Image(systemName: "heart.fill") | ||
.font(.system(size: 88)) | ||
.foregroundStyle(Color(red: 1, green: 0.25, blue: 0.4)) | ||
.shadow(color: .black.opacity(0.35), radius: 8, y: 2) | ||
.keyframeAnimator(initialValue: Pop(), repeating: false) { content, pop in | ||
content.scaleEffect(pop.scale).opacity(pop.opacity) | ||
} keyframes: { _ in | ||
KeyframeTrack(\.scale) { | ||
SpringKeyframe(1.15, duration: 0.2) | ||
SpringKeyframe(1, duration: 0.16) | ||
LinearKeyframe(1, duration: 0.24) | ||
LinearKeyframe(1.1, duration: 0.2) | ||
} | ||
KeyframeTrack(\.opacity) { | ||
LinearKeyframe(1, duration: 0.2) | ||
LinearKeyframe(1, duration: 0.4) | ||
LinearKeyframe(0, duration: 0.2) | ||
} | ||
} | ||
} | ||
} | ||
| ||
/// One slide: its picture, said by `alt`, when and where, the procedure | ||
/// its showing calls, and what is drawn over it (its menu). | ||
struct Slide: Equatable { | ||
| @@ -53,6 +96,8 @@ struct ResolvedSlides: View { | ||
var children: JSON = .null | ||
/// The slide it begins at (`start`, from 0), as a story picked from an archive. | ||
var start = 0 | ||
/// The label of the `Action` among a slide's own that a double-tap runs (a story's ♡), where it is not done yet. | ||
var like: String? | ||
@Environment(\.viewContext) private var view | ||
@Environment(\.accessibilityReduceMotion) private var still | ||
/// The slide gone to; none yet, it shows `start`. | ||
| @@ -70,6 +115,9 @@ struct ResolvedSlides: View { | ||
@State private var ready: Int? | ||
@Environment(\.slidesTrailing) private var trailing | ||
@State private var width: CGFloat = 0 | ||
/// Double-taps so far, told to the slide's own; the hearts bursting where they were. | ||
@State private var likes = 0 | ||
@State private var bursts: [Burst] = [] | ||
| ||
/// Slides from a `Slides`' items. | ||
nonisolated static func slides(_ items: [JSON]) -> [Slide] { | ||
| @@ -157,9 +205,17 @@ struct ResolvedSlides: View { | ||
.id(i) | ||
} | ||
.overlay(alignment: .top) { header(i, slide) } | ||
.overlay(alignment: .topLeading) { | ||
ForEach(bursts) { burst in | ||
HeartBurst().position(burst.at) | ||
} | ||
.allowsHitTesting(false) | ||
} | ||
.clipped() | ||
.contentShape(.rect) | ||
.onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width = $0 } | ||
// With `like`, a double-tap runs it (a tap waits to be sure it is not one). | ||
.gesture(SpatialTapGesture(count: 2).onEnded { liked(at: $0.location) }, including: like == nil ? .subviews : .all) | ||
.onTapGesture { location in | ||
advance(i, by: location.x < width / 2 ? -1 : 1) | ||
} | ||
| @@ -213,6 +269,7 @@ struct ResolvedSlides: View { | ||
.environment(\.asking) { hold(asking: $0) } | ||
// White over the picture, as the rest of its top row. | ||
.environment(\.menuTrigger, MenuTrigger(font: .body.weight(.semibold), color: .white, side: 44)) | ||
.environment(\.slideLike, like.map { SlideLike(label: $0, taps: likes) }) | ||
.id(i) | ||
} | ||
} | ||
| @@ -329,6 +386,17 @@ struct ResolvedSlides: View { | ||
return ([name, when, slide.place].compactMap { $0 } + ["\(i + 1) of \(slides.count)"]).joined(separator: ", ") | ||
} | ||
| ||
/// A double-tap: the slide's `like` asked of its own, a heart bursting where it was. | ||
private func liked(at point: CGPoint) { | ||
likes += 1 | ||
let id = likes | ||
bursts.append(Burst(id: id, at: point)) | ||
Task { | ||
try? await Task.sleep(for: .milliseconds(900)) | ||
bursts.removeAll { $0.id == id } | ||
} | ||
} | ||
| ||
/// Go `by` on from slide `i`: to that slide, or off an end, told to the | ||
/// app where it is told; else it stays. | ||
private func advance(_ i: Int, by: Int) { | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Tree/TreeView.swift+2−1
| @@ -227,7 +227,8 @@ struct ResolvedNode: View { | ||
name: p.str("name"), | ||
empty: p.str("empty"), | ||
children: node, | ||
start: ResolvedSlides.start(p["start"]) | ||
start: ResolvedSlides.start(p["start"]), | ||
like: p.str("like") | ||
) | ||
case "Faces": | ||
if p.str("style") == "pile" { | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/View/Context.swift+3−0
| @@ -334,6 +334,9 @@ extension EnvironmentValues { | ||
/// How a `Menu`'s ⋯ is drawn here, where not as everywhere else (the | ||
/// footnote's size in the muted colour): a story's, over its picture. | ||
@Entry var menuTrigger: MenuTrigger? = nil | ||
/// What a `Slides`' double-tap runs among a picture's own: the `Action` | ||
/// of this label, each time `taps` grows, where it is not done yet. | ||
@Entry var slideLike: SlideLike? = nil | ||
/// Whether cut-short text offers "more": not in a shelf's card, which | ||
/// opens what it is of. | ||
@Entry var clampMore = true | ||
vendor/hud/ios/HUDKit/Tests/HUDKitTests/ComposeTests.swift+26−0
| @@ -82,6 +82,32 @@ import UniformTypeIdentifiers | ||
#expect(form.blocked(fields, given: given, uploads: true) == "Too long") | ||
} | ||
| ||
/// A text's or line's limits are its record's lexicon's: a gallery's | ||
/// title 100 UTF-8 bytes, so 60 accented letters and emoji are past it; | ||
/// a comment's 300 graphemes and 3000 bytes, what is left said of the | ||
/// nearer, within the larger of 10 and a fifth of it. | ||
@MainActor @Test func aFieldIsHeldToItsGraphemesAndItsBytes() { | ||
let title = ComposeField(p: ["name": "title", "kind": "line", "maxBytes": 100, "required": true]) | ||
let sixty = String(repeating: "é", count: 40) + String(repeating: "🌄", count: 5) + String(repeating: "a", count: 15) | ||
#expect(sixty.count == 60) | ||
#expect(title.room(sixty) == ComposeRoom(left: -15, near: true)) | ||
#expect(title.room(String(repeating: "é", count: 50)) == ComposeRoom(left: 0, near: true)) | ||
#expect(title.room(String(repeating: "é", count: 40)) == ComposeRoom(left: 20, near: true)) | ||
#expect(title.room(String(repeating: "é", count: 39)) == ComposeRoom(left: 22, near: false)) | ||
let comment = ComposeField(p: ["name": "text", "kind": "text", "max": 300, "maxBytes": 3000]) | ||
#expect(comment.room(String(repeating: "a", count: 250)) == ComposeRoom(left: 50, near: true)) | ||
// A letter under twelve accents is one grapheme of 25 bytes: the bytes, 3000, come long before 300 of them. | ||
#expect(comment.room(String(repeating: "a" + String(repeating: "\u{0301}", count: 12), count: 130)) == ComposeRoom(left: -250, near: true)) | ||
#expect(comment.room(" a \n") == ComposeRoom(left: 299, near: false)) | ||
#expect(ComposeField(p: ["name": "x", "kind": "text"]).room("a") == nil) | ||
// Past its bytes, a title is not sent; at them, it is. | ||
let form = ComposeForm(fields: [title]) | ||
form.texts["title"] = sixty | ||
#expect(form.blocked([title], given: nil, uploads: true) == "Too long") | ||
form.texts["title"] = String(repeating: "é", count: 50) | ||
#expect(form.blocked([title], given: nil, uploads: true) == nil) | ||
} | ||
| ||
@MainActor @Test func aFormThatNeedsAPhotoIsOfferedOnlyWhereTheAppUploads() { | ||
let p: JSON = ["fields": [["name": "photos", "kind": "photos", "min": 1, "max": 10]]] | ||
let gallery = ComposeField.all(p) | ||
vendor/hud/ios/HUDKit/Tests/HUDKitTests/HUDKitTests.swift+15−0
| @@ -701,6 +701,21 @@ private func conversation() throws -> (drawn: Drawn, root: JSON) { | ||
#expect(!Drawn.tree(["root": ["c": "Stack", "k": [title, map]]]).leadsWithBleed) | ||
#expect(!Drawn.tree(["root": ["c": "Map", "p": [:]]]).leadsWithBleed) | ||
} | ||
| ||
/// A camera's feed, its Bar lifted into the navigation bar, starts with | ||
/// tiles: they meet the bar as they meet the sides. | ||
@Test func tilesUnderALiftedBarLeadTheScreen() { | ||
let bar: JSON = ["c": "Bar", "p": ["title": "Canon EOS 650D"]] | ||
let tiles: JSON = ["c": "Covers", "p": ["style": "tiles"]] | ||
let feed = Drawn.tree(["root": ["c": "Stack", "k": [["c": "Stack", "k": [bar, tiles]]]]]) | ||
#expect(feed.leadsWithBleed) | ||
// A tile draws its Bar in its place, over the tiles. | ||
#expect(!feed.leadsTileWithBleed) | ||
#expect(Drawn.tree(["root": tiles]).leadsTileWithBleed) | ||
// Cards keep their inset, and so do tiles with Select over them. | ||
#expect(!Drawn.tree(["root": ["c": "Covers", "p": [:]]]).leadsWithBleed) | ||
#expect(!Drawn.tree(["root": ["c": "Covers", "p": ["style": "tiles", "select": ["label": "Select"]]]]).leadsWithBleed) | ||
} | ||
} | ||
| ||
@Suite struct Messages { | ||