diff --git a/frameworks/core/components/dialog/dialog_properties.h b/frameworks/core/components/dialog/dialog_properties.h index 7f4e8bcb3c53af979beb510e097c6c001bebd675..6896e6d87747571bd7f94529cf1c58192fb31819 100644 --- a/frameworks/core/components/dialog/dialog_properties.h +++ b/frameworks/core/components/dialog/dialog_properties.h @@ -263,6 +263,7 @@ struct DialogProperties { std::function onDidDisappear; std::function onWillAppear; std::function onWillDisappear; + std::function onWillDismissCallByNDK; WordBreak wordBreak = WordBreak::BREAK_ALL; }; diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index ee9ec678ae2730b93ffbfbe7041bce0afb11b5c0..f60512bb1c8fd8a1df655eacc79f18730b7f00b2 100644 --- a/frameworks/core/components_ng/base/frame_node.h +++ b/frameworks/core/components_ng/base/frame_node.h @@ -942,6 +942,16 @@ public: return currentRect; } + void SetIsUseTransitionAnimator(bool isUseTransitionAnimator) + { + isUseTransitionAnimator_ = isUseTransitionAnimator; + } + + bool GetIsUseTransitionAnimator() + { + return isUseTransitionAnimator_; + } + // this method will check the cache state and return the cached revert matrix preferentially, // but the caller can pass in true to forcible refresh the cache Matrix4& GetOrRefreshRevertMatrixFromCache(bool forceRefresh = false); @@ -1187,6 +1197,8 @@ private: bool isLayoutNode_ = false; bool isCalculateInnerVisibleRectClip_ = false; + bool isUseTransitionAnimator_ = false; + RefPtr overlayNode_; std::unordered_map sceneRateMap_; diff --git a/frameworks/core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.cpp b/frameworks/core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.cpp index 4b7e13ed694f1ac33d706e41b9ad7773333f18d4..9630f42d2ee0e9b0fcf83aee14f9f9082b4ab2e7 100644 --- a/frameworks/core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.cpp @@ -168,6 +168,7 @@ void CustomDialogControllerModelNG::SetCloseDialogForNDK(FrameNode* dialogNode) CHECK_NULL_VOID(dialogNode); ContainerScope scope(Container::CurrentIdSafely()); auto container = Container::Current(); + dialogNode->SetIsUseTransitionAnimator(true); CHECK_NULL_VOID(container); auto pipelineContext = container->GetPipelineContext(); CHECK_NULL_VOID(pipelineContext); diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp index 88270ccb2ee09259dfdfa23de6de87f242ba5114..4ad608da0e40df29dc1e978c7e94cfdd3f68bf28 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp @@ -199,7 +199,9 @@ void DialogPattern::HandleClick(const GestureEvent& info) CHECK_NULL_VOID(pipeline); auto overlayManager = pipeline->GetOverlayManager(); CHECK_NULL_VOID(overlayManager); - if (this->ShouldDismiss()) { + if (this->CallDismissInNDK(static_cast(DialogDismissReason::DIALOG_TOUCH_OUTSIDE))) { + return; + } else if (this->ShouldDismiss()) { overlayManager->SetDismissDialogId(host->GetId()); this->CallOnWillDismiss(static_cast(DialogDismissReason::DIALOG_TOUCH_OUTSIDE)); TAG_LOGI(AceLogTag::ACE_DIALOG, "Dialog Should Dismiss"); diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h index 2e0740301ae0fb2cbfec13a0273a3396ac84146e..14b5ac8fbd483b735f35236befc22d7eef921b20 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h @@ -17,6 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DIALOG_DIALOG_PATTERN_H #include +#include #include "base/geometry/ng/offset_t.h" #include "base/geometry/ng/size_t.h" @@ -73,6 +74,19 @@ public: return false; } + void SetOnWillDismissByNDK(const std::function& onWillDismissByNDK) + { + onWillDismissByNDK_ = onWillDismissByNDK; + } + + bool CallDismissInNDK(int reason) + { + if (onWillDismissByNDK_ && onWillDismissByNDK_(reason)) { + return true; + } + return false; + } + void CallOnWillDismiss(const int32_t reason) { if (onWillDismiss_) { @@ -361,6 +375,7 @@ private: std::string title_; std::string subtitle_; std::function onWillDismiss_; + std::function onWillDismissByNDK_; DialogProperties dialogProperties_; WeakPtr menuNode_; diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp index c226e6e71acfcaece3a75af6f86e52a2235b5826..cad0792d51ca4c740cb6b197c246c38e8bf2556b 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp @@ -105,6 +105,7 @@ RefPtr DialogView::CreateDialogNode( pattern->BuildChild(param); pattern->SetOnWillDismiss(param.onWillDismiss); + pattern->SetOnWillDismissByNDK(param.onWillDismissCallByNDK); if (param.transitionEffect != nullptr) { dialogContext->UpdateChainedTransition(param.transitionEffect); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 8bd841b111b4f6d9b733bf5ad5e5cb35acc7fabf..729f7048bda34f15559a95f5384ccb3188e92cff 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -698,7 +698,7 @@ void OverlayManager::OnDialogCloseEvent(const RefPtr& node) node->OnAccessibilityEvent( AccessibilityEventType::CHANGE, WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_SUBTREE); DeleteDialogHotAreas(node); - root->RemoveChild(node); + root->RemoveChild(node, node->GetIsUseTransitionAnimator()); root->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); if (container->IsDialogContainer() || isShowInSubWindow) { @@ -2822,7 +2822,9 @@ int32_t OverlayManager::RemoveOverlayCommon(const RefPtr& rootNode, } auto dialogPattern = DynamicCast(pattern); CHECK_NULL_RETURN(dialogPattern, OVERLAY_EXISTS); - if (dialogPattern->ShouldDismiss()) { + if (dialogPattern->CallDismissInNDK(static_cast(DialogDismissReason::DIALOG_PRESS_BACK))) { + return OVERLAY_REMOVE; + } else if (dialogPattern->ShouldDismiss()) { SetDismissDialogId(overlay->GetId()); dialogPattern->CallOnWillDismiss(static_cast(DialogDismissReason::DIALOG_PRESS_BACK)); TAG_LOGI(AceLogTag::ACE_OVERLAY, "Dialog Should Dismiss"); diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index e4a2eadeb427cdf352b089e97902e694b589b9ed..faa72a0a1aa73a252125aafe57d634166d535dfd 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -1326,6 +1326,9 @@ struct ArkUIDragInteractionOptions { ArkUI_Bool defaultAnimationBeforeLifting; }; +struct ArkUI_DialogDismissEvent; +typedef ArkUI_DialogDismissEvent* ArkUIDialogDismissEvent; + struct ArkUICommonModifier { void (*setBackgroundColor)(ArkUINodeHandle node, ArkUI_Uint32 color); void (*resetBackgroundColor)(ArkUINodeHandle node); @@ -4712,6 +4715,8 @@ struct ArkUIDialogAPI { ArkUI_Int32 (*show)(ArkUIDialogHandle handle, ArkUI_Bool showInSubWindow); ArkUI_Int32 (*close)(ArkUIDialogHandle handle); ArkUI_Int32 (*registerOnWillDismiss)(ArkUIDialogHandle handle, bool (*eventHandler)(ArkUI_Int32)); + ArkUI_Int32 (*registerOnWillDismissWithUserData)( + ArkUIDialogHandle handler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); }; struct ArkUIBasicNodeAPI { diff --git a/frameworks/core/interfaces/native/node/custom_dialog_model.cpp b/frameworks/core/interfaces/native/node/custom_dialog_model.cpp index 9ae20cbf71b69df0973708bba5fbe8c97c139b91..f85215320c49f9dfb423835bc264d661a2f5080d 100644 --- a/frameworks/core/interfaces/native/node/custom_dialog_model.cpp +++ b/frameworks/core/interfaces/native/node/custom_dialog_model.cpp @@ -13,6 +13,9 @@ * limitations under the License. */ #include "core/interfaces/native/node/custom_dialog_model.h" + +#include "interfaces/native/node/dialog_model.h" + #include "base/error/error_code.h" #include "core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.h" @@ -30,16 +33,28 @@ namespace { constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_START_INDEX = 6; constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_INDEX = 7; constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_END_INDEX = 8; -} +} // namespace ArkUIDialogHandle CreateDialog() { - return new _ArkUIDialog({ .dialogHandle = nullptr, .contentHandle = nullptr, - .alignment = DEFAULT_DIALOG_ALIGNMENT, .offsetX = 0.0f, - .offsetY = 0.0f, .isModal = true, .autoCancel = true, .maskColor = DEFAULT_MASK_COLOR, .maskRect = nullptr, - .backgroundColor = DEFAULT_DIALOG_BACKGROUND_COLOR, .cornerRadiusRect = nullptr, - .gridCount = -1, .enableCustomStyle = false, - .showInSubWindow = false, .enableCustomAnimation = false, .onWillDismissCall = nullptr }); + return new _ArkUIDialog({ .dialogHandle = nullptr, + .contentHandle = nullptr, + .alignment = DEFAULT_DIALOG_ALIGNMENT, + .offsetX = 0.0f, + .offsetY = 0.0f, + .isModal = true, + .autoCancel = true, + .maskColor = DEFAULT_MASK_COLOR, + .maskRect = nullptr, + .backgroundColor = DEFAULT_DIALOG_BACKGROUND_COLOR, + .cornerRadiusRect = nullptr, + .gridCount = -1, + .enableCustomStyle = false, + .showInSubWindow = false, + .enableCustomAnimation = false, + .onWillDismissCall = nullptr, + .onWillDismissCallByNDK = nullptr, + .userData = nullptr }); } void DisposeDialog(ArkUIDialogHandle controllerHandler) @@ -64,6 +79,8 @@ void DisposeDialog(ArkUIDialogHandle controllerHandler) delete cornerRadiusRect; } controllerHandler->onWillDismissCall = nullptr; + controllerHandler->onWillDismissCallByNDK = nullptr; + controllerHandler->userData = nullptr; delete controllerHandler; } @@ -94,6 +111,36 @@ DialogAlignment GetDialogAlignment(int32_t alignment) return DialogAlignment::DEFAULT; } +void ParseDialogMask(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler) +{ + CHECK_NULL_VOID(controllerHandler); + dialogProperties.maskColor = Color(controllerHandler->maskColor); + if (!controllerHandler->maskRect) { + return; + } + DimensionRect maskRect; + maskRect.SetOffset(DimensionOffset(Dimension(controllerHandler->maskRect->x, DimensionUnit::VP), + Dimension(controllerHandler->maskRect->y, DimensionUnit::VP))); + maskRect.SetSize(DimensionSize(Dimension(controllerHandler->maskRect->width, DimensionUnit::VP), + Dimension(controllerHandler->maskRect->height, DimensionUnit::VP))); + dialogProperties.maskRect = maskRect; +} + +void ParseDialogCornerRadiusRect(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler) +{ + CHECK_NULL_VOID(controllerHandler); + if (!controllerHandler->cornerRadiusRect) { + return; + } + NG::BorderRadiusProperty radius; + radius.radiusTopLeft = Dimension(controllerHandler->cornerRadiusRect->topLeft, DimensionUnit::VP); + radius.radiusTopRight = Dimension(controllerHandler->cornerRadiusRect->topRight, DimensionUnit::VP); + radius.radiusBottomLeft = Dimension(controllerHandler->cornerRadiusRect->bottomLeft, DimensionUnit::VP); + radius.radiusBottomRight = Dimension(controllerHandler->cornerRadiusRect->bottomRight, DimensionUnit::VP); + radius.multiValued = true; + dialogProperties.borderRadius = radius; +} + void ParseDialogProperties(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler) { CHECK_NULL_VOID(controllerHandler); @@ -101,39 +148,29 @@ void ParseDialogProperties(DialogProperties& dialogProperties, ArkUIDialogHandle dialogProperties.alignment = GetDialogAlignment(controllerHandler->alignment); dialogProperties.offset = DimensionOffset(Dimension(controllerHandler->offsetX, DimensionUnit::VP), Dimension(controllerHandler->offsetY, DimensionUnit::VP)); - dialogProperties.maskColor = Color(controllerHandler->maskColor); - if (controllerHandler->maskRect) { - DimensionRect maskRect; - maskRect.SetOffset(DimensionOffset(Dimension(controllerHandler->maskRect->x, DimensionUnit::VP), - Dimension(controllerHandler->maskRect->y, DimensionUnit::VP))); - maskRect.SetSize(DimensionSize(Dimension(controllerHandler->maskRect->width, DimensionUnit::VP), - Dimension(controllerHandler->maskRect->height, DimensionUnit::VP))); - dialogProperties.maskRect = maskRect; - } dialogProperties.isShowInSubWindow = controllerHandler->showInSubWindow; dialogProperties.isModal = controllerHandler->isModal; dialogProperties.backgroundColor = Color(controllerHandler->backgroundColor); dialogProperties.customStyle = controllerHandler->enableCustomStyle; dialogProperties.gridCount = controllerHandler->gridCount; - if (controllerHandler->cornerRadiusRect) { - NG::BorderRadiusProperty radius; - radius.radiusTopLeft = Dimension(controllerHandler->cornerRadiusRect->topLeft, DimensionUnit::VP); - radius.radiusTopRight = Dimension(controllerHandler->cornerRadiusRect->topRight, DimensionUnit::VP); - radius.radiusBottomLeft = Dimension(controllerHandler->cornerRadiusRect->bottomLeft, DimensionUnit::VP); - radius.radiusBottomRight = Dimension(controllerHandler->cornerRadiusRect->bottomRight, DimensionUnit::VP); - radius.multiValued = true; - dialogProperties.borderRadius = radius; - } + ParseDialogMask(dialogProperties, controllerHandler); + ParseDialogCornerRadiusRect(dialogProperties, controllerHandler); if (controllerHandler->onWillDismissCall) { - dialogProperties.onWillDismiss = [controllerHandler](int32_t reason) { - CHECK_NULL_VOID(controllerHandler); - CHECK_NULL_VOID(controllerHandler->onWillDismissCall); - auto executeClose = (*(controllerHandler->onWillDismissCall))(reason); - if (!executeClose) { - // todo - } - }; + dialogProperties.onWillDismissCallByNDK = [controllerHandler](int32_t reason) { + return controllerHandler->onWillDismissCall(reason); + }; } + + if (controllerHandler->onWillDismissCallByNDK) { + dialogProperties.onWillDismissCallByNDK = [controllerHandler](int32_t reason) { + ArkUI_DialogDismissEvent event = { controllerHandler->userData, reason, false }; + controllerHandler->onWillDismissCallByNDK(&event); + return event.BlockDismiss; + }; + } else { + dialogProperties.onWillDismissCallByNDK = nullptr; + } + if (controllerHandler->enableCustomAnimation && !dialogProperties.openAnimation.has_value()) { AnimationOption animation; dialogProperties.openAnimation = animation; @@ -287,4 +324,14 @@ ArkUI_Int32 RegisterOnWillDialogDismiss(ArkUIDialogHandle controllerHandler, boo controllerHandler->onWillDismissCall = eventHandler; return ERROR_CODE_NO_ERROR; } + +ArkUI_Int32 RegisterOnWillDialogDismissWithUserData( + ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)) +{ + CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID); + controllerHandler->onWillDismissCallByNDK = callback; + controllerHandler->userData = userData; + return ERROR_CODE_NO_ERROR; +} + } // namespace OHOS::Ace::NG::ViewModel \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/custom_dialog_model.h b/frameworks/core/interfaces/native/node/custom_dialog_model.h index 5f1a5b34f206f3c9254fb555631e78abb2aa2fda..45ef197a6b082e93d3acb4f8c3d3dde47bdfeab8 100644 --- a/frameworks/core/interfaces/native/node/custom_dialog_model.h +++ b/frameworks/core/interfaces/native/node/custom_dialog_model.h @@ -35,6 +35,8 @@ struct _ArkUIDialog { ArkUI_Int32 showInSubWindow; ArkUI_Bool enableCustomAnimation; bool (*onWillDismissCall)(ArkUI_Int32); + void (*onWillDismissCallByNDK)(ArkUI_DialogDismissEvent*); + void* userData; }; namespace OHOS::Ace::NG::CustomDialog { @@ -57,6 +59,8 @@ ArkUI_Int32 EnableDialogCustomAnimation(ArkUIDialogHandle handle, bool enableCus ArkUI_Int32 ShowDialog(ArkUIDialogHandle handle, bool showInSubWindow); ArkUI_Int32 CloseDialog(ArkUIDialogHandle handle); ArkUI_Int32 RegisterOnWillDialogDismiss(ArkUIDialogHandle handler, bool (*eventHandler)(ArkUI_Int32)); +ArkUI_Int32 RegisterOnWillDialogDismissWithUserData( + ArkUIDialogHandle handler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); } // namespace OHOS::Ace::NG::CustomDialog #endif \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/node_api.cpp b/frameworks/core/interfaces/native/node/node_api.cpp index 0ecd103b483124cfbb715345e5a6d2c571a8265e..d97e2db94954fc4e068714c9ff62a2ac59875a66 100644 --- a/frameworks/core/interfaces/native/node/node_api.cpp +++ b/frameworks/core/interfaces/native/node/node_api.cpp @@ -1718,6 +1718,13 @@ ArkUI_Int32 RegisterOnWillDialogDismiss(ArkUIDialogHandle handle, bool (*eventHa return CustomDialog::RegisterOnWillDialogDismiss(handle, eventHandler); } +// Register closing event +ArkUI_Int32 RegisterOnWillDismissWithUserData( + ArkUIDialogHandle handler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)) +{ + return CustomDialog::RegisterOnWillDialogDismissWithUserData(handler, userData, callback); +} + const ArkUIDialogAPI* GetDialogAPI() { static const ArkUIDialogAPI dialogImpl = { @@ -1738,6 +1745,7 @@ const ArkUIDialogAPI* GetDialogAPI() ShowDialog, CloseDialog, RegisterOnWillDialogDismiss, + RegisterOnWillDismissWithUserData }; return &dialogImpl; } diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index a68078269341a707b5d7e718fb2ca2de1a8a326e..a8bc0a8421df067d6718ddad536a3add1f66dc89 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -1970,5 +1970,17 @@ { "first_introduced": "12", "name": "OH_ArkUI_StartDrag" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_DialogDismissEvent_GetUserData" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_DialogDismissEvent_GetDismissReason" } ] diff --git a/interfaces/native/native_dialog.h b/interfaces/native/native_dialog.h index 73e35a6b2e9aae403790a976761567299495fd71..5190f40fdb212b8193a69ab64880542d64233f78 100644 --- a/interfaces/native/native_dialog.h +++ b/interfaces/native/native_dialog.h @@ -23,24 +23,35 @@ extern "C" { #endif /** -* @brief Enumerates the actions for triggering closure of the dialog box. -* -* @since 12 -*/ + * @brief Enumerates the actions for triggering closure of the dialog box. + * + * @since 12 + */ typedef enum { /** Touching the system-defined Back button or pressing the Esc key. */ DIALOG_DISMISS_BACK_PRESS = 0, /** Touching the mask. */ DIALOG_DISMISS_TOUCH_OUTSIDE, + /** 点击关闭按钮。*/ + DIALOG_DISMISS_CLOSE_BUTTON, + /** 下拉关闭。*/ + DIALOG_DISMISS_SLIDE_DOWN, } ArkUI_DismissReason; /** -* @brief Invoked when the dialog box is closed. -* -* @since 12 -*/ + * @brief Invoked when the dialog box is closed. + * + * @since 12 + */ typedef bool (*ArkUI_OnWillDismissEvent)(int32_t reason); +/** + * @brief Defines a struct for a dialog box dismiss event. + * + * @since 12 + */ +typedef struct ArkUI_DialogDismissEvent ArkUI_DialogDismissEvent; + /** * @brief Provides the custom dialog box APIs for the native side. * @@ -208,8 +219,56 @@ typedef struct { * @return Returns 0 if the operation is successful; returns 401 if a parameter error occurs. */ int32_t (*close)(ArkUI_NativeDialogHandle handle); + + /** + * @brief Registers a listener for the dismiss event of the custom dialog box. + * + * @param handle Indicates the pointer to the custom dialog box controller. + * @param userData Indicates the pointer to the custom data. + * @param callback Indicates the callback for the dismiss event of the custom dialog box. + * @return Returns the result code. + * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + */ + int32_t (*registerOnWillDismissWithUserData)( + ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); } ArkUI_NativeDialogAPI_1; +/** + * @brief Sets whether to block the system behavior of dismissing a dialog box. + * + * @param event Indicates the pointer to a dialog box dismiss event object. + * @param shouldBlockDismiss Indicates whether to block the system behavior of dismissing the dialog box. The value + * true means to block the system behavior, and false means the opposite. + * @since 12 + */ +void ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss); + +/** + * @brief Obtains the pointer to user data in a dialog box dismiss event object. + * + * @param event Indicates the pointer to a dialog box dismiss event object. + * + * @return Returns the pointer to user data. + * @since 12 + */ +void* ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event); + +/** + * @brief Obtains the c from a dialog box dismiss event object. + * + * @param event Indicates the pointer to a dialog box dismiss event object. + * + * @return Returns the dismissal reason. Returns -1 if an exception occurs. + * {@link DIALOG_DISMISS_BACK_PRESS}: touching the Back button, swiping left or right on the screen, or + * pressing the Esc key. + * {@link DIALOG_DISMISS_TOUCH_OUTSIDE}: touching the mask. + * {@link DIALOG_DISMISS_CLOSE_BUTTON}: touching the Close button. + * {@link DIALOG_DISMISS_SLIDE_DOWN}: sliding down. + * @since 12 + */ +int32_t ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event); + #ifdef __cplusplus }; #endif diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index 026c9ddb40aa23a9cd49e002c19fa4f635808fb3..7b1495fd38e789f6a6d2f0ae2b32efca593b7b01 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -7303,18 +7303,18 @@ int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle nod int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset); /** -* @brief The event called when the sliding operation offset changes. -* -* @param node Indicates the target node. -* @param userData Indicates the custom data to be saved. -* @param onFinish Callback Events. -* offset Slide offset. -* @return Error code. -* {@link ARKUI_ERROR_CODE_NO_ERROR} Success. -* {@link ARKUI_ERROR_CODE_PARAM_INVALID} Function parameter exception. -* {@link ARKUI_ERROR_CODE_ATTRIBUTE_OR_EVENT_NOT_SUPPORTED} The component does not support this event. -* @since 12 -*/ + * @brief The event called when the sliding operation offset changes. + * + * @param node Indicates the target node. + * @param userData Indicates the custom data to be saved. + * @param onFinish Callback Events. + * offset Slide offset. + * @return Error code. + * {@link ARKUI_ERROR_CODE_NO_ERROR} Success. + * {@link ARKUI_ERROR_CODE_PARAM_INVALID} Function parameter exception. + * {@link ARKUI_ERROR_CODE_ATTRIBUTE_OR_EVENT_NOT_SUPPORTED} The component does not support this event. + * @since 12 + */ int32_t OH_ArkUI_List_CloseAllSwipeActions(ArkUI_NodeHandle node, void* userData, void (*onFinish)(void* userData)); /** diff --git a/interfaces/native/node/dialog_model.cpp b/interfaces/native/node/dialog_model.cpp index 7dc7030787244a2fa65d1c4008ee8b71ec54df74..63ad4448a70e32944d1874083729ef7d50e10ba3 100644 --- a/interfaces/native/node/dialog_model.cpp +++ b/interfaces/native/node/dialog_model.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ #include "dialog_model.h" + +#include "native_dialog.h" #include "native_type.h" #include "node_model.h" @@ -183,4 +185,39 @@ int32_t RegisterOnWillDismiss(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismi return impl->getDialogAPI()->registerOnWillDismiss(handle->controller, eventHandler); } -} // namespace OHOS::Ace::NG::DialogModel \ No newline at end of file +int32_t RegisterOnWillDismissWithUserData( + ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!impl || !handle || !callback) { + return ERROR_CODE_PARAM_INVALID; + } + int result = impl->getDialogAPI()->registerOnWillDismissWithUserData(handle->controller, userData, callback); + return result; +} + +} // namespace OHOS::Ace::NG::DialogModel + +void OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss) +{ + if (!event) { + return; + } + event->BlockDismiss = shouldBlockDismiss; +} + +void* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event) +{ + if (!event) { + return nullptr; + } + return event->userData; +} + +int32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event) +{ + if (!event) { + return -1; + } + return event->reason; +} \ No newline at end of file diff --git a/interfaces/native/node/dialog_model.h b/interfaces/native/node/dialog_model.h index 594b9ef98070303388e1e5d1ab6b93593cfb232a..f1801fcccf81bb1aa22bee2ee95a6e84100d4b19 100644 --- a/interfaces/native/node/dialog_model.h +++ b/interfaces/native/node/dialog_model.h @@ -28,6 +28,12 @@ struct ArkUI_NativeDialog { ArkUIDialogHandle controller = nullptr; }; +struct ArkUI_DialogDismissEvent { + void* userData; + int32_t reason = -1; + bool BlockDismiss = false; +}; + #ifdef __cplusplus }; #endif @@ -51,6 +57,8 @@ int32_t EnableCustomAnimation(ArkUI_NativeDialogHandle handle, bool enableCustom int32_t RegisterOnWillDismiss(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler); int32_t Show(ArkUI_NativeDialogHandle handle, bool showInSubWindow); int32_t Close(ArkUI_NativeDialogHandle handle); +int32_t RegisterOnWillDismissWithUserData( + ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); } // namespace OHOS::Ace::NG::DialogModel #endif // ARKUI_NATIVE_NODE_DIALOG_MODEL_H \ No newline at end of file diff --git a/interfaces/native/node/native_impl.cpp b/interfaces/native/node/native_impl.cpp index 6ce92042084920c10536199e191f15cd29d783be..d2471e0462cc9e16255faa5585a3d2f7cb2bea48 100644 --- a/interfaces/native/node/native_impl.cpp +++ b/interfaces/native/node/native_impl.cpp @@ -110,6 +110,7 @@ ArkUI_NativeDialogAPI_1 dialogImpl_1 = { OHOS::Ace::DialogModel::RegisterOnWillDismiss, OHOS::Ace::DialogModel::Show, OHOS::Ace::DialogModel::Close, + OHOS::Ace::DialogModel::RegisterOnWillDismissWithUserData, }; constexpr int32_t CURRENT_NATIVE_GESTURE_API_VERSION = 1;