Skip to content

Commit 0a2e401

Browse files
committed
Fix switch animation
1 parent fa750ab commit 0a2e401

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/directive/switch/switch.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { $injectTokens } from "../../injection-tokens.js";
2-
import { domInsert, getBlockNodes } from "../../shared/dom.js";
2+
import { domInsert } from "../../shared/dom.js";
33
import { hasAnimate } from "../../shared/utils.js";
44

55
ngSwitchDirective.$inject = [$injectTokens._animate];
@@ -43,19 +43,20 @@ export function ngSwitchDirective($animate) {
4343

4444
let ii;
4545

46+
let runner;
47+
4648
// Start with the last, in case the array is modified during the loop
4749
while (previousLeaveAnimations.length) {
4850
$animate.cancel(previousLeaveAnimations.pop());
4951
}
5052

5153
for (i = 0, ii = selectedScopes.length; i < ii; ++i) {
52-
const selected = getBlockNodes(selectedElements[i].clone);
54+
const selected = selectedElements[i].clone;
5355

5456
selectedScopes[i].$destroy();
5557

5658
if (hasAnimate(selected)) {
57-
const runner = (previousLeaveAnimations[i] =
58-
$animate.leave(selected));
59+
runner = previousLeaveAnimations[i] = $animate.leave(selected);
5960

6061
runner.done(spliceFactory(previousLeaveAnimations, i));
6162
} else {
@@ -85,7 +86,13 @@ export function ngSwitchDirective($animate) {
8586
selectedElements.push(block);
8687

8788
if (hasAnimate(caseElement)) {
88-
$animate.enter(caseElement, anchor.parentElement, anchor);
89+
if (runner) {
90+
requestAnimationFrame(() => {
91+
$animate.enter(caseElement, anchor.parentElement, anchor);
92+
});
93+
} else {
94+
$animate.enter(caseElement, anchor.parentElement, anchor);
95+
}
8996
} else {
9097
domInsert(caseElement, anchor.parentElement, anchor);
9198
}

0 commit comments

Comments
 (0)