Skip to content

Commit 0e502b9

Browse files
authored
fix(button): use animationFrameScheduler in place of requestAnimation… (#16643)
* fix(button): use animationFrameScheduler in place of requestAnimationFrame Closes #16638 * refactor(button): unsubscribe from animationFrameScheduler on destroy
1 parent 791f620 commit 0e502b9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

projects/igniteui-angular/src/lib/directives/button/button-base.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
booleanAttribute,
1010
inject,
1111
AfterViewInit,
12+
OnDestroy
1213
} from '@angular/core';
1314
import { PlatformUtil } from '../../core/utils';
15+
import { animationFrameScheduler, Subscription } from 'rxjs';
1416

1517
export const IgxBaseButtonType = {
1618
Flat: 'flat',
@@ -20,9 +22,10 @@ export const IgxBaseButtonType = {
2022

2123

2224
@Directive()
23-
export abstract class IgxButtonBaseDirective implements AfterViewInit{
25+
export abstract class IgxButtonBaseDirective implements AfterViewInit, OnDestroy {
2426
private _platformUtil = inject(PlatformUtil);
2527
private _viewInit = false;
28+
private _animationScheduler: Subscription;
2629

2730
/**
2831
* Emitted when the button is clicked.
@@ -110,12 +113,16 @@ export abstract class IgxButtonBaseDirective implements AfterViewInit{
110113
if (this._platformUtil.isBrowser && !this._viewInit) {
111114
this._viewInit = true;
112115

113-
requestAnimationFrame(() => {
116+
this._animationScheduler = animationFrameScheduler.schedule(() => {
114117
this.element.nativeElement.style.removeProperty('--_init-transition');
115118
});
116119
}
117120
}
118121

122+
public ngOnDestroy(): void {
123+
this._animationScheduler.unsubscribe();
124+
}
125+
119126
/**
120127
* @hidden
121128
* @internal

0 commit comments

Comments
 (0)