Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: stepping on from a zoomed photo starts the next one at its fit

Yashwanth Kamireddi9d3abcf9b24c
diff --git a/.uiverify/photos-zoom-step.mjs b/.uiverify/photos-zoom-step.mjs
new file mode 100644
index 0000000..5a3e77b
--- /dev/null
+++ b/.uiverify/photos-zoom-step.mjs
@@ -0,0 +1,42 @@
+// Stepping on from a zoomed photo shows the next one at its fit, and never asks for the next
+// one's full-size original: the zoom stayed on for the render that drew the next photo, so the
+// whole original (for a HEIC, downloaded and decoded) was asked for and never looked at.
+//
+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/photos-zoom-step.mjs
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const BASE = process.env.URL ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await page.goto(BASE, { waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(500);
+await page.locator('.px-tile[data-id="p1"]').dblclick();
+await page.waitForTimeout(400);
+await page.keyboard.press("z");
+await page.waitForTimeout(400);
+ok(/scale\(/.test(await page.locator(".px-pan").evaluate((e) => e.style.transform)), "Z zooms in");
+await page.evaluate(() => {
+ window.__sharp = [];
+ new MutationObserver((list) => {
+ for (const m of list) for (const n of m.addedNodes) {
+ if (n.nodeType !== 1) continue;
+ for (const img of [n, ...n.querySelectorAll("img")]) if (img.classList?.contains("px-sharp")) window.__sharp.push(img.getAttribute("src"));
+ }
+ }).observe(document.body, { childList: true, subtree: true });
+});
+await page.keyboard.press("ArrowRight");
+const now = await page.evaluate(() => ({ transform: document.querySelector(".px-pan")?.style.transform ?? null, zoomedClass: document.querySelector(".px-pan")?.classList.contains("is-zoomed") }));
+await page.waitForTimeout(400);
+const sharp = await page.evaluate(() => window.__sharp);
+ok(!sharp.some((s) => /p2/.test(decodeURIComponent(s ?? ""))), `the next photo's original is never asked for ${JSON.stringify(sharp)}`);
+ok(!now.zoomedClass && now.transform === "", `the next photo is not drawn zoomed, from its first frame ${JSON.stringify(now)}`);
+ok((await page.locator(".px-pan").evaluate((e) => e.style.transform)) === "", "and it settles at its fit");
+await b.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index f4ffb6a..efbde6c 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -1100,7 +1100,11 @@ export function PhotosView() {
// frame, so a pan or a pinch never redraws the screen (which made it crawl). Only crossing
// into or out of zoom is state — the cursor and the double-click's meaning change with it.
const lensRef = useRef({ k: 1, x: 0, y: 0 });
- const [zoomed, setZoomed] = useState(false);
+ // The photo the zoom is on: stepping to the next one draws it at its fit from its first
+ // render. As a plain flag it stayed on for that render, and the next photo's whole original
+ // was asked for (for a HEIC, downloaded and decoded) before the zoom was put back.
+ const [zoomedId, setZoomedId] = useState<string | null>(null);
+ const zoomed = zoomedId !== null && zoomedId === shown?.id;
const pan = useRef<HTMLDivElement | null>(null);
const frame = useRef<number | null>(null);
// What is on the screen now, and a glide on its way to the lens.
@@ -1121,7 +1125,7 @@ export function PhotosView() {
};
const paint = (next: { k: number; x: number; y: number }, glide = false) => {
lensRef.current = next;
- setZoomed(next.k > 1);
+ setZoomedId(next.k > 1 ? (shown?.id ?? null) : null);
if (gliding.current !== null) {
cancelAnimationFrame(gliding.current);
gliding.current = null;
@@ -1343,9 +1347,16 @@ export function PhotosView() {
const next = Math.max(1, Math.min(5, k));
paint(bound(next, dx - next * px, dy - next * py), glide);
};
- useEffect(() => {
- unzoom(false);
- }, [shown?.id]);
+ // Back to the fit as another photo comes up, before it is drawn: put back a frame later,
+ // the next photo was painted first at the last one's zoom and pan.
+ useLayoutEffect(() => {
+ if (gliding.current !== null) cancelAnimationFrame(gliding.current);
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
+ gliding.current = frame.current = null;
+ lensRef.current = { k: 1, x: 0, y: 0 };
+ draw(lensRef.current);
+ setZoomedId(null);
+ }, [shown?.id]); // eslint-disable-line react-hooks/exhaustive-deps
// The stage, measured as it opens and as the window is resized: the picture the viewer shows
// is made for its size (viewSrc), and asked for again only when that size crosses a step.
const [, setStep] = useState("");