HarmonyOS鸿蒙Next中CustomDialogController如何禁用侧滑动屏幕边缘消失功能?
HarmonyOS鸿蒙Next中CustomDialogController如何禁用侧滑动屏幕边缘消失功能?
问题描述
我在应用中使用了一个自定义的对话框控制器来展示用户协议与隐私政策。具体实现如下:
private agreementDialogController: CustomDialogController = new CustomDialogController({
builder: AgreementPolicyDialog({
customAgreement: this.AgreementPolicyContent,
onConfirm: this.onConfirm.bind(this),
onCancel: this.onCancel.bind(this),
title: "用户协议与隐私政策",
dialogHeight: 380
}),
alignment: DialogAlignment.Center,
customStyle: true,
autoCancel: false
});
问题
在弹出的隐私政策框中,用户必须同意才能进入应用。然而,我发现侧滑边缘可以让弹窗消失,这与预期的行为不符。
期望行为
希望用户在弹出隐私政策框时,无法通过侧滑或其他方式关闭对话框,必须进行确认或取消操作。
更多关于HarmonyOS鸿蒙Next中CustomDialogController如何禁用侧滑动屏幕边缘消失功能?的实战教程也可以访问 https://www.itying.com/category-93-b0.html
可参考api12新增的接口onWillDismiss,https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-methods-custom-dialog-box.md#customdialogcontrolleroptions%E5%AF%B9%E8%B1%A1%E8%AF%B4%E6%98%8E
更多关于HarmonyOS鸿蒙Next中CustomDialogController如何禁用侧滑动屏幕边缘消失功能?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,CustomDialogController默认支持通过侧滑动屏幕边缘来关闭对话框。要禁用此功能,可以通过设置CustomDialogController的touchOutside属性为false来实现。具体代码如下:
let controller = CustomDialogController({
builder: YourCustomDialogComponent(),
alignment: DialogAlignment.Default,
customStyle: false,
touchOutside: false // 禁用侧滑动屏幕边缘消失功能
});
通过将touchOutside设置为false,用户将无法通过侧滑动屏幕边缘来关闭对话框。
在HarmonyOS鸿蒙Next中,CustomDialogController默认支持通过侧滑屏幕边缘来关闭对话框。要禁用这一功能,可以在创建CustomDialog时,通过设置setCanceledOnTouchOutside(false)来阻止点击外部区域关闭对话框,同时通过重写onKeyDown方法拦截返回键操作,防止通过返回键关闭对话框。此外,确保在CustomDialogController的布局中未启用任何滑动关闭逻辑,从而彻底禁用侧滑消失功能。

