Skip to content

Commit

Permalink
chore(nativeRaf): use native raf over zone wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Apr 26, 2016
1 parent 985bb89 commit 066ab71
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ionic/components/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Ion} from '../ion';
import {IonicApp} from '../app/app';
import {Config} from '../../config/config';
import {Keyboard} from '../../util/keyboard';
import {raf, nativeTimeout, transitionEnd} from '../../util/dom';
import {nativeRaf, nativeTimeout, transitionEnd} from '../../util/dom';
import {ViewController} from '../nav/view-controller';
import {ScrollView} from '../../util/scroll-view';

Expand Down Expand Up @@ -198,8 +198,8 @@ export class Content extends Ion {

lastScrollTop = currentScrollTop;

raf(() => {
raf(next);
nativeRaf(() => {
nativeRaf(next);
});
}

Expand Down
4 changes: 2 additions & 2 deletions ionic/components/img/img.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, Input, ElementRef, ChangeDetectionStrategy, ViewEncapsulation, NgZone} from 'angular2/core';

import {raf} from '../../util/dom';
import {nativeRaf} from '../../util/dom';
import {isPresent} from '../../util/util';
import {Platform} from '../../platform/platform';

Expand Down Expand Up @@ -62,7 +62,7 @@ export class Img {
img.addEventListener('load', () => {
if (img.src === this._normalizeSrc) {
this._elementRef.nativeElement.appendChild(img);
raf(() => {
nativeRaf(() => {
this._update();
});
}
Expand Down
2 changes: 1 addition & 1 deletion ionic/components/input/native-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Directive, Attribute, ElementRef, Renderer, Input, Output, EventEmitter,
import {NgControl} from 'angular2/common';

import {Config} from '../../config/config';
import {CSS, hasFocus, raf} from '../../util/dom';
import {CSS, hasFocus} from '../../util/dom';


/**
Expand Down
6 changes: 3 additions & 3 deletions ionic/components/item/item-sliding-gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {DIRECTION_RIGHT} from '../../gestures/hammer';
import {DragGesture} from '../../gestures/drag-gesture';
import {List} from '../list/list';

import {CSS, raf, closest} from '../../util/dom';
import {CSS, nativeRaf, closest} from '../../util/dom';


export class ItemSlidingGesture extends DragGesture {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ItemSlidingGesture extends DragGesture {
itemData.hasMouseOut = true;
}

raf(() => {
nativeRaf(() => {
if (!this.dragEnded && !this.preventDrag) {
isItemActive(itemContainerEle, true);
this.open(itemContainerEle, newX, false);
Expand Down Expand Up @@ -146,7 +146,7 @@ export class ItemSlidingGesture extends DragGesture {
itemContainerEle.removeEventListener('mouseout', this.onMouseOut);
itemData.hasMouseOut = false;

raf(() => {
nativeRaf(() => {
this.open(itemContainerEle, restingPoint, true);
});
}
Expand Down
1 change: 0 additions & 1 deletion ionic/components/nav/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Keyboard} from '../../util/keyboard';
import {NavParams} from './nav-params';
import {pascalCaseToDashCase, isBlank} from '../../util/util';
import {Portal} from './nav-portal';
import {raf} from '../../util/dom';
import {SwipeBackGesture} from './swipe-back';
import {Transition} from '../../transitions/transition';
import {ViewController} from './view-controller';
Expand Down
2 changes: 1 addition & 1 deletion ionic/components/tap-click/activator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {raf, rafFrames} from '../../util/dom';
import {rafFrames} from '../../util/dom';


export class Activator {
Expand Down
4 changes: 2 additions & 2 deletions ionic/components/tap-click/ripple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Activator} from './activator';
import {CSS, raf, rafFrames} from '../../util/dom';
import {CSS, nativeRaf, rafFrames} from '../../util/dom';
const win: any = window;


Expand All @@ -22,7 +22,7 @@ export class RippleActivator extends Activator {
self._queue.push(activatableEle);

this._zone.runOutsideAngular(function() {
raf(function() {
nativeRaf(function() {
var i;

for (i = 0; i < self._queue.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion ionic/components/tap-click/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class TapClick {

pointerEnd(ev) {
let activatableEle = getActivatableTarget(ev.target);
if (activatableEle) {
if (activatableEle && this.startCoord) {
this.activator && this.activator.upAction(ev, activatableEle, this.startCoord.x, this.startCoord.y);
}
this.moveListeners(false);
Expand Down
6 changes: 3 additions & 3 deletions ionic/components/virtual-scroll/virtual-scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {VirtualItem, VirtualHeader, VirtualFooter} from './virtual-item';
import {VirtualCell, VirtualNode, VirtualData} from './virtual-util';
import {processRecords, populateNodeData, initReadNodes, writeToNodes, updateDimensions, adjustRendered, calcDimensions, estimateHeight} from './virtual-util';
import {isBlank, isPresent, isFunction} from '../../util/util';
import {rafFrames, raf, cancelRaf, pointerCoord, nativeTimeout, clearNativeTimeout} from '../../util/dom';
import {rafFrames, nativeRaf, cancelRaf, pointerCoord, nativeTimeout, clearNativeTimeout} from '../../util/dom';
import {Img} from '../img/img';


Expand Down Expand Up @@ -391,7 +391,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
// oh no! the DOM doesn't have good data yet!
// let's try again in XXms, and give up eventually if we never get data
attempts++;
raf(function() {
nativeRaf(function() {
readDimensions(done);
});
}
Expand Down Expand Up @@ -439,7 +439,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
this._cd.detectChanges();

// wait a frame before trying to read and calculate the dimensions
raf(this.postRenderVirtual.bind(this));
nativeRaf(this.postRenderVirtual.bind(this));
}

/**
Expand Down
9 changes: 6 additions & 3 deletions ionic/util/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
})();

// use native raf rather than the zone wrapped one
export const raf = (window[window['Zone']['__symbol__']('requestAnimationFrame')] || window[window['Zone']['__symbol__']('webkitRequestAnimationFrame')])['bind'](window);
export const nativeRaf = (window[window['Zone']['__symbol__']('requestAnimationFrame')] || window[window['Zone']['__symbol__']('webkitRequestAnimationFrame')])['bind'](window);

// zone wrapped raf
export const raf = window.requestAnimationFrame.bind(window);
export const cancelRaf = window.cancelAnimationFrame.bind(window);

export const nativeTimeout = window[window['Zone']['__symbol__']('setTimeout')]['bind'](window);
Expand All @@ -35,11 +38,11 @@ export function rafFrames(framesToWait, callback) {
framesToWait = Math.ceil(framesToWait);

if (framesToWait < 2) {
raf(callback);
nativeRaf(callback);

} else {
nativeTimeout(() => {
raf(callback);
nativeRaf(callback);
}, (framesToWait - 1) * 16.6667);
}
}
Expand Down
6 changes: 3 additions & 3 deletions ionic/util/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Injectable, NgZone} from 'angular2/core';

import {Config} from '../config/config';
import {Form} from './form';
import {hasFocusedTextInput, raf, rafFrames, nativeTimeout} from './dom';
import {hasFocusedTextInput, nativeRaf, rafFrames, nativeTimeout} from './dom';

/**
* @name Keyboard
Expand Down Expand Up @@ -109,7 +109,7 @@ export class Keyboard {
*/
close() {
console.debug('keyboard close()');
raf(() => {
nativeRaf(() => {
if (hasFocusedTextInput()) {
// only focus out when a text input has focus
this._form.focusOut();
Expand Down Expand Up @@ -137,7 +137,7 @@ export class Keyboard {
let isKeyInputEnabled = false;

function cssClass() {
raf(() => {
nativeRaf(() => {
document.body.classList[isKeyInputEnabled ? 'add' : 'remove']('focus-outline');
});
}
Expand Down
12 changes: 6 additions & 6 deletions ionic/util/scroll-view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CSS, pointerCoord, raf, cancelRaf} from '../util/dom';
import {CSS, pointerCoord, nativeRaf, cancelRaf} from '../util/dom';


export class ScrollView {
Expand Down Expand Up @@ -84,7 +84,7 @@ export class ScrollView {
}

if (easedT < 1) {
raf(step);
nativeRaf(step);

} else {
// done
Expand All @@ -96,9 +96,9 @@ export class ScrollView {
self.isPlaying = true;

// chill out for a frame first
raf(() => {
nativeRaf(() => {
startTime = Date.now();
raf(step);
nativeRaf(step);
});

});
Expand Down Expand Up @@ -232,7 +232,7 @@ export class ScrollView {
// ******** DOM READ ****************
this._setMax();

this._rafId = raf(this._decelerate.bind(this));
this._rafId = nativeRaf(this._decelerate.bind(this));
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ export class ScrollView {
self.setTop(self._top);

if (self._top > 0 && self._top < self._max && Math.abs(self._velocity) > MIN_VELOCITY_CONTINUE_DECELERATION) {
self._rafId = raf(self._decelerate.bind(self));
self._rafId = nativeRaf(self._decelerate.bind(self));
}
}
}
Expand Down

0 comments on commit 066ab71

Please sign in to comment.