chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.5.0 Latest 5 packages
0
0
iOS: a tile comes back scrolled where it was
docs/memory.md+1−1
| @@ -25,7 +25,7 @@ HUD keeps audio and video on disk (`HUD_BLOB_CACHE_BYTES`). It streams images th | ||
| ||
## Workspace | ||
| ||
A tile keeps what it read, and never makes it deeply reactive. It draws it only while its column is within a screen's width of what's in view on the tab on screen. Farther away, or on a tab out of sight, the tile's body is empty and its scroll is kept. As it comes near, the tile draws again from what it read, without asking again. | ||
A tile keeps what it read, and never makes it deeply reactive. It draws it only while its column is within a screen's width of what's in view on the tab on screen. Farther away, or on a tab out of sight, the tile's body is empty and its scroll is kept. As it comes near, the tile draws again from what it read, without asking again. The iOS app keeps a tile's scroll the same way when its view is made again, as switching canvases does (iOS 18 and later). | ||
| ||
A player's music goes on in the page's one `<audio>`, apart from the tiles. It holds only the tracks it plays. A video, or an audio field, stops as its tile stops drawing. | ||
| ||
ios/App/Browser.swift+3−0
| @@ -341,6 +341,9 @@ final class Step: Hashable { | ||
@ObservationIgnored var told: Set<String> = [] | ||
/// When it was last read, or asked whether something newer came. | ||
@ObservationIgnored var checked = Date.distantPast | ||
/// How far down it was scrolled, from its top: kept as its tile scrolls | ||
/// off the strip and its view goes, to scroll back to as it comes back. | ||
@ObservationIgnored var offset: CGFloat = 0 | ||
@ObservationIgnored private var peeking = false | ||
| ||
init(call: Call) { | ||
ios/App/StepScreen.swift+47−0
| @@ -73,6 +73,7 @@ struct StepView: View { | ||
.padding(.vertical, Space.s2) | ||
.id(Self.top) | ||
} | ||
.keepingScroll(of: step, drawn: wired == ObjectIdentifier(step) && step.drawn != nil) | ||
.overlay(alignment: .top) { | ||
if step.fresh, let noun = step.drawn?.latest?.noun { | ||
newer(noun) { | ||
| @@ -259,3 +260,49 @@ struct StepView: View { | ||
} | ||
} | ||
} | ||
| ||
extension View { | ||
/// Keep how far `step`'s scroll view is scrolled in `step`, and scroll | ||
/// back there once its result is `drawn` again, as the web's tile does | ||
/// with its body's `scrollTop`: a tile's view goes as it scrolls off the | ||
/// strip, its step stays. iOS 17 has no way to read or set an offset, so | ||
/// there it starts at the top. | ||
@ViewBuilder | ||
func keepingScroll(of step: Step, drawn: Bool) -> some View { | ||
if #available(iOS 18, *) { | ||
modifier(KeepsScroll(step: step, drawn: drawn)) | ||
} else { | ||
self | ||
} | ||
} | ||
} | ||
| ||
@available(iOS 18, *) | ||
private struct KeepsScroll: ViewModifier { | ||
let step: Step | ||
let drawn: Bool | ||
@State private var position = ScrollPosition(edge: .top) | ||
/// The step scrolled back to where it was; until then, the offset the | ||
/// scroll view starts at (its top) is not kept over the one it had. | ||
@State private var restored: ObjectIdentifier? | ||
| ||
func body(content: Content) -> some View { | ||
content | ||
.scrollPosition($position) | ||
.onScrollGeometryChange(for: CGFloat.self) { $0.contentOffset.y + $0.contentInsets.top } action: { _, y in | ||
if restored == ObjectIdentifier(step) { step.offset = max(y, 0) } | ||
} | ||
.task(id: Restore(step: ObjectIdentifier(step), drawn: drawn)) { | ||
guard drawn, restored != ObjectIdentifier(step) else { return } | ||
// Once what it draws is laid out, so there is somewhere to go. | ||
await Task.yield() | ||
if step.offset > 0 { position.scrollTo(y: step.offset) } | ||
restored = ObjectIdentifier(step) | ||
} | ||
} | ||
| ||
private struct Restore: Hashable { | ||
let step: ObjectIdentifier | ||
let drawn: Bool | ||
} | ||
} | ||