Skip to content

Commit

Permalink
perf(activator): cancelled touch does not cause layout thrashing
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Dec 7, 2016
1 parent 04d9f5a commit 22d6bc5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/tap-click/activator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export abstract class ActivatorBase {

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

abstract clearState();
abstract clearState(animated: boolean);
}

export function isActivatedDisabled(ev: any, activatableEle: any): boolean {
Expand Down
21 changes: 14 additions & 7 deletions src/components/tap-click/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Activator implements ActivatorBase {
}

this.unscheduleClear();
this.deactivate();
this.deactivate(true);

// queue to have this element activated
this._queue.push(activatableEle);
Expand All @@ -69,7 +69,7 @@ export class Activator implements ActivatorBase {
return;
}
this._clearRafDefer = rafFrames(this.clearDelay, () => {
this.clearState();
this.clearState(true);
this._clearRafDefer = null;
});
}
Expand All @@ -82,29 +82,36 @@ export class Activator implements ActivatorBase {
}

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

} else {
// not actively transitioning, good to deactivate any elements
this.deactivate();
this.deactivate(animated);
}
}

// remove the active class from all active elements
deactivate() {
deactivate(animated: boolean) {
this._clearDeferred();

this._queue.length = 0;

let ele;
for (var i = 0; i < this._active.length; i++) {
this._active[i].classList.remove(this._css);
ele = this._active[i];
if (!animated) {
ele.style.transition = 'none';
} else {
ele.style.transition = '';
}
ele.classList.remove(this._css);
}
this._active.length = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/tap-click/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class RippleActivator implements ActivatorBase {
this._upAction(ev, activatableEle, startCoord);
}

clearState() {
clearState(animated: boolean) {
// Highlight
this.highlight && this.highlight.clearState();
this.highlight && this.highlight.clearState(animated);
}

_downAction(ev: UIEvent, activatableEle: HTMLElement, startCoord: PointerCoordinates) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tap-click/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class TapClick {

this.startCoord = null;
this.dispatchClick = false;
this.activator && this.activator.clearState();
this.activator && this.activator.clearState(false);
this.pointerEvents.stop();
}

Expand Down

1 comment on commit 22d6bc5

@JoaoPauloCMarra
Copy link

@JoaoPauloCMarra JoaoPauloCMarra commented on 22d6bc5 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some errors on Gmaps sdk native while clicking on the component, this did the trick:

export var isActivatable = function (ele) { if (ACTIVATABLE_ELEMENTS.indexOf(ele.tagName) > -1) { return true; } for (var i = 0, l = ACTIVATABLE_ATTRIBUTES.length; i < l; i++) { if (typeof ele.hasAttribute !== 'function' || ele.hasAttribute(ACTIVATABLE_ATTRIBUTES[i])) { return true; } } return false; };

Please sign in to comment.