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

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: double-tap favorites stories and galleries, a story has a ♡

Merged chadtmiller.com asked to merge into feature/hud from grain.social/grain:next/story-desktop

Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.

ios/GrainUITests/GrainUITests.swift+41−14
@@ -126,9 +126,11 @@ final class GrainUITests: XCTestCase {
}
}
/// A gallery's own screen (its carousel `zoom`): a tap on its picture
/// opens it full screen in the lightbox, swiped to the next, closed by
/// its ✕. What it read goes to GRAIN_SHOTS/zoom.txt.
/// A gallery's own screen (its carousel `zoom`), opened from its card
/// below its picture (a tap on a feed's picture opens nothing, a
/// double-tap favorites): a tap on its picture opens it full screen in
/// the lightbox, swiped to the next, closed by its ✕. What it read goes
/// to GRAIN_SHOTS/zoom.txt.
func testGalleryZoom() throws {
XCTAssertTrue(app.staticTexts["·"].firstMatch.waitForExistence(timeout: 30), "No cards in Home's feed")
let width = app.windows.firstMatch.frame.width
@@ -138,8 +140,30 @@ final class GrainUITests: XCTestCase {
}
XCTAssertTrue(dots.exists, "No gallery of several pictures in Home's feed")
let screen = app.windows.firstMatch.coordinate(withNormalizedOffset: .zero)
// Its picture, above its dots: in the feed it opens the gallery.
screen.withOffset(CGVector(dx: width / 2, dy: dots.frame.minY - 80)).tap()
// Its card's title, the line below its ♡ row: in the feed it opens the
// gallery. The feed is drawn up a little at a time until the title shows.
func cardTitle() -> XCUIElement? {
let all: [XCUIElement] = app.otherElements.matching(NSPredicate(format: "label BEGINSWITH 'Picture 1 of '")).allElementsBoundByIndex
let hearts: [CGRect] = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Favorite'")).allElementsBoundByIndex.map(\.frame)
let texts: [XCUIElement] = app.staticTexts.allElementsBoundByIndex
for shown in all.map(\.frame) where shown.minY > 100 {
guard let heart = hearts.filter({ (f: CGRect) -> Bool in f.minY > shown.maxY }).min(by: { $0.minY < $1.minY }) else { continue }
if let title = texts.first(where: { (t: XCUIElement) -> Bool in t.frame.minY > heart.maxY && t.frame.minY < heart.maxY + 60 && t.frame.maxY < 720 }) { return title }
}
return nil
}
var found = cardTitle()
for _ in 0..<6 where found == nil {
screen.withOffset(CGVector(dx: 30, dy: 600)).press(forDuration: 0.2, thenDragTo: screen.withOffset(CGVector(dx: 30, dy: 480)), withVelocity: .slow, thenHoldForDuration: 0.3)
found = cardTitle()
}
guard let title = found else {
shot("zoom-no-title")
return XCTFail("No title on the gallery's card")
}
title.tap()
let back = app.navigationBars.buttons.firstMatch
XCTAssertTrue(back.waitForExistence(timeout: 15), "The card didn't open the gallery")
XCTAssertTrue(dots.waitForExistence(timeout: 15), "The gallery's screen has no carousel")
sleep(3)
shot("zoom-gallery")
@@ -198,10 +222,11 @@ final class GrainUITests: XCTestCase {
shot("follows-you")
}
/// Signed in, someone's story has a 💬 at the end of its top row, before
/// its ⋯; tapped, the comments come up as a sheet over the story, which
/// waits under it: after six seconds and the sheet let go, the same story
/// shows. What it measured goes to GRAIN_SHOTS/comments.txt.
/// Signed in, someone's story has a 💬 and a ♡ at the end of its top
/// row, before its ⋯; tapped, the 💬 brings the comments up as a sheet
/// over the story, which waits under it: after six seconds and the sheet
/// let go, the same story shows. What it measured goes to
/// GRAIN_SHOTS/comments.txt.
func testStoryComments() throws {
XCTAssertTrue(app.staticTexts["·"].firstMatch.waitForExistence(timeout: 30), "No cards in Home's feed")
sleep(2)
@@ -215,20 +240,22 @@ final class GrainUITests: XCTestCase {
// The page in front's: its neighbours, drawn either side, have theirs too.
let width = app.windows.firstMatch.frame.width
// From one snapshot, as each slide redraws its row as it goes on.
func snapshotFrame(_ label: String) -> CGRect? {
func snapshotFrame(_ label: String, prefix: Bool = false) -> CGRect? {
func all(_ node: XCUIElementSnapshot) -> [XCUIElementSnapshot] { [node] + node.children.flatMap(all) }
let found = ((try? all(app.snapshot())) ?? []).filter { $0.elementType == .button && $0.label == label }.map { $0.frame }
let found = ((try? all(app.snapshot())) ?? []).filter { $0.elementType == .button && (prefix ? $0.label.localizedCaseInsensitiveContains(label) : $0.label == label) }.map { $0.frame }
return found.first { (f: CGRect) -> Bool in f.minX >= 0 && f.maxX <= width + 1 }
}
XCTAssertTrue(app.buttons["Comments"].firstMatch.waitForExistence(timeout: 10), "No 💬 on the story")
sleep(1)
guard let comments = snapshotFrame("Comments"), let more = snapshotFrame("More") else { return XCTFail("No 💬 or ⋯ on the story in front") }
guard let comments = snapshotFrame("Comments"), let heart = snapshotFrame("favorite", prefix: true), let more = snapshotFrame("More") else { return XCTFail("No 💬, ♡ or ⋯ on the story in front") }
let cross = close.frame
var lines = ["💬 \(comments) centre \(comments.midX), \(comments.midY)", "⋯ \(more) centre \(more.midX), \(more.midY)", "✕ \(cross) centre \(cross.midX), \(cross.midY)"]
var lines = ["💬 \(comments) centre \(comments.midX), \(comments.midY)", "♡ \(heart) centre \(heart.midX), \(heart.midY)", "⋯ \(more) centre \(more.midX), \(more.midY)", "✕ \(cross) centre \(cross.midX), \(cross.midY)"]
XCTAssertEqual(comments.width, 44, accuracy: 0.5)
XCTAssertEqual(comments.height, 44, accuracy: 0.5)
XCTAssertEqual(comments.midY, cross.midY, accuracy: 1, "The 💬 isn't on the ⋯ and ✕'s line")
XCTAssertEqual(more.midX - comments.midX, 44, accuracy: 0.5, "The 💬 isn't just before the ⋯")
XCTAssertEqual(heart.midY, cross.midY, accuracy: 1, "The ♡ isn't on the ⋯ and ✕'s line")
XCTAssertEqual(heart.midX - comments.midX, 44, accuracy: 0.5, "The ♡ isn't just after the 💬")
XCTAssertEqual(more.midX - heart.midX, 44, accuracy: 0.5, "The ♡ isn't just before the ⋯")
shot("story-comments-row")
// Which story the page in front shows, as VoiceOver reads it ("… 2 of 5").
func showing() -> String {
next/views/grain-comments.json+3−2
@@ -355,7 +355,7 @@
{
"name": "text",
"kind": "text",
"placeholder": "Add a comment",
"placeholder": "Add a comment…",
"facets": true,
"suggest": {
"method": "social.grain.actor.searchActorsTypeahead",
@@ -392,7 +392,8 @@
}
}
],
"style": "button"
"style": "field",
"signIn": "Sign in to comment"
}
}
]
next/views/grain-feed.json+1−0
@@ -710,6 +710,7 @@
},
"style": "carousel",
"bleed": true,
"like": "Favorite",
"showAlt": true,
"info": [
{
next/views/grain-stories.json+24−1
@@ -81,7 +81,8 @@
"joins.who.handle"
]
},
"empty": "No stories right now"
"empty": "No stories right now",
"like": "Favorite"
},
"children": [
{
@@ -105,6 +106,28 @@
"sheet": true
}
}
},
{
"component": "Action",
"props": {
"label": "Favorite",
"icon": "heart",
"done": "Favorited",
"create": {
"collection": "social.grain.favorite",
"record": {
"subject": {
"$": "uri"
},
"createdAt": {
"$now": true
}
}
},
"existing": {
"$": "viewer.fav"
}
}
}
]
},
next/views/grain-story-archive.json+24−1
@@ -73,7 +73,8 @@
]
},
"start": "uri",
"empty": "No stories yet"
"empty": "No stories yet",
"like": "Favorite"
},
"children": [
{
@@ -97,6 +98,28 @@
"sheet": true
}
}
},
{
"component": "Action",
"props": {
"label": "Favorite",
"icon": "heart",
"done": "Favorited",
"create": {
"collection": "social.grain.favorite",
"record": {
"subject": {
"$": "uri"
},
"createdAt": {
"$now": true
}
}
},
"existing": {
"$": "viewer.fav"
}
}
}
]
},
vendor/hud/ios/HUDKit/Sources/HUDKit/Parts/DoubleTap.swift+7−2
@@ -56,19 +56,23 @@ struct HeartBursts: View {
}
}
/// A double-tap's heart: it pops up, holds, and fades, as Grain's does.
/// A double-tap's heart: it pops up, holds, and fades, as Grain's does,
/// played once as it appears (a keyframe animator not repeating holds its
/// first value, unseen, until its trigger changes).
private struct HeartBurst: View {
struct Pop {
var scale = 0.3
var opacity = 0.0
}
@State private var shown = false
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
.keyframeAnimator(initialValue: Pop(), trigger: shown) { content, pop in
content.scaleEffect(pop.scale).opacity(pop.opacity)
} keyframes: { _ in
KeyframeTrack(\.scale) {
@@ -83,6 +87,7 @@ private struct HeartBurst: View {
LinearKeyframe(0, duration: 0.2)
}
}
.onAppear { shown = true }
}
}
vendor/hud/COMMIT+1−1
@@ -1 +1 @@
bd7494dc524b9307f1a9afd5b212694e1d4ad944
d74c7fe5704d1a33abafdda495a5fc0b171b89df