Skip to content

Commit bab7ed3

Browse files
Zuckjetalxhub
authored andcommitted
fix(animations): should not invoke disabled child animations (#37724)
Currently child animation will be triggered by `animateChild()` despite it has been disabled. These changes add some logic to prevent that unexpected behavior. PR Close #37724 PR Close #37724
1 parent 6c05c3f commit bab7ed3

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

packages/animations/browser/src/render/transition_animation_engine.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,14 @@ export class TransitionAnimationEngine {
10341034
// instead stretch the first keyframe gap until the animation starts. This is
10351035
// important in order to prevent extra initialization styles from being
10361036
// required by the user for the animation.
1037-
instruction.timelines.forEach(tl => tl.stretchStartingKeyframe = true);
1037+
const timelines: AnimationTimelineInstruction[] = [];
1038+
instruction.timelines.forEach(tl => {
1039+
tl.stretchStartingKeyframe = true;
1040+
if (!this.disabledNodes.has(tl.element)) {
1041+
timelines.push(tl);
1042+
}
1043+
});
1044+
instruction.timelines = timelines;
10381045

10391046
subTimelines.append(element, instruction.timelines);
10401047

packages/core/test/animation/animation_query_integration_spec.ts

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,14 +3309,14 @@ describe('animation query tests', function() {
33093309
})
33103310
class Cmp {
33113311
exp: any = '';
3312-
disableExp = false;
3312+
disabledExp = false;
33133313
}
33143314

33153315
TestBed.configureTestingModule({declarations: [Cmp]});
33163316

33173317
const fixture = TestBed.createComponent(Cmp);
33183318
const cmp = fixture.componentInstance;
3319-
cmp.disableExp = true;
3319+
cmp.disabledExp = true;
33203320
fixture.detectChanges();
33213321
resetLog();
33223322

@@ -3363,14 +3363,14 @@ describe('animation query tests', function() {
33633363
})
33643364
class Cmp {
33653365
exp: any = '';
3366-
disableExp = false;
3366+
disabledExp = false;
33673367
}
33683368

33693369
TestBed.configureTestingModule({declarations: [Cmp]});
33703370

33713371
const fixture = TestBed.createComponent(Cmp);
33723372
const cmp = fixture.componentInstance;
3373-
cmp.disableExp = true;
3373+
cmp.disabledExp = true;
33743374
fixture.detectChanges();
33753375
resetLog();
33763376

@@ -3386,6 +3386,63 @@ describe('animation query tests', function() {
33863386
expect(p2.duration).toEqual(1000);
33873387
expect(p2.element.classList.contains('parent')).toBeTrue();
33883388
});
3389+
3390+
it('should disable the animation for the given element regardless of existing parent element animation queries or child element animation queries',
3391+
() => {
3392+
@Component({
3393+
selector: 'some-cmp',
3394+
template: `
3395+
<div class="parent" [@parentAnimation]="exp">
3396+
<div class="child" [@.disabled]="disabledExp" [@childAnimation]="exp">
3397+
<div class="grand-child" [@grandChildAnimation]="exp"></div>
3398+
</div>
3399+
</div>
3400+
`,
3401+
animations: [
3402+
trigger(
3403+
'parentAnimation',
3404+
[
3405+
transition(
3406+
'* => go',
3407+
[query('@*', animateChild()), animate(1500, style({opacity: 0}))]),
3408+
]),
3409+
trigger(
3410+
'childAnimation',
3411+
[
3412+
transition('* => go', [animate(1000, style({opacity: 0}))]),
3413+
]),
3414+
trigger(
3415+
'grandChildAnimation',
3416+
[
3417+
transition('* => go', [animate(500, style({opacity: 0}))]),
3418+
]),
3419+
]
3420+
})
3421+
class Cmp {
3422+
exp: any = '';
3423+
disabledExp = false;
3424+
}
3425+
3426+
TestBed.configureTestingModule({declarations: [Cmp]});
3427+
3428+
const fixture = TestBed.createComponent(Cmp);
3429+
const cmp = fixture.componentInstance;
3430+
cmp.disabledExp = true;
3431+
fixture.detectChanges();
3432+
resetLog();
3433+
3434+
cmp.exp = 'go';
3435+
fixture.detectChanges();
3436+
3437+
const players = getLog();
3438+
expect(players.length).toEqual(2);
3439+
3440+
const [p1, p2] = players;
3441+
expect(p1.duration).toEqual(500);
3442+
expect(p1.element.classList.contains('grand-child')).toBeTrue();
3443+
expect(p2.duration).toEqual(1500);
3444+
expect(p2.element.classList.contains('parent')).toBeTrue();
3445+
});
33893446
});
33903447
});
33913448
});

0 commit comments

Comments
 (0)