perf: mobile scroll, close #5191
parent
1418422bcf
commit
41fe8be1f6
|
@ -1,9 +1,7 @@
|
||||||
import supportsPassive from '../../_util/supportsPassive';
|
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { watch, onMounted } from 'vue';
|
import { onBeforeUnmount, watch, onMounted } from 'vue';
|
||||||
|
|
||||||
const SMOOTH_PTG = 14 / 15;
|
const SMOOTH_PTG = 14 / 15;
|
||||||
|
|
||||||
export default function useMobileTouchMove(
|
export default function useMobileTouchMove(
|
||||||
inVirtual: Ref<boolean>,
|
inVirtual: Ref<boolean>,
|
||||||
listRef: Ref<HTMLDivElement | undefined>,
|
listRef: Ref<HTMLDivElement | undefined>,
|
||||||
|
@ -19,15 +17,7 @@ export default function useMobileTouchMove(
|
||||||
|
|
||||||
const cleanUpEvents = () => {
|
const cleanUpEvents = () => {
|
||||||
if (element) {
|
if (element) {
|
||||||
element.removeEventListener(
|
element.removeEventListener('touchmove', onTouchMove);
|
||||||
'touchmove',
|
|
||||||
onTouchMove,
|
|
||||||
supportsPassive
|
|
||||||
? ({
|
|
||||||
passive: false,
|
|
||||||
} as EventListenerOptions)
|
|
||||||
: false,
|
|
||||||
);
|
|
||||||
element.removeEventListener('touchend', onTouchEnd);
|
element.removeEventListener('touchend', onTouchEnd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -68,47 +58,28 @@ export default function useMobileTouchMove(
|
||||||
touchY = Math.ceil(e.touches[0].pageY);
|
touchY = Math.ceil(e.touches[0].pageY);
|
||||||
|
|
||||||
element = e.target as HTMLElement;
|
element = e.target as HTMLElement;
|
||||||
element!.addEventListener(
|
element!.addEventListener('touchmove', onTouchMove, { passive: false });
|
||||||
'touchmove',
|
|
||||||
onTouchMove,
|
|
||||||
supportsPassive
|
|
||||||
? ({
|
|
||||||
passive: false,
|
|
||||||
} as EventListenerOptions)
|
|
||||||
: false,
|
|
||||||
);
|
|
||||||
element!.addEventListener('touchend', onTouchEnd);
|
element!.addEventListener('touchend', onTouchEnd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const noop = () => {};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
document.addEventListener('touchmove', noop, { passive: false });
|
||||||
watch(
|
watch(
|
||||||
inVirtual,
|
inVirtual,
|
||||||
val => {
|
val => {
|
||||||
listRef.value.removeEventListener(
|
listRef.value.removeEventListener('touchstart', onTouchStart);
|
||||||
'touchstart',
|
|
||||||
onTouchStart,
|
|
||||||
supportsPassive
|
|
||||||
? ({
|
|
||||||
passive: false,
|
|
||||||
} as EventListenerOptions)
|
|
||||||
: false,
|
|
||||||
);
|
|
||||||
cleanUpEvents();
|
cleanUpEvents();
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
if (val) {
|
if (val) {
|
||||||
listRef.value.addEventListener(
|
listRef.value.addEventListener('touchstart', onTouchStart, { passive: false });
|
||||||
'touchstart',
|
|
||||||
onTouchStart,
|
|
||||||
supportsPassive
|
|
||||||
? ({
|
|
||||||
passive: false,
|
|
||||||
} as EventListenerOptions)
|
|
||||||
: false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
document.removeEventListener('touchmove', noop);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue