fix: passive waring
parent
5b8bda9e51
commit
8d1669b889
|
@ -0,0 +1,13 @@
|
||||||
|
// Test via a getter in the options object to see if the passive property is accessed
|
||||||
|
let supportsPassive = false;
|
||||||
|
try {
|
||||||
|
let opts = Object.defineProperty({}, 'passive', {
|
||||||
|
get() {
|
||||||
|
supportsPassive = true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
window.addEventListener('testPassive', null, opts);
|
||||||
|
window.removeEventListener('testPassive', null, opts);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
export default supportsPassive;
|
|
@ -1,5 +1,6 @@
|
||||||
import addEventListener from '../vc-util/Dom/addEventListener';
|
import addEventListener from '../vc-util/Dom/addEventListener';
|
||||||
import { ComponentPublicInstance } from 'vue';
|
import { ComponentPublicInstance } from 'vue';
|
||||||
|
import supportsPassive from '../_util/supportsPassive';
|
||||||
|
|
||||||
export type BindElement = HTMLElement | Window | null | undefined;
|
export type BindElement = HTMLElement | Window | null | undefined;
|
||||||
export type Rect = ClientRect | DOMRect;
|
export type Rect = ClientRect | DOMRect;
|
||||||
|
@ -78,9 +79,14 @@ export function addObserveTarget(
|
||||||
// Add listener
|
// Add listener
|
||||||
TRIGGER_EVENTS.forEach(eventName => {
|
TRIGGER_EVENTS.forEach(eventName => {
|
||||||
entity!.eventHandlers[eventName] = addEventListener(target, eventName, () => {
|
entity!.eventHandlers[eventName] = addEventListener(target, eventName, () => {
|
||||||
entity!.affixList.forEach(targetAffix => {
|
entity!.affixList.forEach(
|
||||||
|
targetAffix => {
|
||||||
(targetAffix as any).lazyUpdatePosition();
|
(targetAffix as any).lazyUpdatePosition();
|
||||||
});
|
},
|
||||||
|
(eventName === 'touchstart' || eventName === 'touchmove') && supportsPassive
|
||||||
|
? ({ passive: true } as EventListenerOptions)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
transformArguments,
|
transformArguments,
|
||||||
isNumeric,
|
isNumeric,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
import supportsPassive from '../../_util/supportsPassive';
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
@ -100,18 +101,7 @@ const Drawer = defineComponent({
|
||||||
mounted() {
|
mounted() {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (!windowIsUndefined) {
|
if (!windowIsUndefined) {
|
||||||
let passiveSupported = false;
|
this.passive = supportsPassive ? { passive: false } : false;
|
||||||
window.addEventListener(
|
|
||||||
'test',
|
|
||||||
null,
|
|
||||||
Object.defineProperty({}, 'passive', {
|
|
||||||
get: () => {
|
|
||||||
passiveSupported = true;
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
this.passive = passiveSupported ? { passive: false } : false;
|
|
||||||
}
|
}
|
||||||
const open = this.getOpen();
|
const open = this.getOpen();
|
||||||
if (this.handler || open || this.sFirstEnter) {
|
if (this.handler || open || this.sFirstEnter) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import BaseMixin from '../_util/BaseMixin';
|
||||||
import Portal from '../_util/Portal';
|
import Portal from '../_util/Portal';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import { cloneElement } from '../_util/vnode';
|
import { cloneElement } from '../_util/vnode';
|
||||||
|
import supportsPassive from '../_util/supportsPassive';
|
||||||
|
|
||||||
function returnEmptyString() {
|
function returnEmptyString() {
|
||||||
return '';
|
return '';
|
||||||
|
@ -165,6 +166,7 @@ export default defineComponent({
|
||||||
currentDocument,
|
currentDocument,
|
||||||
'touchstart',
|
'touchstart',
|
||||||
this.onDocumentClick,
|
this.onDocumentClick,
|
||||||
|
supportsPassive ? { passive: true } : false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// close popup when trigger type contains 'onContextmenu' and document is scrolling.
|
// close popup when trigger type contains 'onContextmenu' and document is scrolling.
|
||||||
|
@ -378,7 +380,7 @@ export default defineComponent({
|
||||||
mouseProps.onMouseleave = self.onPopupMouseleave;
|
mouseProps.onMouseleave = self.onPopupMouseleave;
|
||||||
}
|
}
|
||||||
mouseProps.onMousedown = this.onPopupMouseDown;
|
mouseProps.onMousedown = this.onPopupMouseDown;
|
||||||
mouseProps.onTouchstart = this.onPopupMouseDown;
|
mouseProps[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart'] = this.onPopupMouseDown;
|
||||||
const { handleGetPopupClassFromAlign, getRootDomNode, getContainer, $attrs } = self;
|
const { handleGetPopupClassFromAlign, getRootDomNode, getContainer, $attrs } = self;
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
@ -603,11 +605,13 @@ export default defineComponent({
|
||||||
if (this.isClickToHide() || this.isClickToShow()) {
|
if (this.isClickToHide() || this.isClickToShow()) {
|
||||||
newChildProps.onClick = this.onClick;
|
newChildProps.onClick = this.onClick;
|
||||||
newChildProps.onMousedown = this.onMousedown;
|
newChildProps.onMousedown = this.onMousedown;
|
||||||
newChildProps.onTouchstart = this.onTouchstart;
|
newChildProps[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart'] = this.onTouchstart;
|
||||||
} else {
|
} else {
|
||||||
newChildProps.onClick = this.createTwoChains('onClick');
|
newChildProps.onClick = this.createTwoChains('onClick');
|
||||||
newChildProps.onMousedown = this.createTwoChains('onMousedown');
|
newChildProps.onMousedown = this.createTwoChains('onMousedown');
|
||||||
newChildProps.onTouchstart = this.createTwoChains('onTouchstart');
|
newChildProps[
|
||||||
|
supportsPassive ? 'onTouchstartPassive' : 'onTouchstart'
|
||||||
|
] = this.createTwoChains('onTouchstart');
|
||||||
}
|
}
|
||||||
if (this.isMouseEnterToShow()) {
|
if (this.isMouseEnterToShow()) {
|
||||||
newChildProps.onMouseenter = this.onMouseenter;
|
newChildProps.onMouseenter = this.onMouseenter;
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
|
import supportsPassive from '../../_util/supportsPassive';
|
||||||
|
|
||||||
export default function addEventListenerWrap(target, eventType, cb, option) {
|
export default function addEventListenerWrap(target, eventType, cb, option) {
|
||||||
if (target.addEventListener) {
|
if (target.addEventListener) {
|
||||||
target.addEventListener(eventType, cb, option);
|
let opt = option;
|
||||||
|
if (
|
||||||
|
opt === undefined &&
|
||||||
|
supportsPassive &&
|
||||||
|
(eventType === 'touchstart' || eventType === 'touchmove' || eventType === 'wheel')
|
||||||
|
) {
|
||||||
|
opt = { passive: true };
|
||||||
|
}
|
||||||
|
target.addEventListener(eventType, cb, opt);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
remove: () => {
|
remove: () => {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import useOriginScroll from './hooks/useOriginScroll';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import { RenderFunc, SharedConfig } from './interface';
|
import { RenderFunc, SharedConfig } from './interface';
|
||||||
|
import supportsPassive from '../_util/supportsPassive';
|
||||||
|
|
||||||
const EMPTY_DATA = [];
|
const EMPTY_DATA = [];
|
||||||
|
|
||||||
|
@ -264,7 +265,11 @@ const List = defineComponent({
|
||||||
}
|
}
|
||||||
const removeEventListener = () => {
|
const removeEventListener = () => {
|
||||||
if (componentRef.value) {
|
if (componentRef.value) {
|
||||||
componentRef.value.removeEventListener('wheel', onRawWheel);
|
componentRef.value.removeEventListener(
|
||||||
|
'wheel',
|
||||||
|
onRawWheel,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
componentRef.value.removeEventListener('DOMMouseScroll', onFireFoxScroll as any);
|
componentRef.value.removeEventListener('DOMMouseScroll', onFireFoxScroll as any);
|
||||||
componentRef.value.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
|
componentRef.value.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +278,11 @@ const List = defineComponent({
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (componentRef.value) {
|
if (componentRef.value) {
|
||||||
removeEventListener();
|
removeEventListener();
|
||||||
componentRef.value.addEventListener('wheel', onRawWheel);
|
componentRef.value.addEventListener(
|
||||||
|
'wheel',
|
||||||
|
onRawWheel,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
componentRef.value.addEventListener('DOMMouseScroll', onFireFoxScroll as any);
|
componentRef.value.addEventListener('DOMMouseScroll', onFireFoxScroll as any);
|
||||||
componentRef.value.addEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
|
componentRef.value.addEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { defineComponent, PropType, reactive } from 'vue';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import createRef from '../_util/createRef';
|
import createRef from '../_util/createRef';
|
||||||
import raf from '../_util/raf';
|
import raf from '../_util/raf';
|
||||||
|
import supportsPassive from '../_util/supportsPassive';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
|
|
||||||
const MIN_SIZE = 20;
|
const MIN_SIZE = 20;
|
||||||
|
@ -60,8 +61,16 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.scrollbarRef.current.addEventListener('touchstart', this.onScrollbarTouchStart);
|
this.scrollbarRef.current.addEventListener(
|
||||||
this.thumbRef.current.addEventListener('touchstart', this.onMouseDown);
|
'touchstart',
|
||||||
|
this.onScrollbarTouchStart,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
|
this.thumbRef.current.addEventListener(
|
||||||
|
'touchstart',
|
||||||
|
this.onMouseDown,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
|
@ -92,7 +101,11 @@ export default defineComponent({
|
||||||
window.addEventListener('mousemove', this.onMouseMove);
|
window.addEventListener('mousemove', this.onMouseMove);
|
||||||
window.addEventListener('mouseup', this.onMouseUp);
|
window.addEventListener('mouseup', this.onMouseUp);
|
||||||
|
|
||||||
this.thumbRef.current.addEventListener('touchmove', this.onMouseMove);
|
this.thumbRef.current.addEventListener(
|
||||||
|
'touchmove',
|
||||||
|
this.onMouseMove,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
this.thumbRef.current.addEventListener('touchend', this.onMouseUp);
|
this.thumbRef.current.addEventListener('touchend', this.onMouseUp);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -100,9 +113,21 @@ export default defineComponent({
|
||||||
window.removeEventListener('mousemove', this.onMouseMove);
|
window.removeEventListener('mousemove', this.onMouseMove);
|
||||||
window.removeEventListener('mouseup', this.onMouseUp);
|
window.removeEventListener('mouseup', this.onMouseUp);
|
||||||
|
|
||||||
this.scrollbarRef.current.removeEventListener('touchstart', this.onScrollbarTouchStart);
|
this.scrollbarRef.current.removeEventListener(
|
||||||
this.thumbRef.current.removeEventListener('touchstart', this.onMouseDown);
|
'touchstart',
|
||||||
this.thumbRef.current.removeEventListener('touchmove', this.onMouseMove);
|
this.onScrollbarTouchStart,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
|
this.thumbRef.current.removeEventListener(
|
||||||
|
'touchstart',
|
||||||
|
this.onMouseDown,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
|
this.thumbRef.current.removeEventListener(
|
||||||
|
'touchmove',
|
||||||
|
this.onMouseMove,
|
||||||
|
supportsPassive ? ({ passive: true } as EventListenerOptions) : false,
|
||||||
|
);
|
||||||
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
|
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
|
||||||
|
|
||||||
raf.cancel(this.moveRaf);
|
raf.cancel(this.moveRaf);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import supportsPassive from '../../_util/supportsPassive';
|
||||||
import { watch, Ref } from 'vue';
|
import { watch, Ref } from 'vue';
|
||||||
|
|
||||||
const SMOOTH_PTG = 14 / 15;
|
const SMOOTH_PTG = 14 / 15;
|
||||||
|
@ -17,7 +18,15 @@ export default function useMobileTouchMove(
|
||||||
|
|
||||||
const cleanUpEvents = () => {
|
const cleanUpEvents = () => {
|
||||||
if (element) {
|
if (element) {
|
||||||
element.removeEventListener('touchmove', onTouchMove);
|
element.removeEventListener(
|
||||||
|
'touchmove',
|
||||||
|
onTouchMove,
|
||||||
|
supportsPassive
|
||||||
|
? ({
|
||||||
|
passive: true,
|
||||||
|
} as EventListenerOptions)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
element.removeEventListener('touchend', onTouchEnd);
|
element.removeEventListener('touchend', onTouchEnd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -58,17 +67,41 @@ 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('touchmove', onTouchMove);
|
element!.addEventListener(
|
||||||
|
'touchmove',
|
||||||
|
onTouchMove,
|
||||||
|
supportsPassive
|
||||||
|
? ({
|
||||||
|
passive: true,
|
||||||
|
} as EventListenerOptions)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
element!.addEventListener('touchend', onTouchEnd);
|
element!.addEventListener('touchend', onTouchEnd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(inVirtual, val => {
|
watch(inVirtual, val => {
|
||||||
listRef.value.removeEventListener('touchstart', onTouchStart);
|
listRef.value.removeEventListener(
|
||||||
|
'touchstart',
|
||||||
|
onTouchStart,
|
||||||
|
supportsPassive
|
||||||
|
? ({
|
||||||
|
passive: true,
|
||||||
|
} as EventListenerOptions)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
cleanUpEvents();
|
cleanUpEvents();
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
if (val) {
|
if (val) {
|
||||||
listRef.value.addEventListener('touchstart', onTouchStart);
|
listRef.value.addEventListener(
|
||||||
|
'touchstart',
|
||||||
|
onTouchStart,
|
||||||
|
supportsPassive
|
||||||
|
? ({
|
||||||
|
passive: true,
|
||||||
|
} as EventListenerOptions)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue