Skip to content

Commit 2732bb4

Browse files
crisbetommalerba
authored andcommitted
chore(snack-bar): switch to OnPush change detection (#5515)
* Switches the snack bar component to `OnPush` change detection. * Removes the `detectChanges` workaround for the choppy animations, because it no longer works with `OnPush`. Properly fixes the initial issue by providing a `void` animation state. Relates to #5035.
1 parent 32db2ba commit 2732bb4

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/lib/snack-bar/simple-snack-bar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Component, ViewEncapsulation} from '@angular/core';
9+
import {Component, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
1010
import {MdSnackBarRef} from './snack-bar-ref';
1111

1212

@@ -20,6 +20,7 @@ import {MdSnackBarRef} from './snack-bar-ref';
2020
templateUrl: 'simple-snack-bar.html',
2121
styleUrls: ['simple-snack-bar.css'],
2222
encapsulation: ViewEncapsulation.None,
23+
changeDetection: ChangeDetectionStrategy.OnPush,
2324
host: {
2425
'class': 'mat-simple-snackbar',
2526
}

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
OnDestroy,
1515
Renderer2,
1616
ElementRef,
17+
ChangeDetectionStrategy,
1718
} from '@angular/core';
1819
import {
1920
trigger,
@@ -52,13 +53,15 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
5253
selector: 'snack-bar-container',
5354
templateUrl: 'snack-bar-container.html',
5455
styleUrls: ['snack-bar-container.css'],
56+
changeDetection: ChangeDetectionStrategy.OnPush,
5557
host: {
5658
'role': 'alert',
5759
'[@state]': 'animationState',
5860
'(@state.done)': 'onAnimationEnd($event)'
5961
},
6062
animations: [
6163
trigger('state', [
64+
state('void', style({transform: 'translateY(100%)'})),
6265
state('initial', style({transform: 'translateY(100%)'})),
6366
state('visible', style({transform: 'translateY(0%)'})),
6467
state('complete', style({transform: 'translateY(100%)'})),

src/lib/snack-bar/snack-bar.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ export class MdSnackBar {
135135
let containerPortal = new ComponentPortal(MdSnackBarContainer, config.viewContainerRef);
136136
let containerRef: ComponentRef<MdSnackBarContainer> = overlayRef.attach(containerPortal);
137137
containerRef.instance.snackBarConfig = config;
138-
139-
// The snackbar animation needs the content to be resolved in order to transform the bar
140-
// out of the view initially (so it can slide in). To make the content resolve, we manually
141-
// detect changes.
142-
containerRef.changeDetectorRef.detectChanges();
143-
144138
return containerRef.instance;
145139
}
146140

0 commit comments

Comments
 (0)