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:
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user