diff --git a/src/components/MainWindow.tsx b/src/components/MainWindow.tsx index 04a3c7b..c4c0903 100644 --- a/src/components/MainWindow.tsx +++ b/src/components/MainWindow.tsx @@ -138,26 +138,80 @@ const THUMB_EXTENSIONS = [ "avif", ]; +/** + * True while a row sits near the list's viewport, so its picture is wanted. + * + * `loading="lazy"` is on the image as well, and it does the half of the job: measured + * in WKWebView against a 250-row library of real screenshots, only 13 of the 250 + * pictures were decoded at rest. What it never does is give one back. Flicking to the + * bottom of the same list took the decoded count from 13 to 136 and no lower, because + * lazy decides when to fetch and never when to forget, so the library's peak memory + * still tracks how far the user has scrolled rather than what is on screen. + * + * Dropping the element when the row leaves view is what closes that half: the same + * scroll-through holds a flat window of about twenty decoded pictures instead of + * accumulating one bitmap per row visited. The file is untouched on disk, so scrolling + * back re-decodes it, which is a fetch of a 42px box and not something to protect + * against. + */ +function useRowIsInView() { + const ref = useRef(null); + const [inView, setInView] = useState(false); + useEffect(() => { + const node = ref.current; + if (!node || typeof IntersectionObserver === "undefined") { + // Without the observer there is no way to know what is off screen, so assume + // the row matters and keep the thumbnail the way it always behaved. + setInView(true); + return; + } + // The root has to be the list itself, not the viewport: rows below the fold are + // hidden by the list's `overflow-y: auto`, and an ancestor's clip is applied + // before the root box is consulted, so measuring against the viewport would make + // the margin do nothing and a fast scroll would show glyph icons until the row + // actually arrived. Against the scroller the margin really does reach seven rows + // ahead, which is what keeps a flick through the library showing pictures. + const observer = new IntersectionObserver( + (entries) => setInView(entries.some((entry) => entry.isIntersecting)), + { root: node.closest(".home-recent-list"), rootMargin: "320px 0px" }, + ); + observer.observe(node); + return () => observer.disconnect(); + }, []); + return [ref, inView] as const; +} + function RecentThumb({ item }: { item: RecentItem }) { const [failed, setFailed] = useState(false); + const [ref, inView] = useRowIsInView(); const extension = extensionOf(item.path); - const showImage = item.kind === "image" && THUMB_EXTENSIONS.includes(extension) && !failed; + const showImage = + item.kind === "image" && THUMB_EXTENSIONS.includes(extension) && !failed && inView; - if (showImage) { - return ( - + return ( + + {/* A favourite has to announce itself without a hover: the star that sets it + lives in the action cluster, which is invisible until the pointer arrives, + so a favourited file looked exactly like an ordinary one across a list you + keep precisely because its entries outlive the files they point at. It rides + the thumbnail rather than the name so no row is pushed sideways, and it is + drawn here rather than only over a decoded picture so a video, a document, + or an off-screen row carries it too. */} + {item.pinned ? ( + + ) : null} + {showImage ? ( setFailed(true)} /> - - ); - } - return ( - - {item.kind === "image" ? ( + ) : item.kind === "image" ? ( + // Off screen, or a picture that refused to decode: the kind glyph stands in, + // which is the same face the row has always shown before a thumbnail loads. ) : item.kind === "video" ? ( diff --git a/src/styles.css b/src/styles.css index 46b0a62..71ab0e9 100644 --- a/src/styles.css +++ b/src/styles.css @@ -4220,6 +4220,38 @@ body[data-view="radial"] .share-backdrop { box-shadow: inset 0 0 0 1.5px rgba(240, 79, 36, 0.55); } +/* The favourite's own mark, on the leading corner of the thumbnail. + + The star that sets a favourite lives in the row's action cluster, and that cluster + is `opacity: 0` until the pointer arrives, so across a list whose whole point is + outliving the files it names, a favourited file looked exactly like an ordinary one + until you hovered it. This mark is the half of the state that survives without a + hover; the inset ring above stays as the quiet half. + + It hangs from the row rather than the thumbnail: the icon box is `overflow: hidden` + to clip pictures to its rounded corners, so a badge on that box would be cut off. + The row is already `position: relative`, and its own padding is the gutter the badge + sits in, which is why no thumbnail in the list has to move over it. On its own disc + it stays readable over a picture that happens to be dark, which a bare star would + not. */ +.home-recent-favorite { + position: absolute; + top: 3px; + left: 3px; + z-index: 1; + display: grid; + place-items: center; + width: 15px; + height: 15px; + border-radius: 999px; + color: #e8891b; + background: rgba(255, 252, 249, 0.94); + box-shadow: 0 1px 3px rgba(60, 33, 18, 0.24); + /* The badge belongs to the row, not to the pointer: neither opening the file nor + dragging the row out of Shift may be interrupted by it. */ + pointer-events: none; +} + .home-card-clear { flex: none; margin-left: -4px;