Skip to content

Commit 14ee548

Browse files
authored
build: add animations toggle to the dev app (#22669)
Adds a button that allows us to test noop animations without having to make code changes.
1 parent d374775 commit 14ee548

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/dev-app/dev-app/dev-app-layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ <h1>Angular Material Demos</h1>
4141
<button mat-icon-button (click)="toggleFullscreen()" title="Toggle fullscreen">
4242
<mat-icon>fullscreen</mat-icon>
4343
</button>
44+
<button mat-button (click)="toggleAnimations()">
45+
{{animationsDisabled ? 'Enable' : 'Disable'}} animations
46+
</button>
4447
<button mat-button (click)="isDark = !isDark">
4548
{{isDark ? 'Light' : 'Dark'}} theme
4649
</button>

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {DOCUMENT} from '@angular/common';
1515

1616
const isDarkThemeKey = 'ANGULAR_COMPONENTS_DEV_APP_DARK_THEME';
1717

18+
export const ANIMATIONS_STORAGE_KEY = 'ANGULAR_COMPONENTS_ANIMATIONS_DISABLED';
19+
1820
/** Root component for the dev-app demos. */
1921
@Component({
2022
selector: 'dev-app-layout',
@@ -111,6 +113,9 @@ export class DevAppLayout {
111113
/** List of possible global density scale values. */
112114
densityScales = [0, -1, -2, 'minimum', 'maximum'];
113115

116+
/** Whether animations are disabled. */
117+
animationsDisabled = localStorage.getItem(ANIMATIONS_STORAGE_KEY) === 'true';
118+
114119
constructor(
115120
private _element: ElementRef<HTMLElement>, public rippleOptions: DevAppRippleOptions,
116121
@Inject(Directionality) public dir: DevAppDirectionality, cdr: ChangeDetectorRef,
@@ -181,6 +186,10 @@ export class DevAppLayout {
181186
}
182187
}
183188

189+
toggleAnimations() {
190+
localStorage.setItem(ANIMATIONS_STORAGE_KEY, (!this.animationsDisabled) + '');
191+
location.reload();
192+
}
184193

185194
/** Gets the index of the next density scale that can be selected. */
186195
getNextDensityIndex() {

src/dev-app/main-module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ import {DevAppDirectionality} from './dev-app/dev-app-directionality';
1919
import {DevAppModule} from './dev-app/dev-app-module';
2020
import {DEV_APP_ROUTES} from './dev-app/routes';
2121
import {DevAppRippleOptions} from './dev-app/ripple-options';
22+
import {ANIMATIONS_STORAGE_KEY} from './dev-app/dev-app-layout';
2223

2324
@NgModule({
2425
imports: [
25-
BrowserAnimationsModule,
26+
BrowserAnimationsModule.withConfig({
27+
// Note that this doesn't seem to work on ViewEngine, but it's
28+
// not a compilation error either so we can live with it.
29+
disableAnimations: localStorage.getItem(ANIMATIONS_STORAGE_KEY) === 'true'
30+
}),
2631
BrowserModule,
2732
DevAppModule,
2833
HttpClientModule,

0 commit comments

Comments
 (0)