From 8b97aa78065a30a7ebc20490b4aaa36148c51d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E4=BC=AF=E8=A8=80?= Date: Mon, 16 Dec 2024 11:51:12 +0800 Subject: [PATCH] =?UTF-8?q?setComponentTargetId=E6=8A=A5=E9=94=99=E4=B8=8B?= =?UTF-8?q?=E6=B2=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/adapter/proxy/base/PopupProxy.ets | 4 +--- .../model/adapter/proxy/base/SheetProxy.ets | 4 +--- .../ets/model/dialog/base/PopupDialog.ets | 20 +++++++++++++++---- .../ets/model/dialog/base/SheetDialog.ets | 11 ++++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/hadss_dialog/src/main/ets/model/adapter/proxy/base/PopupProxy.ets b/hadss_dialog/src/main/ets/model/adapter/proxy/base/PopupProxy.ets index ba325ed..cb452a2 100644 --- a/hadss_dialog/src/main/ets/model/adapter/proxy/base/PopupProxy.ets +++ b/hadss_dialog/src/main/ets/model/adapter/proxy/base/PopupProxy.ets @@ -70,9 +70,7 @@ export class PopupProxy extends CustomProxy { } setComponentTargetId(targetCompId: string) { - if (CompUtils.JudgeID(this.uiContext, targetCompId)) { - this.builderOptions.targetCompId = targetCompId - } + this.builderOptions.targetCompId = targetCompId return this } } diff --git a/hadss_dialog/src/main/ets/model/adapter/proxy/base/SheetProxy.ets b/hadss_dialog/src/main/ets/model/adapter/proxy/base/SheetProxy.ets index 6aa5633..0baf323 100644 --- a/hadss_dialog/src/main/ets/model/adapter/proxy/base/SheetProxy.ets +++ b/hadss_dialog/src/main/ets/model/adapter/proxy/base/SheetProxy.ets @@ -49,9 +49,7 @@ export class SheetProxy extends DialogAdaptorProxy { } setComponentTargetId(targetCompId: string) { - if (CompUtils.JudgeID(this.uiContext, targetCompId)) { - this.builderOptions.targetCompId = targetCompId - } + this.builderOptions.targetCompId = targetCompId return this } 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 1999f65..a1290c7 100644 --- a/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets +++ b/hadss_dialog/src/main/ets/model/dialog/base/PopupDialog.ets @@ -17,8 +17,8 @@ import { InfPopup } from '../interface/InfPopup'; import { CustomDialog } from './CustomDialog'; import { DimensionUtils } from '../../../common/util/DimensionUtils'; import { DialogLifeCycle } from '../../lifecycle/DialogLifeCycle'; -import { ObjectUtils } from '../../../common/util/ObjectUtils'; import { display, inspector } from '@kit.ArkUI'; +import { CompUtils } from '../../../common/util/CompUtils'; /** * 基于系统CommonDialog封装对外提供的customDialog,支持更新自定义内容 @@ -44,11 +44,23 @@ export class PopupDialog extends CustomDialog implements InfPopup { this.updateDialogPosition(); } + public show(isInsideCall?: boolean | undefined): boolean { + let compId = (this.builderOptions as PopupOption).targetCompId; + if (compId) { + CompUtils.JudgeID(this.uiContext, compId) + } + return super.show(isInsideCall) + } + private observeDialogComponent() { - this.targetCompListener = inspector.createComponentObserver((this.builderOptions as PopupOption).targetCompId); - this.targetCompListener?.on('layout', this.onTargetCompLayoutComplete); this.dialogCompListener = inspector.createComponentObserver(this.dialogId); this.dialogCompListener?.on('layout', this.onDialogCompLayoutComplete); + + let compId = (this.builderOptions as PopupOption).targetCompId; + if (compId) { + this.targetCompListener = inspector.createComponentObserver(compId); + this.targetCompListener?.on('layout', this.onTargetCompLayoutComplete); + } } public updateDialogPosition() { @@ -201,7 +213,7 @@ export class PopupDialog extends CustomDialog implements InfPopup { let defaultOffset = DimensionUtils.length2px((this.builderOptions as PopupOption).arrowOffset, maxValue); let arrowWidth = DimensionUtils.length2px((this.builderOptions as PopupOption).arrowWidth, display.getDefaultDisplaySync().width); - let afterOffset = (maxValue- arrowWidth) / 2 + defaultOffset; // 默认居中,在居中上偏移,如不默认居中,不需要此行代码 + let afterOffset = (maxValue - arrowWidth) / 2 + defaultOffset; // 默认居中,在居中上偏移,如不默认居中,不需要此行代码 let maxOffset = maxValue - arrowWidth - vp2px(5); let validOffset = px2vp(Math.max(Math.min(maxOffset, afterOffset), vp2px(5))); return validOffset; diff --git a/hadss_dialog/src/main/ets/model/dialog/base/SheetDialog.ets b/hadss_dialog/src/main/ets/model/dialog/base/SheetDialog.ets index 1697e93..602300d 100644 --- a/hadss_dialog/src/main/ets/model/dialog/base/SheetDialog.ets +++ b/hadss_dialog/src/main/ets/model/dialog/base/SheetDialog.ets @@ -15,6 +15,7 @@ import { SheetOption } from '../../../common/been/option/base/SheetOption'; import { SheetStyle } from '../../../common/been/style/SheetStyle'; import { DialogStatus } from '../../../common/constant/DialogStatus'; +import { CompUtils } from '../../../common/util/CompUtils'; import { DialogLifeCycle } from '../../lifecycle/DialogLifeCycle'; import { SheetLifeCycleHelper } from '../../lifecycle/DialogLifeCycleHelper'; import { GlobalDialogLifeCycleHelper } from '../../lifecycle/GlobalDialogLifeCycleHelper'; @@ -27,10 +28,12 @@ import { CommonDialog } from './CommonDialog'; * 基于系统BindSheet封装的弹窗实例 * */ export class SheetDialog extends CommonDialog implements InfSheet { + private uiContext: UIContext; protected lifeCycleHelper: SheetLifeCycleHelper = new SheetLifeCycleHelper(); constructor(uiContext: UIContext, options: SheetOption, lifeCycle: SheetLifeCycle) { super(uiContext, options, lifeCycle); + this.uiContext = uiContext; //sheet内置方法关闭时同步弹窗状态 this.dialogExecutor = new BindSheetExecutor(uiContext, options as SheetOption, () => { this.isShown = false; @@ -66,4 +69,12 @@ export class SheetDialog extends CommonDialog implements InfSheet { public updateStyle(style: SheetStyle): void { super.updateStyle(style) } + + public show(isInsideCall?: boolean | undefined): boolean { + let compId = (this.builderOptions as SheetOption).targetCompId; + if (compId) { + CompUtils.JudgeID(this.uiContext, compId) + } + return super.show(isInsideCall) + } } \ No newline at end of file -- Gitee