forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathripple.ts
More file actions
121 lines (98 loc) · 4.07 KB
/
ripple.ts
File metadata and controls
121 lines (98 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { Activator } from './activator';
import { App } from '../app/app';
import { Coordinates, CSS, hasPointerMoved, nativeRaf, pointerCoord, rafFrames } from '../../util/dom';
import { Config } from '../../config/config';
/**
* @private
*/
export class RippleActivator extends Activator {
constructor(app: App, config: Config) {
super(app, config);
}
downAction(ev: UIEvent, activatableEle: HTMLElement, startCoord: Coordinates) {
let self = this;
if (self.disableActivated(ev)) {
return;
}
// queue to have this element activated
self._queue.push(activatableEle);
nativeRaf(function() {
for (var i = 0; i < self._queue.length; i++) {
var queuedEle = self._queue[i];
if (queuedEle && queuedEle.parentNode) {
self._active.push(queuedEle);
// DOM WRITE
queuedEle.classList.add(self._css);
var j = queuedEle.childElementCount;
while (j--) {
var rippleEle: any = queuedEle.children[j];
if (rippleEle.tagName === 'ION-BUTTON-EFFECT') {
// DOM WRITE
rippleEle.style.left = '-9999px';
rippleEle.style.opacity = '';
rippleEle.style[CSS.transform] = 'scale(0.001) translateZ(0px)';
rippleEle.style[CSS.transition] = '';
// DOM READ
var clientRect = activatableEle.getBoundingClientRect();
rippleEle.$top = clientRect.top;
rippleEle.$left = clientRect.left;
rippleEle.$width = clientRect.width;
rippleEle.$height = clientRect.height;
break;
}
}
}
}
self._queue = [];
});
}
upAction(ev: UIEvent, activatableEle: HTMLElement, startCoord: Coordinates) {
let self = this;
if (!hasPointerMoved(6, startCoord, pointerCoord(ev))) {
let i = activatableEle.childElementCount;
while (i--) {
var rippleEle: any = activatableEle.children[i];
if (rippleEle.tagName === 'ION-BUTTON-EFFECT') {
var clientPointerX = (startCoord.x - rippleEle.$left);
var clientPointerY = (startCoord.y - rippleEle.$top);
var x = Math.max(Math.abs(rippleEle.$width - clientPointerX), clientPointerX) * 2;
var y = Math.max(Math.abs(rippleEle.$height - clientPointerY), clientPointerY) * 2;
var diameter = Math.min(Math.max(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)), 64), 240);
if (activatableEle.hasAttribute('ion-item')) {
diameter = Math.min(diameter, 140);
}
var radius = Math.sqrt(rippleEle.$width + rippleEle.$height);
var scaleTransitionDuration = Math.max(1600 * Math.sqrt(radius / TOUCH_DOWN_ACCEL) + 0.5, 260);
var opacityTransitionDuration = scaleTransitionDuration * 0.7;
var opacityTransitionDelay = scaleTransitionDuration - opacityTransitionDuration;
// DOM WRITE
rippleEle.style.width = rippleEle.style.height = diameter + 'px';
rippleEle.style.marginTop = rippleEle.style.marginLeft = -(diameter / 2) + 'px';
rippleEle.style.left = clientPointerX + 'px';
rippleEle.style.top = clientPointerY + 'px';
rippleEle.style.opacity = '0';
rippleEle.style[CSS.transform] = 'scale(1) translateZ(0px)';
rippleEle.style[CSS.transition] = 'transform ' +
scaleTransitionDuration +
'ms,opacity ' +
opacityTransitionDuration +
'ms ' +
opacityTransitionDelay + 'ms';
}
}
}
super.upAction(ev, activatableEle, startCoord);
}
deactivate() {
// remove the active class from all active elements
let self = this;
self._queue = [];
rafFrames(2, function() {
for (var i = 0; i < self._active.length; i++) {
self._active[i].classList.remove(self._css);
}
self._active = [];
});
}
}
const TOUCH_DOWN_ACCEL = 300;