Skip to content

Commit 2148093

Browse files
committed
feat(): All 'In' and 'Out' animations triggered only by state changes from false -> true
(Don't trigger In/Out animations when state changes from true -> false)
1 parent 39e226f commit 2148093

File tree

73 files changed

+93
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+93
-88
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ and use them in the template:
7878

7979
### Animations with state or triggered by state changes
8080

81-
These animations take as an input a boolean value. Some of animations, like Attention Seekers are triggered by any changes of the state, but others like `collapse` or `rotate` animations are displaying default state when the value is `falsy` and transition to end state when the value is `truthy`
81+
These animations take as an input a boolean value. Some animations, like Attention Seekers are triggered by any changes of the state, all `in` and `out` animations are triggered by changes of state from `false` to `true`. Animations that preserve state, like `collapse` or `rotate` display default state when the value is `false` and transition to end state when the value is `true`
8282

8383
```ts
8484
import { collapseAnimation, rubberBandAnimation } from 'angular-animations';

demo-app/src/app/demo-dynamic-params/demo-dynamic-params.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ <h1 [@enter1]="{ value: '', params: { delay: 0 } }">
145145
<app-angular-img *ngSwitchCase="'rollIn'" [@rollIn]="{ value: animationState, params: { duration: duration, delay: delay, degrees: degrees, translate: translate }}"></app-angular-img>
146146
<app-angular-img *ngSwitchCase="'rollOut'" [@rollOut]="{ value: animationState, params: { duration: duration, delay: delay, degrees: degrees, translate: translate }}"></app-angular-img>
147147
<!-- Other -->
148-
<app-angular-img *ngSwitchCase="'collapse'" [@collapse]="{ value: animationState, params: { duration: duration, delay: delay }}"></app-angular-img>
149-
<app-angular-img *ngSwitchCase="'rotate'" [@rotate]="{ value: animationState, params: { duration: duration, delay: delay, degrees: degrees }}"></app-angular-img>
148+
<app-angular-img *ngSwitchCase="'collapse'" [@collapse]="{ value: animationWithState, params: { duration: duration, delay: delay }}"></app-angular-img>
149+
<app-angular-img *ngSwitchCase="'rotate'" [@rotate]="{ value: animationWithState, params: { duration: duration, delay: delay, degrees: degrees }}"></app-angular-img>
150150
<app-angular-img *ngSwitchCase="'hueRotate'" [@hueRotate]="{ value: animationState, params: { duration: duration, delay: delay }}"></app-angular-img>
151151
<div *ngSwitchDefault>Select animaion</div>
152152
</div>

demo-app/src/app/demo-dynamic-params/demo-dynamic-params.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,19 @@ export class DemoDynamicParamsComponent implements OnInit {
269269
];
270270
animation = 'pulse';
271271
animationState = false;
272+
animationWithState = false;
272273

273274
animate() {
274-
this.animationState = !this.animationState;
275+
this.animationState = false;
276+
setTimeout(() => {
277+
this.animationState = !this.animationState;
278+
this.animationWithState = !this.animationWithState;
279+
}, 1);
275280
}
276281

277282
animationChanged() {
278283
this.setDefaultParams();
279-
this.animateAfterChange();
284+
this.animate();
280285
}
281286

282287
setDefaultParams() {
@@ -412,12 +417,6 @@ export class DemoDynamicParamsComponent implements OnInit {
412417
}
413418
}
414419

415-
animateAfterChange() {
416-
setTimeout(() => {
417-
this.animate();
418-
}, 1);
419-
}
420-
421420
ngOnInit() {
422421
this.setDefaultParams();
423422
}

demo-app/src/app/demo-main/demo-main.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ <h1 [@enter1]>
9595
<app-angular-img *ngSwitchCase="'rollIn'" [@rollIn]="animationState"></app-angular-img>
9696
<app-angular-img *ngSwitchCase="'rollOut'" [@rollOut]="animationState"></app-angular-img>
9797
<!-- Other -->
98-
<app-angular-img *ngSwitchCase="'collapse'" [@collapse]="animationState"></app-angular-img>
99-
<app-angular-img *ngSwitchCase="'rotate'" [@rotate]="animationState"></app-angular-img>
100-
<app-angular-img *ngSwitchCase="'rotate90'" [@rotate90]="animationState"></app-angular-img>
101-
<app-angular-img *ngSwitchCase="'rotate720'" [@rotate]="{value: animationState, params: { duration: 700, degrees: 720 } }"></app-angular-img>
98+
<app-angular-img *ngSwitchCase="'collapse'" [@collapse]="animationWithState"></app-angular-img>
99+
<app-angular-img *ngSwitchCase="'rotate'" [@rotate]="animationWithState"></app-angular-img>
100+
<app-angular-img *ngSwitchCase="'rotate90'" [@rotate90]="animationWithState"></app-angular-img>
101+
<app-angular-img *ngSwitchCase="'rotate720'" [@rotate]="{value: animationWithState, params: { duration: 700, degrees: 720 } }"></app-angular-img>
102102
<app-angular-img *ngSwitchCase="'hueRotate'" [@hueRotate]="animationState"></app-angular-img>
103103
<div *ngSwitchDefault>Select animaion</div>
104104
</div>
105105

106106

107107
<div [@enter3] (@enter3.done)="animationState = !animationState">
108108
<mat-form-field appearance="outline">
109-
<mat-select [(ngModel)]="animation" (ngModelChange)="animateAfterChange()">
109+
<mat-select [(ngModel)]="animation" (ngModelChange)="animate()">
110110
<mat-optgroup *ngFor="let option of options" [label]="option.label">
111111
<mat-option *ngFor="let animation of option.animations" [value]="animation">{{animation}}</mat-option>
112112
</mat-optgroup>

demo-app/src/app/demo-main/demo-main.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,14 @@ export class DemoMainComponent {
261261
];
262262
animation = 'rubberBand';
263263
animationState = false;
264+
animationWithState = false;
264265
hueBtnState = false;
265266

266267
animate() {
267-
this.animationState = !this.animationState;
268-
}
269-
270-
animateAfterChange() {
268+
this.animationState = false;
271269
setTimeout(() => {
272-
this.animate();
270+
this.animationState = true;
271+
this.animationWithState = !this.animationWithState;
273272
}, 1);
274273
}
275274
}

demo-app/src/app/experiments/experiments.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<app-angular-img *ngFor="let i of [0,1,2,3,4]" [@enter]="{value: '', params: { delay: i * 150 }}" (@enter.done)="hueState = !hueState"></app-angular-img>
44
</div>
55

6-
<button [@btnEnter] [@btnEnterFadeIn] mat-stroked-button color="primary" class="animate-btn" (click)="animationState = !animationState;">Animate
6+
<button [@btnEnter] [@btnEnterFadeIn] mat-stroked-button color="primary" class="animate-btn" (click)="animate()">Animate
77
letters</button>
88

99
<div [@flash]="flashState">

demo-app/src/app/experiments/experiments.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,12 @@ export class ExperimentsComponent implements OnInit {
5050
}
5151
}
5252

53+
animate() {
54+
this.animationState = false;
55+
setTimeout(() => {
56+
this.animationState = true;
57+
}, 1);
58+
}
59+
5360
ngOnInit() {}
5461
}

lib/bouncing-entrances/bounce-in-down.animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const DEFAULT_DURATION = 1000;
5151
export function bounceInDownAnimation(options?: IBounceInDownAnimationOptions): AnimationTriggerMetadata {
5252
return trigger((options && options.anchor) || 'bounceInDown', [
5353
transition(
54-
'0 <=> 1',
54+
'0 => 1',
5555
[
5656
...(options && options.animateChildren === 'before' ? [query('@*', animateChild(), { optional: true })] : []),
5757
group([

lib/bouncing-entrances/bounce-in-left.animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const DEFAULT_DURATION = 1000;
5151
export function bounceInLeftAnimation(options?: IBounceInLeftAnimationOptions): AnimationTriggerMetadata {
5252
return trigger((options && options.anchor) || 'bounceInLeft', [
5353
transition(
54-
'0 <=> 1',
54+
'0 => 1',
5555
[
5656
...(options && options.animateChildren === 'before' ? [query('@*', animateChild(), { optional: true })] : []),
5757
group([

lib/bouncing-entrances/bounce-in-right.animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const DEFAULT_DURATION = 1000;
5151
export function bounceInRightAnimation(options?: IBounceInRightAnimationOptions): AnimationTriggerMetadata {
5252
return trigger((options && options.anchor) || 'bounceInRight', [
5353
transition(
54-
'0 <=> 1',
54+
'0 => 1',
5555
[
5656
...(options && options.animateChildren === 'before' ? [query('@*', animateChild(), { optional: true })] : []),
5757
group([

0 commit comments

Comments
 (0)