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

fix(mdTabs): Fix 0-height animation on iOS devices. #4341

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular
* @ngInject
*/
function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple,
$mdUtil, $animate, $attrs, $compile, $mdTheming) {
$mdUtil, $animateCss, $attrs, $compile, $mdTheming) {
// define private properties
var ctrl = this,
locked = false,
Expand Down Expand Up @@ -635,17 +635,41 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
newHeight = contentHeight + tabsHeight,
currentHeight = $element.prop('clientHeight');
if (currentHeight === newHeight) return;

// Lock during animation so the user can't change tabs
locked = true;
$animate
.animate(
$element,
{ height: currentHeight + 'px' },
{ height: newHeight + 'px' }
)
.then(function () {
$element.css('height', '');
locked = false;
});

var fromHeight = { height: currentHeight + 'px'},
toHeight = { height: newHeight + 'px' };

// Set the height to the current, specific pixel height to fix a bug on iOS where the height
// first animates to 0, then back to the proper height causing a visual glitch
$element.css(fromHeight);

// Animate the height from the old to the new
$animateCss($element, {
from: fromHeight,
to: toHeight,
easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
duration: 0.5
}).start().done(function () {
// Then (to fix the same iOS issue as above), disable transitions and remove the specific
// pixel height so the height can size with browser width/content changes, etc.
$element.css({
transition: 'none',
height: ''
});

// In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
// enough to batch it for us instead of doing it immediately, which undoes the original
// transition: none)
$mdUtil.nextTick(function() {
$element.css('transition', '');
});

// And unlock so tab changes can occur
locked = false;
});
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/components/tabs/tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ md-tabs {
overflow: hidden;
position: relative;
flex-shrink: 0;
&.ng-animate {
transition: height $swift-ease-in-out-duration $swift-ease-in-out-timing-function;
}
&:not(.md-no-tab-content):not(.md-dynamic-height) {
min-height: 200 + $tabs-header-height;
}
Expand Down