index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Effect, ModuleControl } from "queenjs";
  2. import { EditorModule } from "../../module";
  3. import { DesignComp } from "../../objects/DesignTemp/DesignComp";
  4. import { Matrix } from "../SelectCtrl/matrix";
  5. export class AnimCtrl extends ModuleControl<EditorModule> {
  6. initEvent() {
  7. Effect.value(()=>this.store.shortPage).item((v)=>v.offset, (shortState)=>{
  8. console.log("xx")
  9. let next = shortState.index;
  10. if (shortState.offset < 0 ) {
  11. next = shortState.index + 1;
  12. }
  13. if (shortState.offset > 0 ) {
  14. next = shortState.index - 1;
  15. }
  16. this.initAnim();
  17. this.startAnim(next);
  18. }).run();
  19. }
  20. startAnim(index:number) {
  21. const childrens = this.helper.findCardAllChildren(index);
  22. console.log("start anim=>", index, childrens.length);
  23. childrens.forEach((c)=>{
  24. const comp = this.helper.findComp(c) as DesignComp;
  25. if (!comp.anim) return;
  26. comp.anim.transition = false;
  27. comp.layout.transformMatrix = comp.anim.startMatrix;
  28. comp.layout.opacity = 0;
  29. setTimeout(() => {
  30. if (comp.anim) {
  31. comp.anim.transition = true;
  32. comp.layout.transformMatrix = comp.anim.endMatrix;
  33. comp.layout.opacity = 1;
  34. }
  35. }, 100);
  36. })
  37. }
  38. inited = false;
  39. initAnim() {
  40. if (this.inited) return;
  41. this.inited = true;
  42. let n = this.store.streamCardIds.length;
  43. for( let i=0; i<n; i++) {
  44. const childrens = this.helper.findCardAllChildren(i);
  45. childrens.forEach((c)=>{
  46. const comp = this.helper.findComp(c) as DesignComp;
  47. const end = comp.layout.transformMatrix || "matrix(1,0,0,1,0,0)";
  48. const m = Matrix.createFromMatrixStr(end);
  49. m.ty = m.ty - comp.getH();
  50. m.tx = m.tx - comp.getW();
  51. comp.anim = {transition:false, startMatrix: m.getMatrixStr(), endMatrix: end}
  52. })
  53. }
  54. }
  55. }