BaseView.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0}), (i.VIEW_CLOSE_TYPE = void 0);
  5. const s = t("ViewAni"),
  6. o = t("App"),
  7. a = t("ViewManager");
  8. var n;
  9. ((t = n = i.VIEW_CLOSE_TYPE || (i.VIEW_CLOSE_TYPE = {}))[(t.NORMAL = 0)] = "NORMAL"),
  10. (t[(t.DESTORY_VIEW = 1)] = "DESTORY_VIEW"),
  11. (t[(t.DESTORY_VIEW_AND_RES = 2)] = "DESTORY_VIEW_AND_RES"),
  12. (i.default = class extends cc.Component {
  13. constructor() {
  14. super(...arguments),
  15. (this.controller = null),
  16. (this._myParent = null),
  17. (this._isInit = !1),
  18. (this.bgType = 0),
  19. (this.closeType = n.DESTORY_VIEW),
  20. (this.bgImg = null),
  21. (this.viewId = null),
  22. (this._isFullScreen = !1),
  23. (this.isEnterAniFInish = !1),
  24. (this.closeResole = null),
  25. (this.initComplete = null);
  26. }
  27. isFullScreen() {
  28. return this._isFullScreen;
  29. }
  30. start() {
  31. (this.viewAni = this.getComponent(s.default)),
  32. this.viewAni && (this.viewAni.view = this),
  33. this.initComplete && ((this.enabled = !1), this.initComplete(), (this.initComplete = null));
  34. }
  35. enterAniFinish() {
  36. this.isEnterAniFInish = !0;
  37. }
  38. exitAniFinish() {
  39. this.isEnterAniFInish = !1;
  40. }
  41. isInit() {
  42. return this._isInit;
  43. }
  44. applyFunc(t) {
  45. return this.controller.applyFunc.apply(this.controller, arguments);
  46. }
  47. applyControllerFunc(t, e) {
  48. return this.controller.applyControllerFunc.apply(this.controller, arguments);
  49. }
  50. isShow() {
  51. return this.node.parent && this.node.active && (!this.viewAni || !this.viewAni.isExiting);
  52. }
  53. addToParent(t) {
  54. this.node.parent || (t.addChild(this.node), o.default.ViewManager.checkIsNeedAddBg(), this.playEnterAni());
  55. }
  56. onExitAniFinish() {
  57. this.closeType == n.DESTORY_VIEW
  58. ? o.default.ViewManager.destoryView(this.viewId)
  59. : this.closeType == n.DESTORY_VIEW_AND_RES &&
  60. (o.default.ViewManager.destoryView(this.viewId), o.default.ViewManager.releaseViewRes(this.viewId));
  61. }
  62. removeFromParent() {
  63. this.viewAni && this.viewAni.isExitAni() && this.viewAni.enabled
  64. ? this.viewAni.onExit()
  65. : (this.node && this.node.parent && this.node.parent.removeChild(this.node, !1),
  66. (this.node.active = !1),
  67. o.default.ViewManager.checkIsNeedAddBg(),
  68. this.onExitAniFinish());
  69. }
  70. initUI() {
  71. this._isInit = !0;
  72. }
  73. onTouchClose() {
  74. o.default.ViewManager.closeView(this);
  75. }
  76. awaitClose() {
  77. return (
  78. this.closePromise ||
  79. ((this.closePromise = new Promise(t => {
  80. this.closeResole = t;
  81. })),
  82. this.closePromise)
  83. );
  84. }
  85. onTouchBg() {}
  86. initData() {}
  87. destroyView() {
  88. (this.controller = null), (this._myParent = null);
  89. }
  90. open() {
  91. this.sendOpenMsg();
  92. }
  93. playEnterAni() {
  94. (this.viewAni = this.getComponent(s.default)),
  95. this.viewAni && this.viewAni.enabled
  96. ? (this.viewAni.view = this).viewAni.onEnter()
  97. : this.enterAniFinish();
  98. }
  99. reOpen() {}
  100. close() {
  101. (this.initComplete = null),
  102. this.sendCloseMsg(),
  103. this.closeResole && (this.closeResole(), (this.closeResole = null), (this.closePromise = null));
  104. }
  105. sendOpenMsg() {}
  106. changeScenePre() {}
  107. sendCloseMsg() {
  108. o.default.NotificationCenter.dispatch(a.ViewManagerEvent.VIEW_IS_CLOSE, this.viewId);
  109. }
  110. closeView() {
  111. o.default.ViewManager.closeView(this);
  112. }
  113. onDestroy() {
  114. o.default.TimerManager.removeAll(this), o.default.NotificationCenter.removeAll(this);
  115. }
  116. loadResource() {
  117. return new Promise(t => {
  118. this.initComplete = t;
  119. });
  120. }
  121. setVisible(t) {
  122. this.node.active = t;
  123. }
  124. });