Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
update(toolbar, fabSpeedDial, toast): batching nextTick() instead of …
Browse files Browse the repository at this point in the history
…$timeout
  • Loading branch information
ThomasBurleson committed Jul 14, 2015
1 parent d2207ab commit 2668ba0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/components/fabSpeedDial/fabSpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
element.prepend('<div class="md-css-variables"></div>');
}

function FabSpeedDialController($scope, $element, $animate, $timeout) {
function FabSpeedDialController($scope, $element, $animate, $mdUtil) {
var vm = this;

// Define our open/close functions
Expand Down Expand Up @@ -113,9 +113,9 @@
setupWatchers();

// Fire the animations once in a separate digest loop to initialize them
$timeout(function() {
$mdUtil.nextTick(function() {
$animate.addClass($element, 'md-noop');
}, 0);
});

// Set our default variables
function setupDefaults() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function MdToastProvider($$interimElementProvider) {
return $mdToast;

/* @ngInject */
function toastDefaultOptions($timeout, $animate, $mdToast, $mdUtil) {
function toastDefaultOptions($animate, $mdToast, $mdUtil) {
return {
onShow: onShow,
onRemove: onRemove,
Expand All @@ -231,7 +231,7 @@ function MdToastProvider($$interimElementProvider) {
options.onSwipe = function(ev, gesture) {
//Add swipeleft/swiperight class to element so it can animate correctly
element.addClass('md-' + ev.type.replace('$md.',''));
$timeout($mdToast.cancel);
$mdUtil.nextTick($mdToast.cancel);
};
element.on('$md.swipeleft $md.swiperight', options.onSwipe);
return $animate.enter(element, options.parent);
Expand Down
32 changes: 15 additions & 17 deletions src/components/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ angular.module('material.components.toolbar', [
* shrinking by. For example, if 0.25 is given then the toolbar will shrink
* at one fourth the rate at which the user scrolls down. Default 0.5.
*/
function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate, $timeout) {

function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate ) {
var translateY = angular.bind(null, $mdUtil.supplant, 'translate3d(0,{0}px,0)' );

return {
restrict: 'E',
controller: angular.noop,
link: function(scope, element, attr) {

$mdTheming(element);

if (angular.isDefined(attr.mdScrollShrink)) {
Expand Down Expand Up @@ -127,26 +130,21 @@ function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate, $
Math.max(0, y + scrollTop - prevScrollTop)
);

element.css(
$mdConstant.CSS.TRANSFORM,
'translate3d(0,' + (-y * shrinkSpeedFactor) + 'px,0)'
);
contentElement.css(
$mdConstant.CSS.TRANSFORM,
'translate3d(0,' + ((toolbarHeight - y) * shrinkSpeedFactor) + 'px,0)'
);
element.css( $mdConstant.CSS.TRANSFORM, translateY([-y * shrinkSpeedFactor]) );
contentElement.css( $mdConstant.CSS.TRANSFORM, translateY([(toolbarHeight - y) * shrinkSpeedFactor]) );

prevScrollTop = scrollTop;

if (element.hasClass('md-whiteframe-z1')) {
if (!y) {
$timeout(function () { $animate.removeClass(element, 'md-whiteframe-z1'); });
}
} else {
if (y) {
$timeout(function () { $animate.addClass(element, 'md-whiteframe-z1'); });
}
$mdUtil.nextTick(function () {
var hasWhiteFrame = element.hasClass('md-whiteframe-z1');

if ( hasWhiteFrame && !y) {
$animate.removeClass(element, 'md-whiteframe-z1');
} else if ( !hasWhiteFrame && y ) {
$animate.addClass(element, 'md-whiteframe-z1');
}
});

}

}
Expand Down

0 comments on commit 2668ba0

Please sign in to comment.