Skip to content

Commit 4b753b4

Browse files
committed
feat(ohos): forbidden close dialog when back press
1 parent f050c2c commit 4b753b4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

framework/ohos/src/main/cpp/impl/renderer/native/include/renderer/arkui/dialog_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DialogController {
4848
void SetGridColumnCount(int32_t gridCount);
4949
void EnableCustomStyle(bool enableCustomStyle);
5050
void EnableCustomAnimation(bool enableCustomAnimation);
51-
void RegisterOnWillDismiss(ArkUI_OnWillDismissEvent eventHandler);
51+
void RegisterOnWillDismiss(void (*callback)(ArkUI_DialogDismissEvent* event));
5252
void Show();
5353
void Close();
5454
void SetShowInPage(int32_t uniqueId);

framework/ohos/src/main/cpp/impl/renderer/native/src/arkui/dialog_controller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ void DialogController::Close(){
120120
MaybeThrow(NativeDialogApi::GetInstance()->close(dialogHandle));
121121
}
122122

123-
void DialogController::RegisterOnWillDismiss(ArkUI_OnWillDismissEvent eventHandler){
123+
void DialogController::RegisterOnWillDismiss(void (*callback)(ArkUI_DialogDismissEvent* event)){
124124
if(!dialogHandle)
125125
return;
126-
MaybeThrow(NativeDialogApi::GetInstance()->registerOnWillDismiss(dialogHandle,eventHandler));
126+
MaybeThrow(NativeDialogApi::GetInstance()->registerOnWillDismissWithUserData(dialogHandle, nullptr, callback));
127127
}
128128

129129
void DialogController::SetShowInPage(int32_t uniqueId) {

framework/ohos/src/main/cpp/impl/renderer/native/src/components/modal_view.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ inline namespace render {
3030
inline namespace native {
3131
const int DURATION = 200;
3232

33+
// 自定义Dialog关闭回调函数
34+
void OnHippyDialogDismiss(ArkUI_DialogDismissEvent* event) {
35+
if (!event) {
36+
return;
37+
}
38+
auto reason = OH_ArkUI_DialogDismissEvent_GetDismissReason(event);
39+
if (reason == DIALOG_DISMISS_BACK_PRESS || reason == DIALOG_DISMISS_SLIDE_DOWN) {
40+
OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(event, true);
41+
}
42+
}
43+
3344
ModalView::ModalView(std::shared_ptr<NativeRenderContext> &ctx) : BaseView(ctx) {
3445
}
3546

@@ -114,6 +125,7 @@ void ModalView::OpenDialog(int32_t parentNodeUniqueId) {
114125
dialog_->SetCornerRadius(0, 0, 0, 0);
115126
dialog_->SetModalMode(true);
116127
dialog_->SetContent(GetLocalRootArkUINode()->GetArkUINodeHandle());
128+
dialog_->RegisterOnWillDismiss(OnHippyDialogDismiss);
117129
if (is_show_in_page_ && parentNodeUniqueId > 0) {
118130
dialog_->SetShowInPage(parentNodeUniqueId);
119131
}

0 commit comments

Comments
 (0)