Skip to content

Commit

Permalink
fix(material/sidenav): remove deprecated API usage (#30268)
Browse files Browse the repository at this point in the history
The sidenav was using `AfterRenderPhase` which is deprecated. These changes switch it to the supported API.
  • Loading branch information
crisbeto authored Jan 7, 2025
1 parent 980f9ba commit 66741b8
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/material/sidenav/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
afterNextRender,
AfterRenderPhase,
AfterViewInit,
ANIMATION_MODULE_TYPE,
ChangeDetectionStrategy,
Expand Down Expand Up @@ -966,31 +965,21 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
* re-validate drawers when the position changes.
*/
private _watchDrawerPosition(drawer: MatDrawer): void {
if (!drawer) {
return;
}
// NOTE: We need to wait for the microtask queue to be empty before validating,
// since both drawers may be swapping positions at the same time.
drawer.onPositionChanged.pipe(takeUntil(this._drawers.changes)).subscribe(() => {
afterNextRender(
() => {
this._validateDrawers();
},
{injector: this._injector, phase: AfterRenderPhase.Read},
);
afterNextRender({read: () => this._validateDrawers()}, {injector: this._injector});
});
}

/** Subscribes to changes in drawer mode so we can run change detection. */
private _watchDrawerMode(drawer: MatDrawer): void {
if (drawer) {
drawer._modeChanged
.pipe(takeUntil(merge(this._drawers.changes, this._destroyed)))
.subscribe(() => {
this.updateContentMargins();
this._changeDetectorRef.markForCheck();
});
}
drawer._modeChanged
.pipe(takeUntil(merge(this._drawers.changes, this._destroyed)))
.subscribe(() => {
this.updateContentMargins();
this._changeDetectorRef.markForCheck();
});
}

/** Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. */
Expand Down

0 comments on commit 66741b8

Please sign in to comment.