Skip to content

Instantly share code, notes, and snippets.

@Alonski
Created February 19, 2020 20:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Alonski/07fdbc4b652069f2f5bd4d70e2f7f5f0 to your computer and use it in GitHub Desktop.
Save Alonski/07fdbc4b652069f2f5bd4d70e2f7f5f0 to your computer and use it in GitHub Desktop.
Ember.JS Ember Animated Route Transition Animations
<AnimatedOrphans />{{outlet}}
<AnimatedValue
@value={{this.router.currentRouteName}}
@initialInsertion={{true}}
@finalRemoval={{true}}
@use={{this.transition}}
@duration={{600}}
>
{{yield}}
</AnimatedValue>
import Component from "@glimmer/component";
import { action } from "@ember/object";
import opacity from "ember-animated/motions/opacity";
import Sprite from "ember-animated/-private/sprite";
interface TransitionContext {
duration: number;
insertedSprites: Sprite[];
removedSprites: Sprite[];
receivedSprites: Sprite[];
}
export default class FadeAnimationComponent extends Component {
@action
protected *transition(transitionContext: TransitionContext): IterableIterator<unknown> {
yield;
const { insertedSprites, removedSprites, receivedSprites, duration } = transitionContext;
insertedSprites.forEach((sprite: Sprite) => {
opacity(sprite, { from: 0, to: 1 });
});
receivedSprites.forEach((sprite: Sprite) => {
opacity(sprite, { to: 1 });
});
removedSprites.forEach((sprite: Sprite) => {
opacity(sprite, { to: 0, duration: duration / 3 });
});
}
}
<FadeAnimation>
// Route content
</FadeAnimation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment