Skip to content

Commit 22d6bc5

Browse files
committed
perf(activator): cancelled touch does not cause layout thrashing
1 parent 04d9f5a commit 22d6bc5

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/components/tap-click/activator-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export abstract class ActivatorBase {
88

99
abstract upAction(ev: UIEvent, activatableEle: HTMLElement, startCoord: PointerCoordinates);
1010

11-
abstract clearState();
11+
abstract clearState(animated: boolean);
1212
}
1313

1414
export function isActivatedDisabled(ev: any, activatableEle: any): boolean {

src/components/tap-click/activator.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Activator implements ActivatorBase {
4242
}
4343

4444
this.unscheduleClear();
45-
this.deactivate();
45+
this.deactivate(true);
4646

4747
// queue to have this element activated
4848
this._queue.push(activatableEle);
@@ -69,7 +69,7 @@ export class Activator implements ActivatorBase {
6969
return;
7070
}
7171
this._clearRafDefer = rafFrames(this.clearDelay, () => {
72-
this.clearState();
72+
this.clearState(true);
7373
this._clearRafDefer = null;
7474
});
7575
}
@@ -82,29 +82,36 @@ export class Activator implements ActivatorBase {
8282
}
8383

8484
// all states should return to normal
85-
clearState() {
85+
clearState(animated: boolean) {
8686
if (!this.app.isEnabled()) {
8787
// the app is actively disabled, so don't bother deactivating anything.
8888
// this makes it easier on the GPU so it doesn't have to redraw any
8989
// buttons during a transition. This will retry in XX milliseconds.
9090
nativeTimeout(() => {
91-
this.clearState();
91+
this.clearState(animated);
9292
}, 600);
9393

9494
} else {
9595
// not actively transitioning, good to deactivate any elements
96-
this.deactivate();
96+
this.deactivate(animated);
9797
}
9898
}
9999

100100
// remove the active class from all active elements
101-
deactivate() {
101+
deactivate(animated: boolean) {
102102
this._clearDeferred();
103103

104104
this._queue.length = 0;
105105

106+
let ele;
106107
for (var i = 0; i < this._active.length; i++) {
107-
this._active[i].classList.remove(this._css);
108+
ele = this._active[i];
109+
if (!animated) {
110+
ele.style.transition = 'none';
111+
} else {
112+
ele.style.transition = '';
113+
}
114+
ele.classList.remove(this._css);
108115
}
109116
this._active.length = 0;
110117
}

src/components/tap-click/ripple.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export class RippleActivator implements ActivatorBase {
4141
this._upAction(ev, activatableEle, startCoord);
4242
}
4343

44-
clearState() {
44+
clearState(animated: boolean) {
4545
// Highlight
46-
this.highlight && this.highlight.clearState();
46+
this.highlight && this.highlight.clearState(animated);
4747
}
4848

4949
_downAction(ev: UIEvent, activatableEle: HTMLElement, startCoord: PointerCoordinates) {

src/components/tap-click/tap-click.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class TapClick {
109109

110110
this.startCoord = null;
111111
this.dispatchClick = false;
112-
this.activator && this.activator.clearState();
112+
this.activator && this.activator.clearState(false);
113113
this.pointerEvents.stop();
114114
}
115115

0 commit comments

Comments
 (0)