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

Add more EmberAnimation config #244

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions web/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

<Modals />

<div class="absolute top-0 left-0">
<AnimatedOrphans />
</div>

{{#if this.animatedToolsAreShown}}
<AnimatedTools />
{{/if}}
55 changes: 55 additions & 0 deletions web/app/utils/ember-animated/animate-scale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Modified from
// https://github.com/ember-animation/ember-animated/issues/38#issuecomment-392276685

import { Motion, rAF, Sprite, Tween } from 'ember-animated';
import { BaseOptions } from 'ember-animated/-private/motion';
import { TweenLike } from 'ember-animated/-private/tween';

interface AnimateScaleOptions extends BaseOptions {
from?: number;
to?: number;
easing?: (time: number) => number;
}

export class AnimatedScale extends Motion<AnimateScaleOptions> {
prior: Motion<AnimateScaleOptions> | null | undefined = null;
tween: TweenLike | null = null;

interrupted(motions: Motion[]): void {
this.prior = motions.find((m: Motion) => m instanceof this.constructor);
}

*animate(): Generator<Promise<unknown>, void> {
let { sprite, duration, opts } = this;
let to =
opts.to != null
? opts.to
: sprite.finalComputedStyle != null
? parseFloat(sprite.finalComputedStyle.opacity)
: 1;
let from;

from =
opts.from != null
? opts.from
: sprite.initialComputedStyle != null
? parseFloat(sprite.initialComputedStyle.opacity)
: 0;

this.tween = new Tween(from, to, duration);

while (!this.tween.done) {
sprite.applyStyles({
transform: `scale(${this.tween.currentValue})`,
});
yield rAF();
}
}
}

export default function animateScale(
sprite: Sprite,
opts?: Partial<AnimateScaleOptions>
): Promise<unknown> {
return new AnimatedScale(sprite, opts).run();
}
9 changes: 9 additions & 0 deletions web/app/utils/ember-animated/easings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://spicyyoghurt.com/tools/easing-functions

let b = 0; // start value
let c = 1; // change
let d = 1; // duration

export function easeOutQuad(time: number): number {
return -c * (time /= d) * (time - 2) + b;
}
1 change: 1 addition & 0 deletions web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"app/**/*",
"tests/**/*",
"types/**/*",
"node_modules/@gavant/glint-template-types/types/ember-animated/*",
"node_modules/@gavant/glint-template-types/types/ember-click-outside/modifier.d.ts",
"node_modules/@gavant/glint-template-types/types/ember-concurrency/perform.d.ts",
"node_modules/@gavant/glint-template-types/types/ember-on-helper/on-document.d.ts",
Expand Down
1 change: 1 addition & 0 deletions web/types/ember-animated/transition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type EmberAnimatedTransition = Generator<unknown, void, void>;