PullDownToRefresh: reset the state if invisible
All checks were successful
/ depoly (push) Successful in 1m13s

This commit is contained in:
thislight 2024-10-09 15:15:22 +08:00
parent ee39cf8651
commit 49b7f2891b
No known key found for this signature in database
GPG key ID: A50F9451AC56A63E

View file

@ -28,7 +28,7 @@ const PullDownToRefresh: Component<{
let rootElement: HTMLDivElement;
const [pullDown, setPullDown] = createSignal(0);
const stopPos = () => 160
const stopPos = () => 160;
const indicatorOfsY = () => {
if (props.loading) {
@ -43,12 +43,16 @@ const PullDownToRefresh: Component<{
const rootVisible = obvx(() => rootElement);
createEffect(() => {
if (!rootVisible()) setPullDown(0);
});
let released = true;
let v = 0;
let lts = -1;
let ds = 0;
let holding = false;
const K = 5;
const K = 10;
const updatePullDown = (ts: number) => {
released = false;
try {
@ -90,9 +94,10 @@ const PullDownToRefresh: Component<{
const handleLinkedWheel = (event: WheelEvent) => {
const scrollTop = (event.target as HTMLElement).scrollTop;
if (scrollTop >= 0 && scrollTop < 1) {
event.preventDefault()
const d = untrack(pullDown);
if (event.deltaY <= 0 || d > 0) event.preventDefault();
ds = -(event.deltaY / window.devicePixelRatio / 2);
holding = untrack(pullDown) < stopPos();
holding = d < stopPos();
if (wheelTimeout) {
clearTimeout(wheelTimeout);
}
@ -124,15 +129,16 @@ const PullDownToRefresh: Component<{
return;
}
const item = event.targetTouches.item(0)!;
event.preventDefault();
if (untrack(pullDown) > 0) event.preventDefault();
if (lastTouchId && item.identifier !== lastTouchId) {
lastTouchId = undefined;
lastTouchScreenY = 0;
return;
}
holding = true;
if (lastTouchScreenY !== 0) {
ds = (item.screenY - lastTouchScreenY) ;
ds = item.screenY - lastTouchScreenY;
}
lastTouchScreenY = item.screenY;
if (released) {
@ -145,7 +151,11 @@ const PullDownToRefresh: Component<{
lastTouchId = undefined;
lastTouchScreenY = 0;
holding = false;
if (untrack(indicatorOfsY) >= 160 && !props.loading && props.onRefresh) {
if (
untrack(indicatorOfsY) >= stopPos() &&
!props.loading &&
props.onRefresh
) {
setTimeout(props.onRefresh, 0);
} else {
if (released) {