mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-13 03:43:48 +08:00
are your fingies fixed
This commit is contained in:
@@ -113,19 +113,25 @@ initRouter()
|
|||||||
|
|
||||||
const scheduleRestore = () => {
|
const scheduleRestore = () => {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
timer = setTimeout(() => setScrolling(false), 120)
|
const scrollY = window.scrollY
|
||||||
|
// Finger release and completion notifications can precede the last movement.
|
||||||
|
// Keep glass disabled until the scroll position has also settled.
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
if (window.scrollY !== scrollY) scheduleRestore()
|
||||||
|
else setScrolling(false)
|
||||||
|
}, 120)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("scroll", () => {
|
document.addEventListener("scroll", () => {
|
||||||
scrollEnded = false
|
scrollEnded = false
|
||||||
setScrolling(true)
|
setScrolling(true)
|
||||||
|
clearTimeout(timer)
|
||||||
if (!nativeScrollEnd) scheduleRestore()
|
if (!nativeScrollEnd) scheduleRestore()
|
||||||
}, { passive: true })
|
}, { passive: true })
|
||||||
|
|
||||||
document.addEventListener("scrollend", () => {
|
document.addEventListener("scrollend", () => {
|
||||||
scrollEnded = true
|
scrollEnded = true
|
||||||
clearTimeout(timer)
|
scheduleRestore()
|
||||||
setScrolling(false)
|
|
||||||
}, { passive: true })
|
}, { passive: true })
|
||||||
|
|
||||||
window.addEventListener("touchstart", (e) => {
|
window.addEventListener("touchstart", (e) => {
|
||||||
@@ -135,8 +141,7 @@ initRouter()
|
|||||||
|
|
||||||
const releaseTouches = (e) => {
|
const releaseTouches = (e) => {
|
||||||
for (const touch of e.changedTouches) touches.delete(touch.identifier)
|
for (const touch of e.changedTouches) touches.delete(touch.identifier)
|
||||||
if (scrollEnded) setScrolling(false)
|
if (!touches.size && (scrollEnded || !nativeScrollEnd)) scheduleRestore()
|
||||||
else if (!nativeScrollEnd && !touches.size) scheduleRestore()
|
|
||||||
}
|
}
|
||||||
window.addEventListener("touchend", releaseTouches, { passive: true })
|
window.addEventListener("touchend", releaseTouches, { passive: true })
|
||||||
window.addEventListener("touchcancel", releaseTouches, { passive: true })
|
window.addEventListener("touchcancel", releaseTouches, { passive: true })
|
||||||
|
|||||||
@@ -553,6 +553,10 @@ const handlers = { document: {}, window: {} };
|
|||||||
const classes = new Set();
|
const classes = new Set();
|
||||||
const timers = new Map();
|
const timers = new Map();
|
||||||
let nextTimer = 0;
|
let nextTimer = 0;
|
||||||
|
const window = {
|
||||||
|
scrollY: 0,
|
||||||
|
addEventListener: (name, fn) => { handlers.window[name] = fn; },
|
||||||
|
};
|
||||||
class Element {
|
class Element {
|
||||||
constructor(modal = false) { this.modal = modal; }
|
constructor(modal = false) { this.modal = modal; }
|
||||||
closest() { return this.modal ? this : null; }
|
closest() { return this.modal ? this : null; }
|
||||||
@@ -566,7 +570,7 @@ const document = {
|
|||||||
if (native) document.onscrollend = null;
|
if (native) document.onscrollend = null;
|
||||||
vm.runInNewContext(source.slice(source.indexOf('// Disable card blur'), source.indexOf('// Layer 2')), {
|
vm.runInNewContext(source.slice(source.indexOf('// Disable card blur'), source.indexOf('// Layer 2')), {
|
||||||
document, Element,
|
document, Element,
|
||||||
window: { addEventListener: (name, fn) => { handlers.window[name] = fn; } },
|
window,
|
||||||
setTimeout: fn => { timers.set(++nextTimer, fn); return nextTimer; },
|
setTimeout: fn => { timers.set(++nextTimer, fn); return nextTimer; },
|
||||||
clearTimeout: id => timers.delete(id),
|
clearTimeout: id => timers.delete(id),
|
||||||
});
|
});
|
||||||
@@ -575,6 +579,20 @@ const fire = (scope, name, ids = [], modal = false) => handlers[scope][name]?.({
|
|||||||
});
|
});
|
||||||
const tick = () => { const pending = [...timers.values()]; timers.clear(); pending.forEach(fn => fn()); };
|
const tick = () => { const pending = [...timers.values()]; timers.clear(); pending.forEach(fn => fn()); };
|
||||||
const active = () => classes.has('is-scrolling');
|
const active = () => classes.has('is-scrolling');
|
||||||
|
// Inertial movement can continue between delivered scroll events after release.
|
||||||
|
fire('window', 'touchstart', [10]);
|
||||||
|
fire('document', 'scroll');
|
||||||
|
fire('window', 'touchend', [10]);
|
||||||
|
if (native) fire('document', 'scrollend');
|
||||||
|
window.scrollY = 100;
|
||||||
|
tick();
|
||||||
|
assert.equal(active(), true, 'finger release must not end momentum scrolling');
|
||||||
|
window.scrollY = 160;
|
||||||
|
tick();
|
||||||
|
assert.equal(active(), true, 'continued movement must keep blur disabled');
|
||||||
|
tick();
|
||||||
|
assert.equal(active(), false, 'restore after completion and a stable position');
|
||||||
|
fire('document', 'scrollend');
|
||||||
fire('window', 'wheel');
|
fire('window', 'wheel');
|
||||||
assert.equal(active(), false, 'wheel without document movement');
|
assert.equal(active(), false, 'wheel without document movement');
|
||||||
fire('window', 'touchstart', [1, 2]);
|
fire('window', 'touchstart', [1, 2]);
|
||||||
@@ -588,12 +606,23 @@ fire('window', 'touchcancel', [2]);
|
|||||||
tick();
|
tick();
|
||||||
assert.equal(active(), native, 'native completion must be authoritative');
|
assert.equal(active(), native, 'native completion must be authoritative');
|
||||||
fire('document', 'scrollend');
|
fire('document', 'scrollend');
|
||||||
|
tick();
|
||||||
|
assert.equal(active(), false);
|
||||||
|
// More scroll events after a completion signal invalidate its pending restore.
|
||||||
|
fire('document', 'scroll');
|
||||||
|
fire('document', 'scrollend');
|
||||||
|
fire('document', 'scroll');
|
||||||
|
tick();
|
||||||
|
assert.equal(active(), native, 'new scrolling cancels the previous native completion');
|
||||||
|
fire('document', 'scrollend');
|
||||||
|
tick();
|
||||||
assert.equal(active(), false);
|
assert.equal(active(), false);
|
||||||
fire('window', 'touchstart', [4]);
|
fire('window', 'touchstart', [4]);
|
||||||
fire('document', 'scroll');
|
fire('document', 'scroll');
|
||||||
fire('document', 'scrollend');
|
fire('document', 'scrollend');
|
||||||
assert.equal(active(), true, 'hold survives completion');
|
assert.equal(active(), true, 'hold survives completion');
|
||||||
fire('window', 'touchend', [4]);
|
fire('window', 'touchend', [4]);
|
||||||
|
tick();
|
||||||
assert.equal(active(), false, 'release after completion cannot leave state stuck');
|
assert.equal(active(), false, 'release after completion cannot leave state stuck');
|
||||||
fire('document', 'scroll');
|
fire('document', 'scroll');
|
||||||
fire('window', 'hashchange');
|
fire('window', 'hashchange');
|
||||||
@@ -603,6 +632,7 @@ fire('document', 'scroll');
|
|||||||
tick();
|
tick();
|
||||||
assert.equal(active(), native, 'fallback only on unsupported browsers');
|
assert.equal(active(), native, 'fallback only on unsupported browsers');
|
||||||
fire('document', 'scrollend');
|
fire('document', 'scrollend');
|
||||||
|
tick();
|
||||||
assert.equal(active(), false);
|
assert.equal(active(), false);
|
||||||
"""
|
"""
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
|
|||||||
Reference in New Issue
Block a user