From 11975e6e2098dfd40bea9bb1ce301bc120db2a62 Mon Sep 17 00:00:00 2001 From: Andrew Seguin Date: Fri, 28 Jul 2017 12:54:20 -0700 Subject: [PATCH] revert(5422): chore(dialog): switch to OnPush change detection (#6123) * fix(sidenav): animate sidenav on open/close changes * Revert "chore(dialog): switch to OnPush change detection (#5422)" This reverts commit cf071c75f5dd03a5684eb2984eacef427afe94d9. --- src/lib/dialog/dialog-container.ts | 18 ++---------------- src/lib/sidenav/sidenav.ts | 10 +++------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/lib/dialog/dialog-container.ts b/src/lib/dialog/dialog-container.ts index f70b14d5a590..24cc5f96958d 100644 --- a/src/lib/dialog/dialog-container.ts +++ b/src/lib/dialog/dialog-container.ts @@ -16,8 +16,6 @@ import { EventEmitter, Inject, Optional, - ChangeDetectionStrategy, - ChangeDetectorRef, } from '@angular/core'; import { animate, @@ -51,7 +49,6 @@ export function throwMdDialogContentAlreadyAttachedError() { selector: 'md-dialog-container, mat-dialog-container', templateUrl: 'dialog-container.html', styleUrls: ['dialog.css'], - changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, animations: [ trigger('slideDialog', [ @@ -107,7 +104,6 @@ export class MdDialogContainer extends BasePortalHost { private _ngZone: NgZone, private _elementRef: ElementRef, private _focusTrapFactory: FocusTrapFactory, - private _changeDetectorRef: ChangeDetectorRef, @Optional() @Inject(DOCUMENT) _document: any) { super(); @@ -124,12 +120,7 @@ export class MdDialogContainer extends BasePortalHost { } this._savePreviouslyFocusedElement(); - const componentRef = this._portalHost.attachComponentPortal(portal); - - // Ensure that the initial view change are picked up. - componentRef.changeDetectorRef.markForCheck(); - - return componentRef; + return this._portalHost.attachComponentPortal(portal); } /** @@ -142,12 +133,7 @@ export class MdDialogContainer extends BasePortalHost { } this._savePreviouslyFocusedElement(); - const locals = this._portalHost.attachTemplatePortal(portal); - - // Ensure that the initial view change are picked up. - this._changeDetectorRef.markForCheck(); - - return locals; + return this._portalHost.attachTemplatePortal(portal); } /** Moves the focus inside the focus trap. */ diff --git a/src/lib/sidenav/sidenav.ts b/src/lib/sidenav/sidenav.ts index 62372e1c739a..329a5b066776 100644 --- a/src/lib/sidenav/sidenav.ts +++ b/src/lib/sidenav/sidenav.ts @@ -379,13 +379,6 @@ export class MdSidenavContainer implements AfterContentInit { this._watchSidenavAlign(sidenav); }); this._validateDrawers(); - - // Give the view a chance to render the initial state, then enable transitions. Note that we - // don't use data binding, because we're not guaranteed that newer version of Angular will - // re-evaluate them after we set the flag here. - first.call(this._ngZone.onMicrotaskEmpty).subscribe(() => { - this._renderer.addClass(this._element.nativeElement, 'mat-sidenav-transition'); - }); } /** Calls `open` of both start and end sidenavs */ @@ -409,6 +402,9 @@ export class MdSidenavContainer implements AfterContentInit { */ private _watchSidenavToggle(sidenav: MdSidenav): void { merge(sidenav.onOpenStart, sidenav.onCloseStart).subscribe(() => { + // Set the transition class on the container so that the animations occur. This should not + // be set initially because animations should only be triggered via a change in state. + this._renderer.addClass(this._element.nativeElement, 'mat-sidenav-transition'); this._changeDetectorRef.markForCheck(); });