Skip to content

Commit

Permalink
fix(Overlay): export animationFrame$
Browse files Browse the repository at this point in the history
  • Loading branch information
HytonightYX committed Mar 18, 2022
1 parent 283eee6 commit 2379f57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { Observable } from 'rxjs';

export interface Disposable {
dispose(): void;
Expand Down Expand Up @@ -52,3 +53,18 @@ export function startAnimate(

return { dispose };
}

export const animationFrame$ = new Observable<number>((subscriber) => {
let handle: number;

const callback = (arg: number) => {
subscriber.next(arg);
handle = requestAnimationFrame(callback);
};

callback(performance.now());

return () => {
cancelAnimationFrame(handle);
};
});
2 changes: 1 addition & 1 deletion packages/core/src/components/overlays/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class Toast extends React.Component<ToastProps, ToastState> {
componentDidUpdate(prevProps: unknown, prevState: Readonly<ToastState>) {
const { shrinking } = this.state;
if (!prevState.shrinking && shrinking) {
const disposable = startAnimate(this.shrinkingRef.current, Overlay.animations.zeroHeight, () => {
const disposable = startAnimate(this.shrinkingRef.current, Overlay.animations.zeroHeight.getName(), () => {
this.clear();
});
this.subscription.add(() => disposable.dispose());
Expand Down

0 comments on commit 2379f57

Please sign in to comment.