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

Commit 9ac7496

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(tabs): Fix 0-height animation on iOS devices.
On iOS devices, when switching between tabs, the height would jump to 0, then animate to the proper place causing a bad glitch. Fixes #4339. Closes #4341.
1 parent a0ed824 commit 9ac7496

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/components/tabs/js/tabsController.js

+35-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ angular
66
* @ngInject
77
*/
88
function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple,
9-
$mdUtil, $animate, $attrs, $compile, $mdTheming) {
9+
$mdUtil, $animateCss, $attrs, $compile, $mdTheming) {
1010
// define private properties
1111
var ctrl = this,
1212
locked = false,
@@ -635,17 +635,41 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
635635
newHeight = contentHeight + tabsHeight,
636636
currentHeight = $element.prop('clientHeight');
637637
if (currentHeight === newHeight) return;
638+
639+
// Lock during animation so the user can't change tabs
638640
locked = true;
639-
$animate
640-
.animate(
641-
$element,
642-
{ height: currentHeight + 'px' },
643-
{ height: newHeight + 'px' }
644-
)
645-
.then(function () {
646-
$element.css('height', '');
647-
locked = false;
648-
});
641+
642+
var fromHeight = { height: currentHeight + 'px'},
643+
toHeight = { height: newHeight + 'px' };
644+
645+
// Set the height to the current, specific pixel height to fix a bug on iOS where the height
646+
// first animates to 0, then back to the proper height causing a visual glitch
647+
$element.css(fromHeight);
648+
649+
// Animate the height from the old to the new
650+
$animateCss($element, {
651+
from: fromHeight,
652+
to: toHeight,
653+
easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
654+
duration: 0.5
655+
}).start().done(function () {
656+
// Then (to fix the same iOS issue as above), disable transitions and remove the specific
657+
// pixel height so the height can size with browser width/content changes, etc.
658+
$element.css({
659+
transition: 'none',
660+
height: ''
661+
});
662+
663+
// In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
664+
// enough to batch it for us instead of doing it immediately, which undoes the original
665+
// transition: none)
666+
$mdUtil.nextTick(function() {
667+
$element.css('transition', '');
668+
});
669+
670+
// And unlock so tab changes can occur
671+
locked = false;
672+
});
649673
}
650674

651675
/**

src/components/tabs/tabs.scss

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ md-tabs {
3131
overflow: hidden;
3232
position: relative;
3333
flex-shrink: 0;
34-
&.ng-animate {
35-
transition: height $swift-ease-in-out-duration $swift-ease-in-out-timing-function;
36-
}
3734
&:not(.md-no-tab-content):not(.md-dynamic-height) {
3835
min-height: 200 + $tabs-header-height;
3936
}

0 commit comments

Comments
 (0)