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

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: a screen tapped open opens on the first tap

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

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

vendor/hud/web/renderer/src/view/taps.ts+15−7
@@ -1,20 +1,24 @@
// A tap is a touch that stays put on something still. A click that ends a
// touch which moved more than a few pixels, or that came down within a
// moment of what holds a list scrolling (a tap that stops a fling, which a
// touch which moved more than a few pixels, or that came down while what
// holds a list was still scrolling (a tap that stops a fling, which a
// phone's browser may end as a click on whatever scrolled under it), is no
// tap: `strays`, on a list, drops it before it reaches the item, its link or
// its buttons. A mouse's clicks and a keyboard's are left as they are. Its
// its buttons. A scroller is still scrolling until the browser says it came
// to rest (`scrollend`) or it has not moved for a frame or so: one gliding
// moves every frame, so a tap once the glide has stopped, however soon,
// opens. A mouse's clicks and a keyboard's are left as they are. Its
// listeners are the browser's alone: attached as a list is, never on a server.
/** How far a touch may move and still be a tap, in CSS pixels. */
const SLOP = 10;
/** How long after a scroller moved a touch on it is still taken as stopping it. */
const SETTLE = 300;
/** How long a scroller that has not moved may still be scrolling: one gliding moves every frame (a 30 Hz one too), so longer is a scroll at rest. */
const MOVING = 100;
/** The touch last put down: where, when, and whether it has moved past the slop or been taken for a scroll. */
let down: { x: number; y: number; at: number; touch: boolean; moved: boolean } | null = null;
/** When each scroller last moved, by its event's target (the document for the page's own). */
/** When each scroller last moved, and last came to rest where the browser says so, by its event's target (the document for the page's own). */
const scrolled = new WeakMap<EventTarget, number>();
const rested = new WeakMap<EventTarget, number>();
let listening = false;
function listen() {
@@ -38,6 +42,8 @@ function listen() {
// The browser took the touch for a scroll.
window.addEventListener('pointercancel', () => down && (down.moved = true), options);
window.addEventListener('scroll', (event) => event.target && scrolled.set(event.target, event.timeStamp), options);
// The browser says it came to rest, where it does (a touch that stops a glide brings one too, after it came down).
window.addEventListener('scrollend', (event) => event.target && rested.set(event.target, event.timeStamp), options);
}
/** Whether `event`, a click in `list`, ends a touch that was no tap. */
@@ -47,7 +53,9 @@ function stray(list: Element, event: MouseEvent): boolean {
if (down.moved || Math.hypot(event.clientX - down.x, event.clientY - down.y) > SLOP) return true;
for (let at: Node | null = list; at; at = at.parentNode) {
const moved = scrolled.get(at);
if (moved !== undefined && moved > down.at - SETTLE) return true;
const rest = rested.get(at);
const resting = rest !== undefined && moved !== undefined && rest >= moved && rest <= down.at;
if (moved !== undefined && moved > down.at - MOVING && !resting) return true;
}
return false;
}
vendor/hud/web/shell/src/Nav.svelte+11−4
@@ -359,8 +359,10 @@
}
/* A rail: the same items, icons alone in a column of 52px squares, each
label a tooltip beside it as it is hovered or focused; the wordmark
its first letter; the links left out. */
label a tooltip beside it as it is hovered (where a pointer hovers: a
touch screen's first tap would only show it, as iOS takes a hover that
shows something) or focused; the wordmark its first letter; the links
left out. */
@container hud-nav (max-width: 160px) {
.nav {
align-items: center;
@@ -412,13 +414,18 @@
transition: opacity 0.12s;
}
.item:hover .label,
.item:focus-visible .label,
.action:hover .label,
.action:focus-visible .label {
opacity: 1;
}
@media (hover: hover) {
.item:hover .label,
.action:hover .label {
opacity: 1;
}
}
.pitch,
.links {
display: none;
vendor/hud/web/shell/src/Shell.svelte+6−3
@@ -253,7 +253,8 @@
return root ? { ...here, calls: [root, ...here.calls.slice(1)] } : here;
}
/** The history entry the app last made, as JSON: the stack is already where it says. */
/** The history entry the app last made or came to (`made`, as JSON): the stack is already where it says. Read in place of `navigation.here`, which a router may set only once its move settles: an answer that lands before then (one read ahead, already there as its screen opens) teaching handles (`renamed`) would otherwise put the entry before back over the one just made, the screen tapped open gone again. */
let entered: Here | undefined = undefined;
let made = '';
/** A place as history keeps it: each call less its `compose` (routes.ts's `plain`), the pager's too, so going back or forward to it, or loading it again, opens no form. */
@@ -266,12 +267,13 @@
/** A history entry for a tab's place: pushed, or in place of the one on screen; a lone root has no screen under it to go up to. */
async function enter(tab: number, place: Place, how: Move) {
const was = navigation.here;
const was = entered ?? navigation.here;
const under = place.calls.length > 1 || place.pager !== null || Boolean(place.sheet);
const up = under && (how === 'open' || (how === 'replace' && isHere(was) && was.up));
const here: Here = { tab, ...plainPlace($state.snapshot(place)), up };
const url = urlOf(tab, here);
path = url;
entered = here;
made = JSON.stringify(here);
await navigation.go(url, here, how === 'replace');
}
@@ -287,7 +289,7 @@
/** Accounts' handles learnt: the URL on screen names them. */
function renamed() {
const here = navigation.here;
const here = entered ?? navigation.here;
if (!isHere(here)) return;
const url = urlOf(here.tab, here);
if (url !== path) void enter(here.tab, here, 'replace');
@@ -459,6 +461,7 @@
if (!isHere(here) || here.tab >= app.tabs.length) return;
const said = JSON.stringify(here);
if (said === made) return;
entered = here;
made = said;
untrack(() => {
path = location.pathname + location.search;
vendor/hud/COMMIT+1−1
@@ -1 +1 @@
d36a4eb6feae2ce5b7bd90d4d75e1cbc452cf219
2318f428b3e8fedf70b6805b460a0be779d2c992