Skip to content

Commit d0fef43

Browse files
authored
remove deprecated animations API (#2916)
### Fixes # <!-- Mention the issues this PR addresses --> ### Checks - [ ] Ran `yarn test-build` - [ ] Updated relevant documentations - [ ] Updated matching config options in altair-static ### Changes proposed in this pull request: <!-- Describe the changes being introduced in this PR --> ## Summary by Sourcery Migrate components away from the deprecated Angular animations API to a CSS-based animation system with global utility classes and enable OnPush change detection for better performance Enhancements: - Remove Angular animations triggers and related imports from several components - Replace in-template animation bindings with animate.enter/leave attributes backed by CSS utility classes - Introduce a new global SCSS file defining animation keyframes and utility classes - Enable OnPush change detection on affected components - Import the new animations stylesheet into the main styles <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Modernized animation system throughout the application with improved CSS-based animation utilities for fade and slide transitions. * Optimized component performance by implementing more efficient change detection strategies. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 6efdf5f commit d0fef43

File tree

10 files changed

+85
-62
lines changed

10 files changed

+85
-62
lines changed

packages/altair-app/src/app/modules/altair/components/confirm-toast/confirm-toast.component.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
import {
2-
animate,
3-
keyframes,
4-
state,
5-
style,
6-
transition,
7-
trigger,
8-
} from '@angular/animations';
91
import { ChangeDetectionStrategy, Component } from '@angular/core';
102
import { Toast } from 'ngx-toastr';
113

124
@Component({
135
selector: 'app-confirm-toast',
146
templateUrl: './confirm-toast.component.html',
157
styles: [],
16-
animations: [
17-
trigger('flyInOut', [
18-
state('inactive', style({ opacity: 0 })),
19-
state('active', style({ opacity: 1 })),
20-
state('removed', style({ opacity: 0 })),
21-
transition('inactive => active', animate('{{ easeTime }}ms {{ easing }}')),
22-
transition('active => removed', animate('{{ easeTime }}ms {{ easing }}')),
23-
]),
24-
],
258
standalone: false,
26-
// components with animations don't work well with OnPush change detection
27-
// changeDetection: ChangeDetectionStrategy.OnPush,
9+
changeDetection: ChangeDetectionStrategy.OnPush,
2810
})
2911
export class ConfirmToastComponent extends Toast {
3012
action(event: Event) {

packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer-search-results/doc-viewer-search-results.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<div
88
class="doc-viewer-search-result-item"
99
(click)="goToItem(result)"
10-
[@showResultItem]
10+
animate.enter="animate animate-slide-in"
11+
animate.leave="animate animate-fade-out"
1112
>
1213
@switch (result.cat) {
1314
@case ('type') {

packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer-search-results/doc-viewer-search-results.component.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,12 @@
1-
import { Component, ChangeDetectionStrategy, input, output } from '@angular/core';
2-
import { trigger, state, style, animate, transition } from '@angular/animations';
3-
import { GraphQLArgument } from 'graphql';
1+
import { ChangeDetectionStrategy, Component, input, output } from '@angular/core';
42
import { DocumentIndexEntry } from '../models';
53

64
@Component({
75
selector: 'app-doc-viewer-search-results',
86
templateUrl: './doc-viewer-search-results.component.html',
97
styleUrls: ['./doc-viewer-search-results.component.scss'],
10-
// eslint-disable-next-line @angular-eslint/component-max-inline-declarations
11-
animations: [
12-
trigger('showResultItem', [
13-
transition(':enter', [
14-
style({
15-
opacity: 0,
16-
transform: 'translateY(50%)',
17-
}),
18-
animate(
19-
200,
20-
style({
21-
opacity: 1,
22-
transform: 'translateY(0)',
23-
})
24-
),
25-
]),
26-
transition(':leave', [
27-
style({ height: '*' }), // Get the runtime height for use in the next transition
28-
animate(
29-
200,
30-
style({
31-
transform: 'translateY(150%)',
32-
opacity: 0,
33-
height: 0, // This works since we retrieved the runtime height previously
34-
})
35-
),
36-
]),
37-
]),
38-
],
398
standalone: false,
40-
// components with animations don't work well with OnPush change detection
41-
// changeDetection: ChangeDetectionStrategy.OnPush,
9+
changeDetection: ChangeDetectionStrategy.OnPush,
4210
})
4311
export class DocViewerSearchResultsComponent {
4412
readonly results = input<DocumentIndexEntry[]>([]);

packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer/doc-viewer.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
@if (allowIntrospection() && docView(); as docView) {
22
<div #docViewer class="app-doc-viewer">
33
@if (isLoading()) {
4-
<div class="app-doc-loader" [@fadeInOutAnimation]>
4+
<div
5+
class="app-doc-loader"
6+
animate.enter="animate animate-fade-in"
7+
animate.leave="animate animate-fade-out"
8+
>
59
<div class="app-doc-loader-content">
610
<img
711
src="assets/img/logo.svg"

packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer/doc-viewer.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { debug } from '../../../utils/logger';
1616
import { UntilDestroy } from '@ngneat/until-destroy';
1717
import { GraphQLSchema, GraphQLObjectType, GraphQLDirective } from 'graphql';
1818
import { DocumentIndexEntry } from '../models';
19-
import { fadeInOutAnimationTrigger } from '../../../animations';
2019
import { GqlService } from '../../../services';
2120
import getRootTypes from '../../../utils/get-root-types';
2221
import { DocView } from 'altair-graphql-core/build/types/state/docs.interfaces';
@@ -29,7 +28,6 @@ import { debounce } from 'lodash-es';
2928
@Component({
3029
selector: 'app-doc-viewer',
3130
templateUrl: './doc-viewer.component.html',
32-
animations: [fadeInOutAnimationTrigger],
3331
standalone: false,
3432
})
3533
export class DocViewerComponent {

packages/altair-app/src/app/modules/altair/components/tips/tips.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@if (currentTip) {
2-
<div class="tips" [@fadeInOutAnimation]>
2+
<div
3+
class="tips"
4+
animate.enter="animate animate-fade-in"
5+
animate.leave="animate animate-fade-out"
6+
>
37
<div class="tips-inner">
48
<span class="tips-title">Tip:</span>
59
{{ currentTip.text }}

packages/altair-app/src/app/modules/altair/components/tips/tips.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
OnDestroy,
44
effect,
55
input,
6+
ChangeDetectionStrategy,
67
} from '@angular/core';
78
import { rand } from '../../utils';
8-
import { fadeInOutAnimationTrigger } from '../../animations';
99

1010
interface Tip {
1111
text: string;
@@ -22,8 +22,8 @@ const DEFAULT_TIP_INTERVAL = 60000;
2222
selector: 'app-tips',
2323
templateUrl: './tips.component.html',
2424
styles: ``,
25-
animations: [fadeInOutAnimationTrigger],
2625
standalone: false,
26+
changeDetection: ChangeDetectionStrategy.OnPush,
2727
})
2828
export class TipsComponent implements OnDestroy {
2929
readonly activeWindowId = input('');

packages/altair-app/src/app/modules/altair/containers/window/window.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
} from '../../services';
3838
import { Observable, EMPTY, combineLatest, of } from 'rxjs';
3939
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
40-
import { fadeInOutAnimationTrigger } from '../../animations';
4140
import { IDictionary, TrackByIdItem } from '../../interfaces/shared';
4241
import collectVariables from 'codemirror-graphql/utils/collectVariables';
4342
import {
@@ -78,7 +77,6 @@ import { LoadingRequestStateEntry } from 'altair-graphql-core/build/types/state/
7877
@Component({
7978
selector: 'app-window',
8079
templateUrl: './window.component.html',
81-
animations: [fadeInOutAnimationTrigger],
8280
standalone: false,
8381
})
8482
export class WindowComponent implements OnInit {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.animate {
2+
transition-duration: 300ms;
3+
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
4+
animation-duration: 300ms;
5+
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
6+
will-change: opacity, transform;
7+
}
8+
9+
.animate--infinite {
10+
animation-iteration-count: infinite;
11+
}
12+
13+
.animate-fade-in {
14+
animation-name: animate-fade-in;
15+
}
16+
17+
@keyframes animate-fade-in {
18+
0% {
19+
opacity: 0;
20+
}
21+
100% {
22+
opacity: 1;
23+
}
24+
}
25+
26+
.animate-fade-out {
27+
animation-name: animate-fade-out;
28+
}
29+
30+
@keyframes animate-fade-out {
31+
0% {
32+
opacity: 1;
33+
}
34+
100% {
35+
opacity: 0;
36+
}
37+
}
38+
39+
.animate-slide-in {
40+
animation-name: animate-slide-in;
41+
}
42+
43+
@keyframes animate-slide-in {
44+
0% {
45+
opacity: 0;
46+
transform: translateY(50%);
47+
}
48+
100% {
49+
opacity: 1;
50+
transform: translateY(0);
51+
}
52+
}
53+
54+
.animate-slide-out {
55+
animation-name: animate-slide-out;
56+
}
57+
58+
@keyframes animate-slide-out {
59+
0% {
60+
opacity: 1;
61+
transform: translateY(0);
62+
}
63+
100% {
64+
opacity: 0;
65+
transform: translateY(50%);
66+
}
67+
}

packages/altair-app/src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
@import 'ngx-toastr/toastr';
88

99
@import 'scss/globals';
10+
@import 'scss/animations';
1011
@import 'scss/framework';
1112
@import 'scss/all';

0 commit comments

Comments
 (0)