Swiping between items shows the next one's picture with its text (#471)

The preview a swipe draws beside the reader was built as the drag
began, so its pictures started loading then: its text showed first and
the picture popped in a moment later, flashing and pushing the text
down under the finger. Reported from the iOS app on an item with a
picture at its top.

The pictures of the items either side of the one open are now fetched
and decoded when it opens (a few each, parsed with DOMParser, which
loads nothing itself), so the preview draws them at once. And the end
of a swipe keeps the preview over the reader until the new item's
pictures are decoded, at most 300 ms, instead of swapping in the same
moment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 00:52:39 +00:00
parent 2b06db9d26
commit f652e6906b
3 changed files with 27 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Swiping between items on a phone no longer flashes: the pictures of the items either side are loaded ahead, so the preview under your finger shows its picture with its text, and the swipe ends only once the new item's pictures are ready (#471).
- Deleting a downloaded file, marking everything read, deleting a signal and the other actions that ask first now ask in the page's own dialog, so they go ahead in the iOS app, which answered the browser's question Cancel without showing it (#462).
- A page kept for offline from before a deploy, shown on waking before the network was back, is loaded again rather than run with the new script, which left it dead until reloaded by hand (#449).
- On a phone the totals along the bottom (All Subscriptions: N items, N unread) are text alone, centred just above the home indicator, instead of a band and rule that ran to the bottom edge and were cut off by the screen's rounded corners (#424).

View File

@@ -148,7 +148,31 @@ function slideOn(dx: number, go: () => void){
const to = dir * (w + (beside(dx).className === 'dim' ? 0 : GAP));
const ms = still() ? 0 : Math.round(Math.max(120, 250 * (1 - Math.abs(dx) / (w || 1))));
slide(to, ms);
setTimeout(() => { go(); slide(0, 0); }, ms);
// The preview stays over the reader until the new item's pictures are drawn (#471): swapped at
// once, its text came a frame before the picture above it, and flashed where the picture would be.
setTimeout(() => { go(); drawn($('#detail'), 300).then(() => { if(!touch) slide(0, 0); }); }, ms);
}
/// The pictures of the items either side of the one open, fetched and decoded ahead (#471): the
/// preview a swipe draws is built as the drag begins, and its picture loaded only then came in
/// after its text, flashing and pushing the text down under the finger. Held here, so the browser
/// keeps them decoded; a few each, since only the top of an item shows in the preview.
let warm: HTMLImageElement[] = [];
function warmNeighbours(){
if(!narrow()) return;
const i = S.entries.findIndex(x => entryKey(x) === S.sel);
const html = [S.entries[i - 1], S.entries[i + 1]].filter(e => e).map(e => textOf(e!)).join('');
// Parsed, not put in the page: a document from DOMParser loads none of its pictures.
const srcs = [...new DOMParser().parseFromString(html, 'text/html').images].slice(0, 6).map(i => i.src);
warm = srcs.map(src => { const im = new Image(); im.src = src; im.decode().catch(() => {}); return im; });
}
/// When the pictures in `el` are decoded and ready to draw, or `max` ms, whichever is sooner, so a
/// slow picture never holds up the page.
function drawn(el: HTMLElement | null, max: number): Promise<unknown> {
const pending = [...el?.querySelectorAll('img') ?? []].filter(i => !i.complete || !i.naturalWidth);
if(!pending.length) return Promise.resolve();
return Promise.race([Promise.all(pending.map(i => i.decode().catch(() => {}))), new Promise(r => setTimeout(r, max))]);
}
document.addEventListener('touchend', () => {

View File

@@ -335,6 +335,7 @@ function selectEntry(e: Entry,turning=false){
showDetail(e);
const d=$('#detail'); if(d) d.scrollTop=0;
if(turning) loadAhead();
warmNeighbours();
}
/// Where the next page starts. On the Unread tab the items read here are no longer unread on the