exit.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Feature } from '../Feature.mjs';
  2. let id = 0;
  3. class ExitAnimationFeature extends Feature {
  4. constructor() {
  5. super(...arguments);
  6. this.id = id++;
  7. }
  8. update() {
  9. if (!this.node.presenceContext)
  10. return;
  11. const { isPresent, onExitComplete } = this.node.presenceContext;
  12. const { isPresent: prevIsPresent } = this.node.prevPresenceContext || {};
  13. if (!this.node.animationState || isPresent === prevIsPresent) {
  14. return;
  15. }
  16. const exitAnimation = this.node.animationState.setActive("exit", !isPresent);
  17. if (onExitComplete && !isPresent) {
  18. exitAnimation.then(() => {
  19. onExitComplete(this.id);
  20. });
  21. }
  22. }
  23. mount() {
  24. const { register, onExitComplete } = this.node.presenceContext || {};
  25. if (onExitComplete) {
  26. onExitComplete(this.id);
  27. }
  28. if (register) {
  29. this.unmount = register(this.id);
  30. }
  31. }
  32. unmount() { }
  33. }
  34. export { ExitAnimationFeature };