Fix live swipe paging and retain tilt preference on iOS
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 29s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 29s
Replace the damped single-screen fade with live mobile panels on a shared composited rail, preserving per-tab scrolling and pausing offscreen physics. Center macro text and separate the saved tilt switch from session motion permission, resuming permission from a normal interaction. Validate live previews, interruption and multi-touch cancellation, relaunch, and permission races.
This commit is contained in:
parent
7288e56c02
commit
3c0d6560f1
15 changed files with 784 additions and 263 deletions
|
|
@ -3,7 +3,7 @@
|
|||
(() => {
|
||||
const checks = {};
|
||||
const font = (element) => getComputedStyle(element).fontSize.split('px')[0] * 1;
|
||||
const visible = (selector) => [...document.querySelectorAll(selector)].filter(e => e.getBoundingClientRect().width > 0);
|
||||
const visible = (selector) => [...document.querySelectorAll(selector)].filter(e => e.getBoundingClientRect().width > 0 && !e.closest('.page-panel[aria-hidden="true"]'));
|
||||
const dialog = document.querySelector('dialog[open]');
|
||||
checks.noHorizontalPageOverflow = document.documentElement.scrollWidth <= window.innerWidth + 1;
|
||||
if (!dialog && visible('.dashboard-grid').length) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
(async () => {
|
||||
const checks = {};
|
||||
const pause = (ms = 380) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
const visible = selector => [...document.querySelectorAll(selector)].filter(e => e.getBoundingClientRect().width > 0);
|
||||
const visible = selector => [...document.querySelectorAll(selector)].filter(e => e.getBoundingClientRect().width > 0 && !e.closest('.page-panel[aria-hidden="true"]'));
|
||||
const page = () => document.querySelector('main').getAttribute('aria-label');
|
||||
const nav = async label => {
|
||||
visible('.bottom-nav button').find(e => e.textContent.trim() === label).click();
|
||||
|
|
|
|||
65
tests/browser/swipe-preview.check.js
Normal file
65
tests/browser/swipe-preview.check.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Run on an unlocked phone-size localhost preview using Runtime.evaluate with
|
||||
// awaitPromise. Reproduces the visible adjacent screen and centered macro text.
|
||||
(async () => {
|
||||
const checks = {};
|
||||
const target = document.querySelector('.orb');
|
||||
const rect = target.getBoundingClientRect();
|
||||
const x = innerWidth / 2;
|
||||
const y = rect.y + rect.height / 2;
|
||||
const emit = (type, dx, ended = false) => {
|
||||
const touch = new Touch({ identifier: 21, target, clientX: x + dx, clientY: y });
|
||||
target.dispatchEvent(new TouchEvent(type, { bubbles: true, cancelable: true, touches: ended ? [] : [touch], changedTouches: [touch] }));
|
||||
};
|
||||
emit('touchstart', 0);
|
||||
emit('touchmove', -70);
|
||||
emit('touchmove', -140);
|
||||
await new Promise(requestAnimationFrame);
|
||||
await new Promise(requestAnimationFrame);
|
||||
const nextHeading = [...document.querySelectorAll('h1')].find(e => e.textContent.includes('Library'));
|
||||
const next = nextHeading?.getBoundingClientRect();
|
||||
checks.nextScreenVisibleDuringDrag = Boolean(next && next.width > 0 && next.left > 0 && next.left < innerWidth);
|
||||
const current = target.getBoundingClientRect();
|
||||
checks.followsFingerWithoutDamping = Math.abs((rect.left - current.left) - 140) < 3;
|
||||
emit('touchcancel', -140, true);
|
||||
await new Promise(resolve => setTimeout(resolve, 380));
|
||||
emit('touchstart', 0);
|
||||
emit('touchmove', -100);
|
||||
await new Promise(requestAnimationFrame);
|
||||
const first = new Touch({ identifier: 21, target, clientX: x - 100, clientY: y });
|
||||
const second = new Touch({ identifier: 22, target, clientX: x + 10, clientY: y });
|
||||
target.dispatchEvent(new TouchEvent('touchstart', { bubbles: true, touches: [first, second], changedTouches: [second] }));
|
||||
target.dispatchEvent(new TouchEvent('touchend', { bubbles: true, touches: [], changedTouches: [first, second] }));
|
||||
await new Promise(resolve => setTimeout(resolve, 380));
|
||||
checks.multitouchDoesNotLeavePartialPage = Math.abs(target.getBoundingClientRect().left - rect.left) < 2;
|
||||
const libraryButton = [...document.querySelectorAll('.bottom-nav button')].find(e => e.textContent.trim() === 'Library');
|
||||
libraryButton.click();
|
||||
await new Promise(requestAnimationFrame);
|
||||
const viewport = document.querySelector('main');
|
||||
const rail = document.querySelector('.page-rail');
|
||||
const before = new DOMMatrixReadOnly(getComputedStyle(rail).transform).m41;
|
||||
const resumeTouch = (type, dx) => {
|
||||
const touch = new Touch({ identifier: 23, target: viewport, clientX: x + dx, clientY: y });
|
||||
viewport.dispatchEvent(new TouchEvent(type, { bubbles: true, cancelable: true, touches: type === 'touchcancel' ? [] : [touch], changedTouches: [touch] }));
|
||||
};
|
||||
resumeTouch('touchstart', 0);
|
||||
resumeTouch('touchmove', 40);
|
||||
await new Promise(requestAnimationFrame);
|
||||
await new Promise(requestAnimationFrame);
|
||||
const after = new DOMMatrixReadOnly(getComputedStyle(rail).transform).m41;
|
||||
const desired = before + 40;
|
||||
const expected = desired > 0 ? desired * .15 : desired;
|
||||
checks.interruptedSettleContinuesWithoutJump = Math.abs(after - expected) < 5;
|
||||
resumeTouch('touchcancel', 40);
|
||||
await new Promise(resolve => setTimeout(resolve, 380));
|
||||
[...document.querySelectorAll('.bottom-nav button')].find(e => e.textContent.trim() === 'Today').click();
|
||||
await new Promise(resolve => setTimeout(resolve, 380));
|
||||
checks.macroNumbersCentered = [...document.querySelectorAll('.macro')].filter(e => e.getBoundingClientRect().width > 0).every(macro => {
|
||||
const value = macro.querySelector('div:not(.progress-track)');
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(value);
|
||||
const text = range.getBoundingClientRect();
|
||||
const track = macro.querySelector('.progress-track').getBoundingClientRect();
|
||||
return Math.abs(text.x + text.width / 2 - track.x - track.width / 2) < 2;
|
||||
});
|
||||
return { pass: Object.values(checks).every(Boolean), checks };
|
||||
})()
|
||||
111
tests/tilt.test.js
Normal file
111
tests/tilt.test.js
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import vm from "node:vm";
|
||||
import ts from "typescript";
|
||||
|
||||
// Reload the real hook module with an iOS-style permission API and the same
|
||||
// device storage. The hook snapshot is the value bound to the Settings switch.
|
||||
function launch(storage, permission = async () => "granted") {
|
||||
const exports = {};
|
||||
const effects = [];
|
||||
const document = new EventTarget();
|
||||
const context = {
|
||||
exports,
|
||||
require: () => ({
|
||||
useSyncExternalStore: (_subscribe, snapshot) => snapshot(),
|
||||
useEffect: (effect) => effects.push(effect),
|
||||
}),
|
||||
DeviceOrientationEvent: class {
|
||||
static requestPermission = permission;
|
||||
},
|
||||
localStorage: {
|
||||
getItem: (key) => storage.get(key) ?? null,
|
||||
setItem: (key, value) => storage.set(key, value),
|
||||
},
|
||||
document,
|
||||
};
|
||||
vm.runInNewContext(
|
||||
ts.transpileModule(
|
||||
readFileSync(new URL("../src/useTilt.ts", import.meta.url), "utf8"),
|
||||
{
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
},
|
||||
},
|
||||
).outputText,
|
||||
context,
|
||||
);
|
||||
return { api: exports, document, effects, snapshot: () => exports.useTilt() };
|
||||
}
|
||||
|
||||
test("saved tilt stays switched on when an iOS PWA is relaunched", async () => {
|
||||
const storage = new Map();
|
||||
const first = launch(storage);
|
||||
await first.snapshot().toggleTilt();
|
||||
assert.equal(first.snapshot().enabled, true);
|
||||
assert.equal(storage.get("calio-tilt"), "true");
|
||||
const reopened = launch(storage);
|
||||
assert.equal(
|
||||
reopened.snapshot().enabled,
|
||||
true,
|
||||
"A session permission check must not reset the saved switch",
|
||||
);
|
||||
});
|
||||
|
||||
test("explicitly switching tilt off stays off after reopening", async () => {
|
||||
const storage = new Map();
|
||||
const first = launch(storage);
|
||||
await first.snapshot().toggleTilt();
|
||||
await first.snapshot().toggleTilt();
|
||||
assert.equal(launch(storage).snapshot().enabled, false);
|
||||
});
|
||||
|
||||
test("the first app interaction resumes iOS motion without toggling the preference", async () => {
|
||||
let calls = 0;
|
||||
const reopened = launch(new Map([["calio-tilt", "true"]]), async () => {
|
||||
calls++;
|
||||
return "granted";
|
||||
});
|
||||
assert.equal(reopened.snapshot().status, "permission");
|
||||
reopened.api.useTiltResume(true);
|
||||
const cleanup = reopened.effects[0]();
|
||||
reopened.document.dispatchEvent(new Event("pointerup"));
|
||||
reopened.document.dispatchEvent(new Event("touchend"));
|
||||
await reopened.snapshot().requestTiltPermission();
|
||||
assert.equal(
|
||||
calls,
|
||||
1,
|
||||
"Overlapping pointer/touch events must share one request",
|
||||
);
|
||||
assert.equal(reopened.snapshot().enabled, true);
|
||||
assert.equal(reopened.snapshot().status, "enabled");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("denial preserves the preference and a late permission grant cannot undo switching off", async () => {
|
||||
const denied = launch(
|
||||
new Map([["calio-tilt", "true"]]),
|
||||
async () => "denied",
|
||||
);
|
||||
await denied.snapshot().requestTiltPermission();
|
||||
assert.equal(denied.snapshot().enabled, true);
|
||||
assert.equal(denied.snapshot().status, "denied");
|
||||
let grant;
|
||||
const storage = new Map();
|
||||
const pending = launch(
|
||||
storage,
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
grant = resolve;
|
||||
}),
|
||||
);
|
||||
const enabling = pending.snapshot().toggleTilt();
|
||||
await pending.snapshot().toggleTilt();
|
||||
grant("granted");
|
||||
await enabling;
|
||||
assert.equal(pending.snapshot().enabled, false);
|
||||
assert.equal(pending.snapshot().status, "off");
|
||||
assert.equal(storage.get("calio-tilt"), "false");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue