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

Commit

Permalink
fix(speedDial): Fix intially open bug.
Browse files Browse the repository at this point in the history
Due to an animation issue, the FAB Speed Dial started in an open
state when using the `md-fling` animation.

Fix by delaying the initial animation until after the component
was fully rendered so that the animation's calculations were correct
and adding some CSS to ensure the first animation fired instantly.

Fixes #6111.
  • Loading branch information
topherfangio authored and jelbourn committed Dec 10, 2015
1 parent ea60dd3 commit cfdd7cf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/components/fabSpeedDial/fabController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
setupDefaults();
setupListeners();
setupWatchers();

var initialAnimationAttempts = 0;
fireInitialAnimations();

function setupDefaults() {
Expand All @@ -40,6 +42,9 @@

// Start the keyboard interaction at the first action
resetActionIndex();

// Add an animations waiting class so we know not to run
$element.addClass('md-animations-waiting');
}

function setupListeners() {
Expand Down Expand Up @@ -133,11 +138,23 @@
});
}

// Fire the animations once in a separate digest loop to initialize them
function fireInitialAnimations() {
$mdUtil.nextTick(function() {
$animate.addClass($element, 'md-noop');
});
// If the element is actually visible on the screen
if ($element[0].scrollHeight > 0) {
// Fire our animation
$animate.addClass($element, 'md-animations-ready').then(function() {
// Remove the waiting class
$element.removeClass('md-animations-waiting');
});
}

// Otherwise, try for up to 1 second before giving up
else if (initialAnimationAttempts < 10) {
$timeout(fireInitialAnimations, 100);

// Increment our counter
initialAnimationAttempts = initialAnimationAttempts + 1;
}
}

function enableKeyboard() {
Expand Down
9 changes: 8 additions & 1 deletion src/components/fabSpeedDial/fabSpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
function delayDone(done) { $timeout(done, cssAnimationDuration, false); }

function runAnimation(element) {
// Don't run if we are still waiting and we are not ready
if (element.hasClass('md-animations-waiting') && !element.hasClass('md-animations-ready')) {
return;
}

var el = element[0];
var ctrl = element.controller('mdFabSpeedDial');
var items = el.querySelectorAll('.md-fab-action-item');
Expand Down Expand Up @@ -184,8 +189,10 @@
addClass: function(element, className, done) {
if (element.hasClass('md-fling')) {
runAnimation(element);
delayDone(done);
} else {
done();
}
delayDone(done);
},
removeClass: function(element, className, done) {
runAnimation(element);
Expand Down
15 changes: 14 additions & 1 deletion src/components/fabSpeedDial/fabSpeedDial.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,22 @@ md-fab-speed-dial {
/*
* Handle the animations
*/
&.md-scale {
&.md-fling {
.md-fab-action-item {
opacity: 1;
}
}

// For the initial animation, set the duration to be instant
&.md-fling.md-animations-waiting {
.md-fab-action-item {
opacity: 0;
transition-duration: 0s;
}
}

&.md-scale {
.md-fab-action-item {
transform: scale(0.1);
transition: $swift-ease-in;

Expand Down

0 comments on commit cfdd7cf

Please sign in to comment.