From f79cd57f757e2386f8e0288524e6fef8639f27c1 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 21 Oct 2023 22:36:47 +0800 Subject: [PATCH] feat: UiController.holdOn --- src/core/main/custom/ui.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/main/custom/ui.ts b/src/core/main/custom/ui.ts index 1fc25e5..0ac15ef 100644 --- a/src/core/main/custom/ui.ts +++ b/src/core/main/custom/ui.ts @@ -158,6 +158,8 @@ export class UiController extends Focus { list: Record = {}; num: number = 0; + private hold: boolean = false; + constructor(equal?: boolean) { super(true, equal); UiController.list.push(this); @@ -165,7 +167,8 @@ export class UiController extends Focus { spliced.forEach(v => { v.ui.emit('close'); if (this.stack.length === 0) { - this.emit('end'); + if (!this.hold) this.emit('end'); + this.hold = false; } }); }); @@ -194,6 +197,17 @@ export class UiController extends Focus { return this.list[id]; } + /** + * 暂时保持下一次删除ui不会导致ui整体被关闭,引起ui背景闪烁。 + * 例如可以用于道具栏,打开道具时就应当 holdOn,然后通过道具使用钩子来判断接下来是否要隐藏 app: + * ```txt + * hold on -> close -> use item -> hook -> stack.length === 0 ? hide app : no action + * ``` + */ + holdOn() { + this.hold = true; + } + /** * 关闭一个ui,注意如果不是平等模式,在其之后的ui都会同时关闭掉 * @param num 要关闭的ui的唯一标识符