@tarojs/components
Version:
Taro 组件库。
70 lines (66 loc) • 1.95 kB
JavaScript
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-5bd7cbab.js';
import { c as classnames } from './index-cd1a2d33.js';
const indexCss = "body,html{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}taro-view-core{display:block}";
let View = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.onLongPress = createEvent(this, "longpress", 7);
this.hoverStartTime = 50;
this.hoverStayTime = 400;
this.hover = false;
this.touch = false;
this.startTime = 0;
}
onTouchStart() {
if (this.hoverClass) {
this.touch = true;
setTimeout(() => {
if (this.touch) {
this.hover = true;
}
}, this.hoverStartTime);
}
this.timeoutEvent = setTimeout(() => {
this.onLongPress.emit();
}, 350);
this.startTime = Date.now();
}
onTouchMove() {
clearTimeout(this.timeoutEvent);
}
onTouchEnd() {
const spanTime = Date.now() - this.startTime;
if (spanTime < 350) {
clearTimeout(this.timeoutEvent);
}
if (this.hoverClass) {
this.touch = false;
setTimeout(() => {
if (!this.touch) {
this.hover = false;
}
}, this.hoverStayTime);
}
}
componentDidRender() {
const el = this.el;
el.childNodes.forEach(item => {
if (item.nodeType === document.COMMENT_NODE && item["s-cn"])
item["s-cn"] = false;
});
}
render() {
const cls = classnames({
[`${this.hoverClass}`]: this.hover
});
let attr = {};
if (!!this.animation) {
attr['animation'] = this.animation;
attr['data-animation'] = this.animation;
}
return (h(Host, Object.assign({ class: cls }, attr), h("slot", null)));
}
get el() { return getElement(this); }
};
View.style = indexCss;
export { View as taro_view_core };