UNPKG

1.59 kBJavaScriptView Raw
1import { r as registerInstance, c as createEvent, h, H as Host } from './index-8809c729.js';
2import { c as classnames } from './index-1d8e8acd.js';
3
4const coverViewCss = "taro-cover-view-core{display:block}";
5
6let CoverView = class {
7 constructor(hostRef) {
8 registerInstance(this, hostRef);
9 this.onLongPress = createEvent(this, "longpress", 7);
10 this.hoverStartTime = 50;
11 this.hoverStayTime = 400;
12 this.hover = false;
13 this.touch = false;
14 this.startTime = 0;
15 }
16 onTouchStart() {
17 if (this.hoverClass) {
18 this.touch = true;
19 setTimeout(() => {
20 if (this.touch) {
21 this.hover = true;
22 }
23 }, this.hoverStartTime);
24 }
25 this.timeoutEvent = setTimeout(() => {
26 this.onLongPress.emit();
27 }, 350);
28 this.startTime = Date.now();
29 }
30 onTouchMove() {
31 clearTimeout(this.timeoutEvent);
32 }
33 onTouchEnd() {
34 const spanTime = Date.now() - this.startTime;
35 if (spanTime < 350) {
36 clearTimeout(this.timeoutEvent);
37 }
38 if (this.hoverClass) {
39 this.touch = false;
40 setTimeout(() => {
41 if (!this.touch) {
42 this.hover = false;
43 }
44 }, this.hoverStayTime);
45 }
46 }
47 render() {
48 const cls = classnames({
49 [`${this.hoverClass}`]: this.hover
50 });
51 let attr = {};
52 if (!!this.animation) {
53 attr['animation'] = this.animation;
54 attr['data-animation'] = this.animation;
55 }
56 return (h(Host, Object.assign({ class: cls }, attr), h("slot", null)));
57 }
58};
59CoverView.style = coverViewCss;
60
61export { CoverView as taro_cover_view_core };