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

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: swipe back reaches Your story; with none, New story alone on iOS

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

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

ios/Grain/StoryPager.swift+77−29
@@ -7,7 +7,9 @@ import SwiftUI
/// as a level (a tab chosen on it swapped in there), and the one in front.
/// Only the page tapped may open the form its call opens at (Your story's
/// `compose`, with none), and only until it is left (`opensForms`), as the
/// web's pager.
/// web's pager. Where it does, no stories are drawn: that form alone is
/// (`alone`), over the tabs, and it closing, sent or not, closes them, as
/// Grain's Your story with none goes to the camera and back.
@MainActor @Observable
final class Stories: Identifiable {
let tab: Int
@@ -17,6 +19,8 @@ final class Stories: Identifiable {
let tapped: Int
/// Whether the page tapped was left: from then on, no page opens a form by itself.
private(set) var leftTapped = false
/// Whether the page tapped's call opens at a form (its `compose`).
let composes: Bool
init(_ pages: Pages, tab: Int) {
self.tab = tab
@@ -24,11 +28,22 @@ final class Stories: Identifiable {
let at = min(max(pages.at, 0), max(pages.calls.count - 1, 0))
self.at = at
tapped = at
composes = pages.calls.indices.contains(at) && pages.calls[at].args["compose"] != nil
}
/// Whether page `i` may open the form its call opens at by itself.
func opensForms(_ i: Int) -> Bool { i == tapped && !leftTapped }
/// Whether the page tapped is drawn as its form alone: its call opens at
/// one, and until it answers afresh (not its tree as last drawn, which
/// may be either), it may be only that; once it has, where it is.
var alone: Bool {
guard composes, !leftTapped else { return false }
let level = levels[tapped]
guard let drawn = level.drawn, !level.refreshing, !level.swapping else { return true }
return drawn.opensAtForm
}
/// To page `to`: leaving the page tapped, no page opens a form by itself again.
func move(to: Int) {
if at == tapped, to != tapped { leftTapped = true }
@@ -72,37 +87,56 @@ struct StoryPager: View {
private var down: CGFloat { min(dy / 300, 1) }
var body: some View {
Group {
if stories.alone {
// Your story with none: its form alone over the tabs, nothing drawn
// meanwhile; it closing, sent or not, closes the stories.
page(stories.tapped, alone: { shell.closeStories() })
} else {
pager
}
}
.presentationBackground(.clear)
}
/// Page `i`, wired to the stories; with `alone`, drawn as its form alone.
private func page(_ i: Int, alone: (@MainActor () -> Void)? = nil) -> some View {
StoryPage(
level: stories.levels[i],
shell: shell,
active: i == stories.at && !fading,
opensForms: stories.opensForms(i),
alone: alone,
open: { call in
shell.closeStories()
shell.open(call, in: stories.tab)
},
replace: { shell.replace(stories.levels[i], with: $0) },
end: { way in if i == stories.at { end(way) } },
// A story deleted (an action that leaves): the stories close.
leave: { fadeAway() },
// Its comments as a sheet over it, the story held meanwhile.
sheet: { shell.openSheet($0, in: stories.tab) },
wrote: { shell.wrote(on: stories.levels[i], in: stories.tab) },
held: shell.sheet != nil
)
.id(ObjectIdentifier(stories.levels[i]))
}
private var pager: some View {
let shown = max(stories.at - 1, 0)...min(stories.at + 1, stories.levels.count - 1)
ZStack {
return ZStack {
Color.black
.opacity(1 - down)
.ignoresSafeArea()
ZStack {
ForEach(Array(shown), id: \.self) { i in
StoryPage(
level: stories.levels[i],
shell: shell,
active: i == stories.at && !fading,
opensForms: stories.opensForms(i),
open: { call in
shell.closeStories()
shell.open(call, in: stories.tab)
},
replace: { shell.replace(stories.levels[i], with: $0) },
end: { way in if i == stories.at { end(way) } },
// A story deleted (an action that leaves): the stories close.
leave: { fadeAway() },
// Its comments as a sheet over it, the story held meanwhile.
sheet: { shell.openSheet($0, in: stories.tab) },
wrote: { shell.wrote(on: stories.levels[i], in: stories.tab) },
held: shell.sheet != nil
)
.id(ObjectIdentifier(stories.levels[i]))
.offset(x: offset(i))
.scaleEffect(scale(i))
.opacity(opacity(i))
.zIndex(i == stories.at ? 1 : 0)
.allowsHitTesting(i == stories.at)
page(i)
.offset(x: offset(i))
.scaleEffect(scale(i))
.opacity(opacity(i))
.zIndex(i == stories.at ? 1 : 0)
.allowsHitTesting(i == stories.at)
}
}
// The slides' top row ends before the ✕, their ⋯ just before it.
@@ -131,7 +165,6 @@ struct StoryPager: View {
.simultaneousGesture(drag)
.environment(\.hudTheme, shell.config.dark)
.preferredColorScheme(.dark)
.presentationBackground(.clear)
.sheet(item: Binding(get: { shell.sheet?.overStories == true ? shell.sheet : nil }, set: { if $0 == nil { shell.sheet = nil } })) { sheet in
SheetScreen(shell: shell, sheet: sheet)
}
@@ -271,13 +304,17 @@ struct StoryPager: View {
}
/// One page of the stories: its call's answer drawn by HUDKit with a
/// context of its own, in front or drawn ahead (`active`).
/// context of its own, in front or drawn ahead (`active`); with `alone`,
/// only the form its call opens at (`OpenedForm`), once it answers afresh,
/// nothing before, `alone` told as it closes or its write reads it again.
private struct StoryPage: View {
let level: Level
let shell: Shell
let active: Bool
/// Whether a form its call opens at may open by itself (the page tapped, until left).
let opensForms: Bool
/// Drawn as its form alone: told as that is done, sent or not.
let alone: (@MainActor () -> Void)?
let open: @MainActor (Call) -> Void
let replace: @MainActor (Call) -> Void
let end: @MainActor (Way) -> Void
@@ -296,6 +333,7 @@ private struct StoryPage: View {
shell: Shell,
active: Bool,
opensForms: Bool,
alone: (@MainActor () -> Void)?,
open: @escaping @MainActor (Call) -> Void,
replace: @escaping @MainActor (Call) -> Void,
end: @escaping @MainActor (Way) -> Void,
@@ -308,6 +346,7 @@ private struct StoryPage: View {
self.shell = shell
self.active = active
self.opensForms = opensForms
self.alone = alone
self.open = open
self.replace = replace
self.end = end
@@ -324,7 +363,14 @@ private struct StoryPage: View {
var body: some View {
Group {
if level.needsSignIn {
if let alone {
// Nothing until it answers afresh, but a view, so it loads.
if let drawn = shown, !level.refreshing, !level.swapping {
OpenedForm(drawn: drawn, context: context, done: alone)
} else {
Color.clear
}
} else if level.needsSignIn {
SignInAsk(shell: shell, words: "Sign in to see this")
} else if let drawn = shown {
ResultView(drawn: drawn, context: context, onRetry: retry)
@@ -360,5 +406,7 @@ private struct StoryPage: View {
private func configure() {
context.wire(level: level, shell: shell, open: open, replace: replace, pages: nil, sheet: sheet, leave: leave, wrote: wrote)
context.onEnd = end
// Sent alone, the stories close rather than read its page again.
if let alone { context.onReload = { alone() } }
}
}
ios/README.md+1−1
@@ -11,7 +11,7 @@ guest; Sign in goes through the server's OAuth.
- `Grain/GrainApp.swift`: the app, its tab bar and each tab's stack; its app delegate, HUDKit's `PushAppDelegate`; grain.social links opened as their routes.
- `Grain/Shell.swift`: the server, the accounts kept on the device and the one in use, each tab's levels, signing in and out, switching accounts, push, and opening a route's path. Settings' Accounts lists every account kept (in the order first kept, each its picture, name and handle as its own profile answered, read with its own tokens and kept 10 minutes, as `frame.account.picture` says), the one in use ticked; a tap on another switches to it, Add account signs in to one more (one kept already has its tokens replaced, no second row), and Sign out (or Delete account's) leaves the account used before it. Signing in, out or switching starts every tab afresh, as the web loads its page anew: no screen, last tree, read-ahead, badge or open form of the account before is drawn again. A level opened again draws its tree as last drawn at once (HUDKit's `LastTree`: the account's own, at most 10 minutes old) while its call is read afresh; a write lets the account's go.
- `Grain/LevelScreen.swift`: one level, its view drawn by HUDKit's TreeView, and how a view's context is wired. Each time a level shows (opened, gone back to, its tab chosen again) it is read afresh, a thin line moving under the bar meanwhile, the answer drawn in place where it was scrolled, with the pages loaded past the first kept after it.
- `Grain/StoryPager.swift`: people's stories over the tabs, from the stories strip (a `pages` list), swiped between as grain-ios does.
- `Grain/StoryPager.swift`: people's stories over the tabs, from the stories strip (a `pages` list), swiped between as grain-ios does; Your story with none of one's own is its New story form alone over the tab (HUDKit's `OpenedForm`), Cancel or Share closing it back to the tab.
- `Grain/Config.swift`: `grain.social.json` read, its palettes as HUDKit themes, its `signIn` as HUDKit's `SignInPlan`.
- `Grain/SignInSheet.swift`: signing in, as grain-ios's LoginView, from `grain.social.json`'s `signIn`: over Grain's photo, the wordmark, the heading and its line, the handle field with the accounts the typeahead (typeahead.waow.tech) finds as it is typed (arrows and tab move through them, return or a tap picks one and signs in), Sign in, Create one (a new account, `prompt=create`), the legal line, its links in Safari; errors in red.
- `Grain/Fonts/`: Syne and Plus Jakarta Sans, Google Fonts' variable TTFs (OFL), registered in `UIAppFonts`; titles are Syne at weight 800.
next/views/grain-feed.json+2−1
@@ -513,7 +513,8 @@
"$": "profile.did"
}
},
"compose": true
"compose": true,
"unless": "unviewedCount"
}
},
"pages": true
vendor/hud/COMMIT+1−1
@@ -1 +1 @@
7354661b1c453f5ec710f3f43e91001c29041755
001122e6c434953882d3cf02ec2b469901b9c7e7