|
1 | 1 | import { $injectTokens } from "../../injection-tokens.js"; |
2 | | -import { domInsert, getBlockNodes } from "../../shared/dom.js"; |
| 2 | +import { domInsert } from "../../shared/dom.js"; |
3 | 3 | import { hasAnimate } from "../../shared/utils.js"; |
4 | 4 |
|
5 | 5 | ngSwitchDirective.$inject = [$injectTokens._animate]; |
@@ -43,19 +43,20 @@ export function ngSwitchDirective($animate) { |
43 | 43 |
|
44 | 44 | let ii; |
45 | 45 |
|
| 46 | + let runner; |
| 47 | + |
46 | 48 | // Start with the last, in case the array is modified during the loop |
47 | 49 | while (previousLeaveAnimations.length) { |
48 | 50 | $animate.cancel(previousLeaveAnimations.pop()); |
49 | 51 | } |
50 | 52 |
|
51 | 53 | for (i = 0, ii = selectedScopes.length; i < ii; ++i) { |
52 | | - const selected = getBlockNodes(selectedElements[i].clone); |
| 54 | + const selected = selectedElements[i].clone; |
53 | 55 |
|
54 | 56 | selectedScopes[i].$destroy(); |
55 | 57 |
|
56 | 58 | if (hasAnimate(selected)) { |
57 | | - const runner = (previousLeaveAnimations[i] = |
58 | | - $animate.leave(selected)); |
| 59 | + runner = previousLeaveAnimations[i] = $animate.leave(selected); |
59 | 60 |
|
60 | 61 | runner.done(spliceFactory(previousLeaveAnimations, i)); |
61 | 62 | } else { |
@@ -85,7 +86,13 @@ export function ngSwitchDirective($animate) { |
85 | 86 | selectedElements.push(block); |
86 | 87 |
|
87 | 88 | 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 | + } |
89 | 96 | } else { |
90 | 97 | domInsert(caseElement, anchor.parentElement, anchor); |
91 | 98 | } |
|
0 commit comments