@fengxi/ui-framework
Version:
Cocos Creator UI框架库 类似鸿蒙的UI框架
45 lines (44 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIManager = void 0;
const cc_1 = require("cc");
const SingletonMixin_1 = require("../base/SingletonMixin");
/**
* UI管理器
*/
class UIManager extends SingletonMixin_1.SingletonMixin {
constructor() {
super(...arguments);
this.currentPage = undefined;
}
static get Instance() {
return super.getInstance();
}
init() {
cc_1.game.on(cc_1.Game.EVENT_SHOW, this.onForeground.bind(this));
cc_1.game.on(cc_1.Game.EVENT_HIDE, this.onBackground.bind(this));
}
onForeground() {
if (this.currentPage) {
this.currentPage.onPageShow();
}
}
onBackground() {
if (this.currentPage) {
this.currentPage.onPageHide();
}
}
async changeCurrentPage(page, isReplace = false) {
if (!page || page === this.currentPage) {
return;
}
// 如果是replace 销毁当前页面
if (this.currentPage && isReplace) {
this.currentPage.aboutToDisappear();
}
this.currentPage = page;
await this.currentPage.aboutToAppear();
this.currentPage.appear();
}
}
exports.UIManager = UIManager;