diff --git a/.gitignore b/.gitignore
index ea27eaff8c3ecef3e9ebe6399a5f9073cd962a7b..54890a3f04d1eaeab58cacd10d637988fbc11621 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,5 @@
/.clang-tidy
**/.test
/.appanalyzer
+/build-profile.json5
oh-package-lock.json5
\ No newline at end of file
diff --git a/docs/Reference.md b/docs/Reference.md
index f228e6909b4fca9563bbb066fba17fa51b6d84c9..4d423d7e5f06f5696220b26dd8d3bc2e64d1044b 100644
--- a/docs/Reference.md
+++ b/docs/Reference.md
@@ -41,7 +41,8 @@
| 方法名 | 类型 | 使用说明 |
|----------------------------------|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static init | (uicontext: UIContext) => void | 用于置顶默认的弹窗上下文,并且将弹窗绑定至特定页面 |
-| static getCurrentPageDialogs | () => infDialog
(type: DialogType) => InfDialog[]
(modelName: string) => InfDialog[] | 根据弹窗类型,弹窗状态获取当前页面的弹窗;DEFAULT状态的弹窗不属于任何页面
数组返回的顺序按照最新show的在第一个元素; |
+| static getCurrentPageDialogs | () => infDialog
(type: DialogType) => InfDialog[]
(modelName: string) => InfDialog[] | 根据弹窗类型,模板名称获取当前页面的弹窗;DEFAULT状态的弹窗不属于任何页面
数组返回的顺序按照最新show的在第一个元素; |
+| static getCurrentPageDialogsByStatus | (status?: DialogStatus) => InfDialog[] | 根据弹窗状态,获取当前页面的弹窗;
数组返回的顺序按照最新show的在第一个元素; |
| static dispatchBackPressToDialog | () => DialogBackPressResult | 向DialogHub的弹窗分发BackPress事件,即尝试关闭当前页面最上层的弹窗,并返回对应的结果;
说明:DialogHub弹出的弹窗默认不响应侧滑手势,有诉求的开发者可以在弹窗所在页面的onBackPress生命周期调用本方法模拟弹窗响应侧滑返回手势
(注:BindSheet类型弹窗会自动处理BackPress事件关闭弹窗,无需在OnBackPress中分发事件) |
| static addEventListener | (listener: GlobalEvent) => void | 增加全局的弹窗事件监听 |
| static removeEventListener | (listener: GlobalEvent) => void | 移除全局的弹窗事件监听 |
@@ -325,6 +326,7 @@ Builder与Template关系图
| addLifecycleListener | (listener: **DialogLifeCycle**) => **void** | 添加生命周期监听,多次监听不会前后覆盖,而是多次触发 |
| removeLifecycleListener | (listener: **DialogLifeCycle**) => **void** | 删除生命周期监听 |
| show | () => boolean | 展示弹窗,允许指定当次弹窗弹出的上下文 |
+| hide | () => boolean | 隐藏弹窗(节点不下树) |
| dismiss | () => boolean | 关闭弹窗(对应节点下树) |
| updateContent | (param: T) => **void** | 更新开发者给弹窗指定的参数;要求传入类型与弹窗内容Builder的入参保持一致,否则会报错 |
| updateStyle | (param: **DialogStyle**) => void | 更新基本样式 |
@@ -335,6 +337,8 @@ Builder与Template关系图
|---------------|-------------------------------------------|----------------------------------------------------------------------------------------------|
| onShow | () => void | 弹出
说明:弹窗跟随页面自动隐藏/恢复不出发show/willShow生命周期 |
| onWillShow | () => boolean | 即将弹出,
返回true,表示允许本次show
返回false,表示拒绝本次show
说明:弹窗跟随页面自动隐藏/恢复时不出发show/willShow生命周期 |
+| onHide | () => void | 隐藏弹窗 |
+| onWillHide | () => boolean | 即将隐藏 |
| onDismiss | () => void | 关闭 |
| onWillDismiss | (reason?: DialogDismissReason) => boolean | 即将关闭,通过回调的方式,提供开发者本次弹窗即将关闭的原因:
返回true,表示允许本次dismiss
返回false,表示拒绝本次dismiss |
diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets
index 5445a8161ce2d3ff8f56569191677570a3bd3fe2..58f188ffe0dab5edc47b5378b088e7006cd824f8 100644
--- a/entry/src/main/ets/entryability/EntryAbility.ets
+++ b/entry/src/main/ets/entryability/EntryAbility.ets
@@ -16,7 +16,7 @@ export default class EntryAbility extends UIAbility {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
- windowStage.loadContent('pages/Index', (err) => {
+ windowStage.loadContent('pages/DialogLevelTest', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
diff --git a/entry/src/main/ets/pages/CustomPopupTest.ets b/entry/src/main/ets/pages/CustomPopupTest.ets
index 4281a64894242d42ff28b2d2f732d94d3ce37eaa..113e6402d9d4d705d395ceb75055d314e21780c0 100644
--- a/entry/src/main/ets/pages/CustomPopupTest.ets
+++ b/entry/src/main/ets/pages/CustomPopupTest.ets
@@ -77,7 +77,7 @@ struct CustomPopupTest {
.id('cwq' + index)
.onClick(() => {
console.log('[DialogHub DEBUG] Click')
- DialogHub
+ this.popupDialog = DialogHub
.getPopup()
.setContent(wrapBuilder(multiTest))
.setAnimation({
@@ -96,8 +96,8 @@ struct CustomPopupTest {
dialogBehavior: { autoDismiss: true, passThroughGesture: false, isModal: true }
})
.setComponentTargetId("cwq" + index)
- .build()
- .show();
+ .build();
+ this.popupDialog.show();
})
}.width('100%').alignItems(index % 2 === 0 ? HorizontalAlign.Start : HorizontalAlign.End).padding(30)
@@ -121,6 +121,11 @@ struct CustomPopupTest {
url: 'pages/CustomPopupTest'
})
})
+
+ Button('close popup')
+ .onClick(() => {
+
+ })
}
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
diff --git a/entry/src/main/ets/pages/DialogLevelTest.ets b/entry/src/main/ets/pages/DialogLevelTest.ets
new file mode 100644
index 0000000000000000000000000000000000000000..e5aa20c94ba269786ced597d76ec819d464a5b0b
--- /dev/null
+++ b/entry/src/main/ets/pages/DialogLevelTest.ets
@@ -0,0 +1,183 @@
+import { DialogAction,
+ DialogConfig,
+ DialogHub,
+ DialogLifeCycle,
+ DialogStatus, InfCustomDialog, InfDialog, InfSheet } from '@hadss/dialoghub';
+import { DHubLogger } from '@hadss/dialoghub/src/main/ets/log/DHubLogger';
+import { CommonDialog } from '@hadss/dialoghub/src/main/ets/model/dialog/base/CommonDialog';
+
+class Dialog1Param {
+ close: () => void;
+ constructor(close: () => void) {
+ this.close = close;
+ }
+}
+
+@Builder
+function dialog1(param: Dialog1Param) {
+ Column() {
+ TextInput({ placeholder: '请输入' })
+
+ Text('打开二级弹窗')
+ .fontSize(24)
+ .fontColor(Color.Red)
+ .onClick(() => {
+ param.close();
+ })
+
+ }
+ .width('90%')
+ .height(200)
+}
+
+@Builder
+function dialog2() {
+ Column() {
+ Text('二级弹窗')
+ .fontSize(24)
+ .fontColor(Color.Blue)
+ }
+ .width('90%')
+ .height(150)
+}
+
+class MaskParam {
+ close: () => void = () => {};
+}
+
+@Builder
+function maskDialog(param: MaskParam) {
+ Column() {}
+ .width('100%')
+ .height('100%')
+ .backgroundColor(Color.Transparent)
+ .onClick(() => {
+ console.log('testTag: mask clicked');
+ param.close();
+ })
+}
+
+@Entry
+@Component
+struct DialogLevelTest {
+ @State message: string = 'Hello World';
+ maskDialog: InfCustomDialog | undefined = undefined;
+ dialogs: InfDialog[] = [];
+ dialog1: InfCustomDialog | undefined = undefined;
+ dialog2: InfCustomDialog | undefined = undefined;
+ toastDialog: InfCustomDialog | undefined = undefined;
+ popupDialog: InfCustomDialog | undefined = undefined;
+ sheetDialog: InfSheet | undefined = undefined;
+
+
+ initMaskDialog() {
+ this.maskDialog = DialogHub.getCustomDialog()
+ .setConfig({
+ dialogBehavior: {
+ isModal: true,
+ passThroughGesture: false,
+ autoDismiss: true
+ }
+ })
+ .setStyle({
+ maskBackgroundEffect: { radius: 40 },
+ backgroundColor: Color.Transparent
+ })
+ .setOperableContent(wrapBuilder(maskDialog), (dialogAction: DialogAction) => {
+ let maskParam = new MaskParam();
+ maskParam.close = () => {
+ if (this.dialogs.length >= 1) {
+ this.dialogs[this.dialogs.length - 1].dismiss();
+ }
+ }
+ return maskParam;
+ })
+ .build();
+ }
+
+ initDialog() {
+ DialogHub.init(this.getUIContext());
+ this.initMaskDialog();
+ let dialogConfig: DialogConfig = {
+ dialogBehavior: {
+ isModal: false,
+ passThroughGesture: false,
+ autoDismiss: false
+ }
+ };
+ let lifeCycle: DialogLifeCycle = {
+ onWillShow: () => {
+ // 显示第一个弹窗时,先弹出遮罩弹窗
+ if (this.dialogs.length == 0) {
+ this.maskDialog?.show();
+ }
+ return true;
+ },
+ onShow: () => {
+ setTimeout(() => {
+ let dialogs = DialogHub.getCurrentPageDialogsByStatus();
+ if (dialogs.length - 1 > this.dialogs.length) { // dialog.length - 1, 因为dialogs包含遮罩弹窗
+ // 显示二级弹窗时,关闭一级弹窗
+ if (this.dialogs.length > 0) {
+ this.dialogs[this.dialogs.length - 1].hide();
+ }
+ this.dialogs.push(dialogs[0]);
+ }
+ })
+ },
+ onDismiss: () => {
+ console.log('testTag: dialogs length when dialog before dismiss: ', this.dialogs.length);
+ this.dialogs.pop();
+ console.log('testTag: dialogs length when dialog dismiss: ', this.dialogs.length);
+ if (this.dialogs.length == 0) {
+ this.maskDialog?.dismiss();
+ } else {
+ this.dialogs[this.dialogs.length - 1].show();
+ }
+ console.log('testTag: dialog onDismiss called');
+ }
+ }
+ this.dialog1 = DialogHub.getCustomDialog()
+ .setConfig(dialogConfig)
+ .setStyle({
+ borderColor: Color.Black,
+ borderWidth: 2
+ })
+ .setLifeCycleListener(lifeCycle)
+ .setOperableContent(
+ wrapBuilder(dialog1), (dialogAction: DialogAction) => {
+ let param = new Dialog1Param(() => {
+ if (this.dialog2) {
+ this.dialog2.show();
+ }
+ })
+ return param;
+ }
+ ).build();
+ this.dialog2 = DialogHub.getCustomDialog().setContent(wrapBuilder(dialog2))
+ .setConfig(dialogConfig)
+ .setLifeCycleListener(lifeCycle)
+ .build();
+ }
+
+ aboutToAppear(): void {
+ DHubLogger.openLog("DEBUG");
+ this.initDialog();
+ }
+
+ build() {
+ Column({ space: 10 }) {
+ Button('打开一级弹窗')
+ .onClick(() => {
+ this.dialog1?.show();
+ })
+ .margin({
+ top: 20
+ })
+ }
+ // .justifyContent(FlexAlign.Center)
+ .height('100%')
+ .width('100%')
+ .id('sheet')
+ }
+}
\ No newline at end of file
diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json
index 0e124d15ce4153e8a29479cac6efd28e8704c3a0..482be410ffdaa6548aae4f9a73492bdf99a3a6be 100644
--- a/entry/src/main/resources/base/profile/main_pages.json
+++ b/entry/src/main/resources/base/profile/main_pages.json
@@ -9,6 +9,7 @@
"pages/CustomPopupTest",
"pages/APITestPage",
"pages/CustomTest",
- "pages/PerformanceTest"
+ "pages/PerformanceTest",
+ "pages/DialogLevelTest"
]
}
\ No newline at end of file
diff --git a/hadss_dialog/src/main/ets/common/been/DialogAction.ets b/hadss_dialog/src/main/ets/common/been/DialogAction.ets
index c8c137f34fd93dfc1ccd0274e4a2c00f2e230359..134ecd270a05c1b65673507682246bb8d703d597 100644
--- a/hadss_dialog/src/main/ets/common/been/DialogAction.ets
+++ b/hadss_dialog/src/main/ets/common/been/DialogAction.ets
@@ -16,4 +16,5 @@
export interface DialogAction {
show: () => void;
dismiss: () => void;
+ hide: () => void;
}
\ No newline at end of file
diff --git a/hadss_dialog/src/main/ets/model/DialogHub.ets b/hadss_dialog/src/main/ets/model/DialogHub.ets
index ea86b4d7ec125a6321e0a7a5384b4b1feb6bd897..f3531e4987ef1a75a7686e9e2375cc2ea2a9371b 100644
--- a/hadss_dialog/src/main/ets/model/DialogHub.ets
+++ b/hadss_dialog/src/main/ets/model/DialogHub.ets
@@ -289,6 +289,10 @@ export class DialogHub {
.getCurrentPageDialogs(undefined, type, modelName, DialogStatus.SHOW) ?? [];
}
+ static getCurrentPageDialogsByStatus(status?: DialogStatus) {
+ return AppLifeCycleHelper.getInstance(DialogHub.uiContext).getCurrentPageDialogs(undefined, undefined, undefined, status) ?? [];
+ }
+
static dispatchBackPressToDialog(): DialogBackPressResult {
let curentPageDialogs = AppLifeCycleHelper.getInstance(DialogHub.uiContext)
.getCurrentPageDialogs(undefined, undefined, undefined, DialogStatus.SHOW);
diff --git a/hadss_dialog/src/main/ets/model/dialog/base/CommonDialog.ets b/hadss_dialog/src/main/ets/model/dialog/base/CommonDialog.ets
index a928c3539cbc9140be481e6a552fd9c138c5ece4..02b473d1cd41cf4e1122302e1a0118917a426583 100644
--- a/hadss_dialog/src/main/ets/model/dialog/base/CommonDialog.ets
+++ b/hadss_dialog/src/main/ets/model/dialog/base/CommonDialog.ets
@@ -53,6 +53,9 @@ export class CommonDialog implements InfDialog {
},
dismiss: (): void => {
this.dismiss();
+ },
+ hide: (): void => {
+ this.hide();
}
}
@@ -159,8 +162,40 @@ export class CommonDialog implements InfDialog {
}
public hide(isInsideCall?: boolean) {
- this.close(true, isInsideCall);
- KeyboardAvoidHelper.getInstance().restore();
+ if (isInsideCall) {
+ this.isShown = false;
+ this.dialogStatus = DialogStatus.HIDE;
+ this.dialogExecutor?.hide();
+ return true;
+ } else if (!this.isShown) {
+ return true;
+ } else {
+ DHubLogger.debug(`DialogId:${this.dialogId},type:${DialogType[this.type]}, dialog about to hide`);
+ let singleShouldHide: boolean = (this.lifeCycleHelper as DialogLifeCycleHelper).dispatchWillHide();
+ let globalShouldHide: boolean = GlobalDialogLifeCycleHelper.getInstance().dispatchWillHide(this);
+ if (singleShouldHide && globalShouldHide) {
+ this.dialogStatus = DialogStatus.HIDE;
+ DHubLogger.debug(`DialogId:${this.dialogId},type:${DialogType[this.type]}, dialog Executor start hide`);
+
+ if (this.animatorHelper.isUseAnimation()) {
+ this.animatorHelper.close(() => {
+ this.isShown = false;
+ this.dialogExecutor?.hide();
+ });
+ } else {
+ this.isShown = false;
+ this.dialogExecutor?.hide();
+ }
+ KeyboardAvoidHelper.getInstance().restore();
+ setTimeout(() => {
+ (this.lifeCycleHelper as DialogLifeCycleHelper)?.dispatchHide();
+ GlobalDialogLifeCycleHelper.getInstance().dispatchHide(this);
+ DHubLogger.debug(`DialogId:${this.dialogId},type:${DialogType[this.type]}, dialog finish hide`);
+ });
+ return true;
+ }
+ }
+ return false;
}
public dismiss(dismissReason?: DialogDismissReason): boolean {
diff --git a/hadss_dialog/src/main/ets/model/dialog/base/CustomDialog.ets b/hadss_dialog/src/main/ets/model/dialog/base/CustomDialog.ets
index 7e10f583e43d75c074919e5fd3395fb419b07626..de5d6f9e1be07faafd496661af386e7f5d158a9b 100644
--- a/hadss_dialog/src/main/ets/model/dialog/base/CustomDialog.ets
+++ b/hadss_dialog/src/main/ets/model/dialog/base/CustomDialog.ets
@@ -184,10 +184,13 @@ export class CustomDialog extends CommonDialog implements InfCustomDialog {
return super.dismiss(dismissReason);
}
- public hide(isInsideCall?: boolean): void {
- (this.builderOptions as CustomOption).focusable = false;
- this.update(['focusable']);
- super.hide(isInsideCall);
+ public hide(isInsideCall?: boolean): boolean {
+ let res = super.hide(isInsideCall);
+ if (res) {
+ (this.builderOptions as CustomOption).focusable = false;
+ this.update(['focusable']);
+ }
+ return res;
}
public show(isInsideCall?: boolean | undefined): boolean {
diff --git a/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets b/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets
index fe89edd0abce6846cc11e8a44c99fa64adeaca8c..b7a69aae7dbe7290edf96a9c3d64e0f73a2dfb24 100644
--- a/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets
+++ b/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets
@@ -40,6 +40,7 @@ export class PopupDialog extends CustomDialog implements InfPopup {
}
private arrowOffsetXCache = 0
private arrowOffsetYCache = 0
+ private selfRectangle: componentUtils.ComponentInfo | undefined = undefined;
constructor(uiContext: UIContext, options: PopupOption, lifeCycle: DialogLifeCycle) {
super(uiContext, options, lifeCycle);
@@ -113,9 +114,9 @@ export class PopupDialog extends CustomDialog implements InfPopup {
this.updateDialogPosition();
}
- public hide(isInsideCall?: boolean | undefined): void {
+ public hide(isInsideCall?: boolean | undefined): boolean {
this.needWaitRouter = Boolean(isInsideCall); // need wait when router/navigation to old Page
- super.hide(isInsideCall)
+ return super.hide(isInsideCall)
}
public updateDialogPosition() {
@@ -126,7 +127,13 @@ export class PopupDialog extends CustomDialog implements InfPopup {
(this.builderOptions as PopupOption).targetCompRectangle = targetRectangle;
updateKeys.push('targetCompRectRectangle')
DHubLogger.debug(`PopupDialogId:${this.dialogId},type:${DialogType[this.type]}, Got targetRectangle ${JSON.stringify(targetRectangle)}}`);
- let selfRectangle = this.componentUtil.getRectangleById(this.builderOptions.dialogId);
+ if (!this.selfRectangle) {
+ this.selfRectangle = this.componentUtil.getRectangleById(this.builderOptions.dialogId);
+ if (this.selfRectangle.size.width == 0 && this.selfRectangle.size.height == 0) {
+ this.selfRectangle = undefined;
+ }
+ }
+ let selfRectangle = this.selfRectangle ?? this.componentUtil.getRectangleById(this.builderOptions.dialogId);
DHubLogger.debug(`PopupDialogId:${this.dialogId},type:${DialogType[this.type]}, Got selfRectangle ${JSON.stringify(selfRectangle)}}`);
this.dialogRectangle = selfRectangle;
diff --git a/hadss_dialog/src/main/ets/model/dialog/executor/BindSheetExecutor.ets b/hadss_dialog/src/main/ets/model/dialog/executor/BindSheetExecutor.ets
index 16bd212747199fb14fe282e62a3e4a8a68d9eb92..81ca8ae464d13fd2505679bf837a3c8bd15b880a 100644
--- a/hadss_dialog/src/main/ets/model/dialog/executor/BindSheetExecutor.ets
+++ b/hadss_dialog/src/main/ets/model/dialog/executor/BindSheetExecutor.ets
@@ -120,11 +120,12 @@ export class BindSheetExecutor extends DialogExecutor {
}
public hide() {
+ this.uiContext.closeBindSheet(this.contentNode);
}
public dismiss(): void {
this.uiContext.closeBindSheet(this.contentNode);
- this.init();
+ this.contentNode = undefined;
}
public resetIndex(): void {
diff --git a/hadss_dialog/src/main/ets/model/dialog/interface/InfDialog.ets b/hadss_dialog/src/main/ets/model/dialog/interface/InfDialog.ets
index b8ccb7454fa1ef8ce37d54b70e4ceacd155fdb32..3afe46dd6505a1b2f5d9cc724977476e3ab8631a 100644
--- a/hadss_dialog/src/main/ets/model/dialog/interface/InfDialog.ets
+++ b/hadss_dialog/src/main/ets/model/dialog/interface/InfDialog.ets
@@ -27,6 +27,8 @@ export interface InfDialog {
show(): boolean;
+ hide(): boolean;
+
dismiss(): boolean;
getStatus(): DialogStatus;
diff --git a/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycle.ets b/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycle.ets
index a3dd1273aa396c03c597436e8de20695f2642b16..a804e3cf0ed5351698ea0ada82c57d53c937b173 100644
--- a/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycle.ets
+++ b/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycle.ets
@@ -25,6 +25,16 @@ export interface DialogLifeCycle {
*/
onWillShow?: () => boolean;
+ /**
+ * Dialog hided
+ */
+ onHide?: () => void;
+
+ /**
+ * Dialog about to hide
+ */
+ onWillHide?: () => boolean;
+
/**
* Popup closed
*/
diff --git a/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycleHelper.ets b/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycleHelper.ets
index 75dea05d7d14c727897cfd48a2eb34065773b9e0..3ebb6f470f3d88002ea3f3cd48c9c158c5cc819e 100644
--- a/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycleHelper.ets
+++ b/hadss_dialog/src/main/ets/model/lifecycle/DialogLifeCycleHelper.ets
@@ -46,6 +46,31 @@ export class DialogLifeCycleHelper extends ListenerManager {
return willShow;
}
+ /**
+ * dispatch dialog hide life cycle
+ */
+ public dispatchHide(): void {
+ this.listeners.forEach((lifecycle) => {
+ lifecycle.onHide?.();
+ })
+ }
+
+ /**
+ * dispatch dialog willHide life cycle
+ * @returns the result of dialog hide
+ */
+ public dispatchWillHide(): boolean {
+ let hide = true;
+ for (let i = 0; i < this.listeners.length; i++) {
+ let lifecycle = this.listeners[i];
+ if (lifecycle.onWillHide && !lifecycle.onWillHide()) {
+ hide = false;
+ break;
+ }
+ }
+ return hide;
+ }
+
/**
* dispatch dialog dismiss life cycle.
*
@@ -89,6 +114,24 @@ export class SheetLifeCycleHelper extends ListenerManager {
return willShow;
}
+ public dispatchHide(): void {
+ this.listeners.forEach((lifecycle) => {
+ lifecycle.onHide?.();
+ })
+ }
+
+ public dispatchWillHide(): boolean {
+ let hide = true;
+ for (let i = 0; i < this.listeners.length; i++) {
+ let lifecycle = this.listeners[i];
+ if (lifecycle.onWillHide && !lifecycle.onWillHide()) {
+ hide = false;
+ break;
+ }
+ }
+ return hide;
+ }
+
public dispatchDismiss(): void {
this.listeners.forEach((lifecycle) => {
lifecycle.onDismiss?.();
diff --git a/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycle.ets b/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycle.ets
index cfe8ec17ae729b9000384b65fd3c04e0eb3aff4f..3c2916caf6d1865f6ba4d327a15f37d4e8d21c8b 100644
--- a/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycle.ets
+++ b/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycle.ets
@@ -28,6 +28,19 @@ export interface GlobalDialogLifeCycle {
*/
onWillShow?: (dialog: CommonDialog) => boolean;
+ /**
+ * lifecycle after the dialog hide
+ * @param dialog
+ */
+ onHide?: (dialog: CommonDialog) => void;
+
+ /**
+ * lifecycle before the dialog hide
+ * @param dialog
+ * @returns whether the dialog will hide
+ */
+ onWillHide?: (dialog: CommonDialog) => boolean;
+
/**
* close
*
diff --git a/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycleHelper.ets b/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycleHelper.ets
index 55915803b75cfbd1c08f152ab050b63f6e78c499..cf030cfecb1851088e96423da801670101a38ffc 100644
--- a/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycleHelper.ets
+++ b/hadss_dialog/src/main/ets/model/lifecycle/GlobalDialogLifeCycleHelper.ets
@@ -58,6 +58,31 @@ export class GlobalDialogLifeCycleHelper extends ListenerManager {
+ lifecycle.onHide?.(dialog);
+ });
+ }
+
+ /**
+ * dispatch dialog will hide life cycle
+ * @param dialog
+ * @returns whether the dialog will hide
+ */
+ public dispatchWillHide(dialog: CommonDialog): boolean {
+ let willHide: boolean = true;
+ this.listeners.forEach((lifecycle) => {
+ if (lifecycle.onWillHide && !lifecycle.onWillHide(dialog)) {
+ willHide = false;
+ }
+ });
+ return willHide;
+ }
+
/**
* dispatch dialog dismiss life cycle.
*