Skip to content

Commit ae6bc0a

Browse files
authored
fix(button): use animationFrameScheduler in place of requestAnimation… (#16645)
* fix(button): use animationFrameScheduler in place of requestAnimationFrame Closes #16638 * refactor(button): unsubscribe from animationFrameScheduler on destroy
1 parent 7a28f9c commit ae6bc0a

File tree

1 file changed

+10
-3
lines changed
  • projects/igniteui-angular/directives/src/directives/button

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 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 'igniteui-angular/core';
15+
import { animationFrameScheduler, Subscription } from 'rxjs';
1416

1517
export const IgxBaseButtonType = {
1618
Flat: 'flat',
@@ -20,10 +22,11 @@ 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
public element = inject(ElementRef);
26-
private _viewInit = false;
28+
private _viewInit = false;
29+
private _animationScheduler: Subscription;
2730

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

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

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

0 commit comments

Comments
 (0)