@tarojs/components
Version:
80 lines (74 loc) • 2.4 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-e751dfe3.js');
const index$1 = require('./index-f6805218.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}";
const View = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.onLongPress = index.createEvent(this, "longpress", 7);
this.startTime = 0;
this.animation = undefined;
this.hoverClass = undefined;
this.hoverStartTime = 50;
this.hoverStayTime = 400;
this.hover = false;
this.touch = false;
}
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 => {
// Note: ['s-cn'] Content Reference Node
if (item.nodeType === document.COMMENT_NODE && item['s-cn'])
item['s-cn'] = false;
// Note: ['s-sr'] Is a slot reference node (渲染完成后禁用 slotRelocation 特性, 避免 Stencil 组件相互调用时内置排序与第三方 UI 框架冲突导致组件顺序混乱)
if (item.nodeType !== document.COMMENT_NODE && item['s-sr'])
item['s-sr'] = false;
});
}
render() {
const cls = index$1.classnames({
[`${this.hoverClass}`]: this.hover
});
let attr = {};
if (!!this.animation) {
attr['animation'] = this.animation;
attr['data-animation'] = this.animation;
}
return (index.h(index.Host, Object.assign({ class: cls }, attr), index.h("slot", null)));
}
get el() { return index.getElement(this); }
};
View.style = indexCss;
exports.taro_view_core = View;