Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel animation frames in Cubic Bezier preview. #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cubic-bezier/view/cubic-bezier-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class CubicBezierPreviewView implements View {
private readonly value_: Value<CubicBezier>;
private stopped_ = true;
private startTime_ = -1;
private requestId_ = -1;

constructor(doc: Document, config: Config) {
this.onDispose_ = this.onDispose_.bind(this);
Expand Down Expand Up @@ -71,10 +72,11 @@ export class CubicBezierPreviewView implements View {

this.startTime_ = new Date().getTime() + PREVIEW_DELAY;
this.stopped_ = false;
requestAnimationFrame(this.onTimer_);
this.requestId_ = requestAnimationFrame(this.onTimer_);
}

public stop(): void {
cancelAnimationFrame(this.requestId_);
this.stopped_ = true;
this.markerElem_.classList.remove(className('m', 'a'));
}
Expand Down Expand Up @@ -114,7 +116,7 @@ export class CubicBezierPreviewView implements View {
}

if (!this.stopped_) {
requestAnimationFrame(this.onTimer_);
this.requestId_ = requestAnimationFrame(this.onTimer_);
}
}

Expand Down