diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index c9ef25c1a6700970c1e0b13357f0a468c3b44934..59a0b25777385b318c6edd903e4dfac69c70f222 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -6134,9 +6134,11 @@ void JSViewAbstract::JsBindContentCover(const JSCallbackInfo& info) modalStyle.modalTransition = NG::ModalTransition::DEFAULT; std::function onShowCallback; std::function onDismissCallback; + std::function onWillShowCallback; + std::function onWillDismissCallback; if (info.Length() == 3) { if (info[2]->IsObject()) { - ParseOverlayCallback(info[2], onShowCallback, onDismissCallback); + ParseOverlayCallback(info[2], onShowCallback, onDismissCallback, onWillShowCallback, onWillDismissCallback); ParseModalStyle(info[2], modalStyle); } else if (info[2]->IsNumber()) { auto transitionNumber = info[2]->ToNumber(); @@ -6146,7 +6148,8 @@ void JSViewAbstract::JsBindContentCover(const JSCallbackInfo& info) } } ViewAbstractModel::GetInstance()->BindContentCover(isShow, std::move(callback), std::move(buildFunc), modalStyle, - std::move(onShowCallback), std::move(onDismissCallback)); + std::move(onShowCallback), std::move(onDismissCallback), std::move(onWillShowCallback), + std::move(onWillDismissCallback)); } void JSViewAbstract::ParseModalStyle(const JSRef& paramObj, NG::ModalStyle& modalStyle) @@ -6205,18 +6208,21 @@ void JSViewAbstract::JsBindSheet(const JSCallbackInfo& info) sheetStyle.showCloseIcon = true; std::function onShowCallback; std::function onDismissCallback; + std::function onWillShowCallback; + std::function onWillDismissCallback; std::function shouldDismissFunc; std::function titleBuilderFunction; if (info.Length() == 3) { if (info[2]->IsObject()) { - ParseSheetCallback(info[2], onShowCallback, onDismissCallback, shouldDismissFunc); + ParseSheetCallback(info[2], onShowCallback, onDismissCallback, shouldDismissFunc, onWillShowCallback, + onWillDismissCallback); ParseSheetStyle(info[2], sheetStyle); ParseSheetTitle(info[2], sheetStyle, titleBuilderFunction); } } ViewAbstractModel::GetInstance()->BindSheet(isShow, std::move(callback), std::move(buildFunc), std::move(titleBuilderFunction), sheetStyle, std::move(onShowCallback), std::move(onDismissCallback), - std::move(shouldDismissFunc)); + std::move(shouldDismissFunc), std::move(onWillShowCallback), std::move(onWillDismissCallback)); } void JSViewAbstract::ParseSheetStyle(const JSRef& paramObj, NG::SheetStyle& sheetStyle) @@ -6398,11 +6404,14 @@ bool JSViewAbstract::ParseSheetBackgroundBlurStyle(const JSRef& args, Blu } void JSViewAbstract::ParseSheetCallback(const JSRef& paramObj, std::function& onAppear, - std::function& onDisappear, std::function& shouldDismiss) + std::function& onDisappear, std::function& shouldDismiss, std::function& onWillAppear, + std::function& onWillDisappear) { auto showCallback = paramObj->GetProperty("onAppear"); auto dismissCallback = paramObj->GetProperty("onDisappear"); auto shouldDismissFunc = paramObj->GetProperty("shouldDismiss"); + auto willShowCallback = paramObj->GetProperty("onWillAppear"); + auto willDismissCallback = paramObj->GetProperty("onWillDisappear"); if (showCallback->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(showCallback)); @@ -6426,6 +6435,16 @@ void JSViewAbstract::ParseSheetCallback(const JSRef& paramObj, std::fu func->ExecuteJS(1, &newJSVal); }; } + if (willShowCallback->IsFunction()) { + RefPtr jsFunc = + AceType::MakeRefPtr(JSRef(), JSRef::Cast(willShowCallback)); + onWillAppear = [func = std::move(jsFunc)]() { func->Execute(); }; + } + if (willDismissCallback->IsFunction()) { + RefPtr jsFunc = + AceType::MakeRefPtr(JSRef(), JSRef::Cast(willDismissCallback)); + onWillDisappear = [func = std::move(jsFunc)]() { func->Execute(); }; + } } void JSViewAbstract::ParseSheetTitle( @@ -6463,10 +6482,13 @@ panda::Local JSViewAbstract::JsDismissSheet(panda::JsiRuntime } void JSViewAbstract::ParseOverlayCallback( - const JSRef& paramObj, std::function& onAppear, std::function& onDisappear) + const JSRef& paramObj, std::function& onAppear, std::function& onDisappear, + std::function& onWillAppear, std::function& onWillDisappear) { auto showCallback = paramObj->GetProperty("onAppear"); auto dismissCallback = paramObj->GetProperty("onDisappear"); + auto willShowCallback = paramObj->GetProperty("onWillAppear"); + auto willDismissCallback = paramObj->GetProperty("onWillDisappear"); WeakPtr frameNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); if (showCallback->IsFunction()) { RefPtr jsFunc = @@ -6484,6 +6506,16 @@ void JSViewAbstract::ParseOverlayCallback( func->Execute(); }; } + if (willShowCallback->IsFunction()) { + RefPtr jsFunc = + AceType::MakeRefPtr(JSRef(), JSRef::Cast(willShowCallback)); + onWillAppear = [func = std::move(jsFunc)]() { func->Execute(); }; + } + if (willDismissCallback->IsFunction()) { + RefPtr jsFunc = + AceType::MakeRefPtr(JSRef(), JSRef::Cast(willDismissCallback)); + onWillDisappear = [func = std::move(jsFunc)]() { func->Execute(); }; + } } void JSViewAbstract::JSCreateAnimatableProperty(const JSCallbackInfo& info) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index 7de29f99cd8df2a7b0a5048ae75a4966e53c582a..78d3a3f6a8766524e81c611d6776a3d3ad12c420 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -125,12 +125,14 @@ public: static void ParseSheetDetentHeight(const JSRef& args, NG::SheetHeight& detent); static bool ParseSheetBackgroundBlurStyle(const JSRef& args, BlurStyleOption& blurStyleOptions); static void ParseSheetCallback(const JSRef& paramObj, std::function& onAppear, - std::function& onDisappear, std::function& shouldDismiss); + std::function& onDisappear, std::function& onWillAppear, std::function& onWillDisappear, + std::function& shouldDismiss); static void ParseSheetTitle(const JSRef& paramObj, NG::SheetStyle& sheetStyle, std::function& titleBuilderFunction); static panda::Local JsDismissSheet(panda::JsiRuntimeCallInfo* runtimeCallInfo); - static void ParseOverlayCallback( - const JSRef& paramObj, std::function& onAppear, std::function& onDisappear); + static void ParseOverlayCallback(const JSRef& paramObj, std::function& onAppear, + std::function& onDisappear, std::function& onWillAppear, + std::function& onWillDisappear); static void JsBorderColor(const JSCallbackInfo& info); static void ParseBorderColor(const JSRef& args); static void JsPadding(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h index ec3d8e3d8281eb8590ed24b5db2e10a5d6413f66..f28c3f8bb9e5060e829674cab09871321137ca24 100755 --- a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h @@ -228,11 +228,13 @@ public: std::function& previewBuildFunc) override; void BindContentCover(bool isShow, std::function&& callback, std::function&& buildFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear) override {} + std::function&& onDisappear, std::function&& onWillAppear, + std::function&& onWillDisappear) override {} void BindSheet(bool isShow, std::function&& callback, std::function&& buildFunc, std::function&& titleBuildFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss) override {} + std::function&& shouldDismiss, std::function&& onWillAppear, + std::function&& onWillDisappear) override {} void DismissSheet() override {} void SetAccessibilityGroup(bool accessible) override; diff --git a/frameworks/core/components_ng/base/view_abstract_model.h b/frameworks/core/components_ng/base/view_abstract_model.h index f69d817f9827cb1e82308c4f16cd88c8cfc446b6..7f28fdfcef519b37293720514dd78e362afebe26 100755 --- a/frameworks/core/components_ng/base/view_abstract_model.h +++ b/frameworks/core/components_ng/base/view_abstract_model.h @@ -290,11 +290,12 @@ public: std::function& previewBuildFunc) = 0; virtual void BindContentCover(bool isShow, std::function&& callback, std::function&& buildFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear) = 0; + std::function&& onDisappear, std::function&& onWillAppear, + std::function&& onWillDisappear) = 0; virtual void BindSheet(bool isShow, std::function&& callback, std::function&& buildFunc, std::function&& titleBuildFunc, NG::SheetStyle& sheetStyle, - std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss) = 0; + std::function&& onAppear, std::function&& onDisappear, std::function&& shouldDismiss, + std::function&& onWillAppear, std::function&& onWillDisappear) = 0; virtual void DismissSheet() = 0; virtual void DismissDialog() {}; diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp index 270b13e771ec8d65ea8826ba9b7d471316ad42b4..39948c30df061ec12c1414fc4198411ec31520d1 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp @@ -322,7 +322,7 @@ void ViewAbstractModelNG::SetScale(float x, float y, float z) void ViewAbstractModelNG::BindContentCover(bool isShow, std::function&& callback, std::function&& buildFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear) + std::function&& onDisappear, std::function&& onWillAppear, std::function&& onWillDisappear) { auto targetNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); CHECK_NULL_VOID(targetNode); @@ -348,7 +348,8 @@ void ViewAbstractModelNG::BindContentCover(bool isShow, std::functionPushDestroyCallback(destructor); overlayManager->BindContentCover(isShow, std::move(callback), std::move(buildNodeFunc), modalStyle, - std::move(onAppear), std::move(onDisappear), targetNode); + std::move(onAppear), std::move(onDisappear), + std::move(onWillAppear), std::move(onWillDisappear), targetNode); } void ViewAbstractModelNG::RegisterContextMenuKeyEvent( @@ -378,7 +379,8 @@ void ViewAbstractModelNG::RegisterContextMenuKeyEvent( void ViewAbstractModelNG::BindSheet(bool isShow, std::function&& callback, std::function&& buildFunc, std::function&& titleBuildFunc, NG::SheetStyle& sheetStyle, - std::function&& onAppear, std::function&& onDisappear, std::function&& shouldDismiss) + std::function&& onAppear, std::function&& onDisappear, std::function&& shouldDismiss, + std::function&& onWillAppear, std::function&& onWillDisappear) { auto targetNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); CHECK_NULL_VOID(targetNode); @@ -411,7 +413,8 @@ void ViewAbstractModelNG::BindSheet(bool isShow, std::functionPushDestroyCallback(destructor); overlayManager->BindSheet(isShow, std::move(callback), std::move(buildNodeFunc), std::move(buildTitleNodeFunc), - sheetStyle, std::move(onAppear), std::move(onDisappear), std::move(shouldDismiss), targetNode); + sheetStyle, std::move(onAppear), std::move(onDisappear), std::move(shouldDismiss), std::move(onWillAppear), + std::move(onWillDisappear), targetNode); } void ViewAbstractModelNG::DismissSheet() diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.h b/frameworks/core/components_ng/base/view_abstract_model_ng.h index a47a0c0430fb58ef415976c50a0c932c96ab7926..efc812839e77b7fe3e9e37be51fe1a8ef48473d8 100755 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -1010,11 +1010,13 @@ public: void BindContentCover(bool isShow, std::function&& callback, std::function&& buildFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear) override; + std::function&& onDisappear, std::function&& onWillAppear, + std::function&& onWillDisappear) override; void BindSheet(bool isShow, std::function&& callback, std::function&& buildFunc, std::function&& titleBuildFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, - std::function&& onDisappear, std::function&& shouldDismiss) override; + std::function&& onDisappear, std::function&& shouldDismiss, + std::function&& onWillAppear, std::function&& onWillDisappear) override; void DismissSheet() override; void SetAccessibilityGroup(bool accessible) override; diff --git a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp index a05e9bef131b34916a61c887362b2818da0d18c4..67fae83d99ef3a321e8528b7c15a8e819408e97c 100644 --- a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp +++ b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp @@ -287,11 +287,13 @@ void AppBarView::BindContentCover(const RefPtr& targetNode) modalStyle.modalTransition = NG::ModalTransition::NONE; auto buildNodeFunc = [targetNode, overlayManager, &modalStyle, &stageAbilityName]() -> RefPtr { auto onRelease = [overlayManager, &modalStyle, targetNode](int32_t releaseCode) { - overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + false, nullptr, nullptr, modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); }; auto onError = [overlayManager, &modalStyle, targetNode]( int32_t code, const std::string& name, const std::string& message) { - overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + false, nullptr, nullptr, modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); }; // Create parameters of UIExtension. @@ -323,7 +325,8 @@ void AppBarView::BindContentCover(const RefPtr& targetNode) uiExtNode->MarkModifyDone(); return uiExtNode; }; - overlayManager->BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); } void AppBarView::SetVisible(bool visible) diff --git a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h index 6b5474832d1ba7dcca747d6ef0d99e52c6f37dff..edd2ade34398df876272a0a416187ba9d2a4588b 100644 --- a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h @@ -75,6 +75,30 @@ public: } } + void UpdateOnWillDisappear(std::function&& onWillDisappear) + { + onWillDisappear_ = std::move(onWillDisappear); + } + + void OnWillDisappear() + { + if (onWillDisappear_) { + onWillDisappear_(); + } + } + + void UpdateOnAppear(std::function&& onAppear) + { + onAppear_ = std::move(onAppear); + } + + void OnAppear() + { + if (onAppear_) { + onAppear_(); + } + } + FocusPattern GetFocusPattern() const override { return { FocusType::SCOPE, true }; @@ -109,6 +133,8 @@ private: ModalTransition type_ = ModalTransition::DEFAULT; std::function callback_; std::function onDisappear_; + std::function onWillDisappear_; + std::function onAppear_; bool isExecuteOnDisappear_ = false; ACE_DISALLOW_COPY_AND_MOVE(ModalPresentationPattern); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 7b75408df1adf72c76c9cf464bb222ab9e28cb95..0063ec7e44183f7c10d2d355ac653ed920cbd182 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -1913,6 +1913,7 @@ bool OverlayManager::ModalPageExitProcess(const RefPtr& topModalNode) CHECK_NULL_RETURN(rootNode, true); auto builder = AceType::DynamicCast(topModalNode->GetFirstChild()); CHECK_NULL_RETURN(builder, false); + topModalNode->GetPattern()->OnWillDisappear(); auto modalTransition = topModalNode->GetPattern()->GetType(); if (builder->GetRenderContext()->HasDisappearTransition()) { if (!topModalNode->GetPattern()->IsExecuteOnDisappear()) { @@ -1942,6 +1943,7 @@ bool OverlayManager::SheetPageExitProcess(const RefPtr& topModalNode) { auto builder = AceType::DynamicCast(topModalNode->GetLastChild()); CHECK_NULL_RETURN(builder, false); + topModalNode->GetPattern()->OnWillDisappear(); if (builder->GetRenderContext()->HasDisappearTransition()) { if (!topModalNode->GetPattern()->IsExecuteOnDisappear()) { topModalNode->GetPattern()->OnDisappear(); @@ -2196,7 +2198,8 @@ RefPtr OverlayManager::GetModalNodeInStack(std::stack&& callback, std::function()>&& buildNodeFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear, const RefPtr& targetNode, int32_t sessionId) + std::function&& onDisappear, std::function&& onWillAppear, std::function&& onWillDisappear, + const RefPtr& targetNode, int32_t sessionId) { int32_t targetId = targetNode ? targetNode->GetId() : sessionId; auto rootNode = FindWindowScene(targetNode); @@ -2215,11 +2218,17 @@ void OverlayManager::BindContentCover(bool isShow, std::functionGetRenderContext()->UpdateBackgroundColor(modalStyle.backgroundColor.value()); } topModalNode->GetPattern()->UpdateOnDisappear(std::move(onDisappear)); + topModalNode->GetPattern()->UpdateOnWillDisappear( + std::move(onWillDisappear)); + topModalNode->GetPattern()->UpdateOnAppear(std::move(onAppear)); topModalNode->GetPattern()->SetType(modalTransition.value()); return; } } } + if (onWillAppear) { + onWillAppear(); + } // builder content auto builder = AceType::DynamicCast(buildNodeFunc()); CHECK_NULL_VOID(builder); @@ -2235,6 +2244,8 @@ void OverlayManager::BindContentCover(bool isShow, std::functionGetPattern(); CHECK_NULL_VOID(modalPagePattern); modalPagePattern->UpdateOnDisappear(std::move(onDisappear)); + modalPagePattern->UpdateOnWillDisappear(std::move(onWillDisappear)); + modalPagePattern->UpdateOnAppear(std::move(onAppear)); modalPagePattern->UpdateUIExtensionMode(modalStyle.isUIExtension); modalStack_.push(WeakClaim(RawPtr(modalNode))); modalList_.emplace_back(WeakClaim(RawPtr(modalNode))); @@ -2243,7 +2254,8 @@ void OverlayManager::BindContentCover(bool isShow, std::functionAddChild(builder); FireModalPageShow(); rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - if (onAppear != nullptr) { + if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE) && + onAppear) { onAppear(); } // Fire hidden event of navdestination under the appeared modal @@ -2263,6 +2275,9 @@ void OverlayManager::BindContentCover(bool isShow, std::functionGetTag() != V2::SHEET_PAGE_TAG && topModalNode->GetTag() != V2::MODAL_PAGE_TAG) { return; } + if (onWillDisappear) { + onWillDisappear(); + } if (topModalNode->GetTag() == V2::SHEET_PAGE_TAG || topModalNode->GetPattern()->GetTargetId() != targetId) { DeleteModal(targetId); @@ -2373,11 +2388,19 @@ void OverlayManager::PlayDefaultModalTransition(const RefPtr& modalNo if (isTransitionIn) { context->OnTransformTranslateUpdate({ 0.0f, showHeight, 0.0f }); + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + option.SetOnFinishEvent( + [modalWK = WeakClaim(RawPtr(modalNode))] { + auto modal = modalWK.Upgrade(); + CHECK_NULL_VOID(modal); + modal->GetPattern()->OnAppear(); + }); + } AnimationUtils::Animate(option, [context]() { if (context) { context->OnTransformTranslateUpdate({ 0.0f, 0.0f, 0.0f }); } - }); + }, option.GetOnFinishEvent()); } else { auto lastModalNode = lastModalNode_.Upgrade(); CHECK_NULL_VOID(lastModalNode); @@ -2429,7 +2452,14 @@ void OverlayManager::PlayAlphaModalTransition(const RefPtr& modalNode // last page animation lastModalContext->OpacityAnimation(option, 1, 0); lastModalContext->UpdateOpacity(0); - + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + option.SetOnFinishEvent( + [modalWK = WeakClaim(RawPtr(modalNode))] { + auto modal = modalWK.Upgrade(); + CHECK_NULL_VOID(modal); + modal->GetPattern()->OnAppear(); + }); + } // current modal page animation context->OpacityAnimation(option, 0, 1); } else { @@ -2461,7 +2491,8 @@ void OverlayManager::PlayAlphaModalTransition(const RefPtr& modalNode void OverlayManager::BindSheet(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, std::function()>&& buildtitleNodeFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss, const RefPtr& targetNode) + std::function&& shouldDismiss, std::function&& onWillAppear, + std::function&& onWillDisappear, const RefPtr& targetNode) { auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); @@ -2469,11 +2500,13 @@ void OverlayManager::BindSheet(bool isShow, std::functionOnBindSheet(isShow, std::move(callback), std::move(buildNodeFunc), std::move(buildtitleNodeFunc), - sheetStyle, std::move(onAppear), std::move(onDisappear), std::move(shouldDismiss), targetNode); + sheetStyle, std::move(onAppear), std::move(onDisappear), std::move(shouldDismiss), std::move(onWillAppear), + std::move(onWillDisappear), targetNode); auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); pipeline->FlushUITasks(); @@ -2484,7 +2517,8 @@ void OverlayManager::BindSheet(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, std::function()>&& buildtitleNodeFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss, const RefPtr& targetNode) + std::function&& shouldDismiss, std::function&& onWillAppear, + std::function&& onWillDisappear, const RefPtr& targetNode) { int32_t targetId = targetNode->GetId(); auto rootNode = FindWindowScene(targetNode); @@ -2516,6 +2550,8 @@ void OverlayManager::OnBindSheet(bool isShow, std::functionGetPattern()->UpdateOnDisappear(std::move(onDisappear)); topModalNode->GetPattern()->UpdateShouldDismiss(std::move(shouldDismiss)); + topModalNode->GetPattern()->UpdateOnWillDisappear(std::move(onWillDisappear)); + topModalNode->GetPattern()->UpdateOnAppear(std::move(onAppear)); auto layoutProperty = topModalNode->GetLayoutProperty(); layoutProperty->UpdateSheetStyle(sheetStyle); topModalNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); @@ -2549,6 +2585,8 @@ void OverlayManager::OnBindSheet(bool isShow, std::functionGetPattern()->UpdateOnDisappear(std::move(onDisappear)); sheetNode->GetPattern()->UpdateShouldDismiss(std::move(shouldDismiss)); + sheetNode->GetPattern()->UpdateOnWillDisappear(std::move(onWillDisappear)); + sheetNode->GetPattern()->UpdateOnAppear(std::move(onAppear)); sheetMap_[targetId] = WeakClaim(RawPtr(sheetNode)); modalStack_.push(WeakClaim(RawPtr(sheetNode))); SaveLastModalNode(); @@ -2584,8 +2622,8 @@ void OverlayManager::OnBindSheet(bool isShow, std::functionMountToParent(rootNode); PlaySheetMaskTransition(maskNode, true, static_cast(callback)); - auto columnNode = FrameNode::CreateFrameNode(V2::SHEET_WRAPPER_TAG, - ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(true)); + auto columnNode = FrameNode::CreateFrameNode(V2::SHEET_WRAPPER_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr(true)); CHECK_NULL_VOID(columnNode); auto columnLayoutProps = columnNode->GetLayoutProperty(); CHECK_NULL_VOID(columnLayoutProps); @@ -2598,7 +2636,10 @@ void OverlayManager::OnBindSheet(bool isShow, std::functionMarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); pipeline->FlushUITasks(); ComputeSheetOffset(sheetStyle, sheetNode); - if (onAppear != nullptr) { + if (onWillAppear) { + onWillAppear(); + } + if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE) && onAppear) { onAppear(); } @@ -2626,6 +2667,7 @@ void OverlayManager::CloseSheet(int32_t targetId) CHECK_NULL_VOID(scrollNode); auto builder = AceType::DynamicCast(scrollNode->GetChildAtIndex(0)); CHECK_NULL_VOID(builder); + sheetNode->GetPattern()->OnWillDisappear(); if (builder->GetRenderContext()->HasDisappearTransition()) { if (!sheetNode->GetPattern()->IsExecuteOnDisappear()) { sheetNode->GetPattern()->OnDisappear(); @@ -2728,6 +2770,9 @@ void OverlayManager::PlaySheetTransition( auto context = sheetNode->GetRenderContext(); CHECK_NULL_VOID(context); context->UpdateRenderGroup(false, true, true); + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + sheetNode->GetPattern()->OnAppear(); + } }); sheetParent->GetEventHub()->GetOrCreateGestureEventHub()->SetHitTestMode(HitTestMode::HTMDEFAULT); AnimationUtils::Animate( @@ -2736,11 +2781,11 @@ void OverlayManager::PlaySheetTransition( if (context) { context->OnTransformTranslateUpdate({ 0.0f, offset, 0.0f }); } - }); + }, + option.GetOnFinishEvent()); } else { option.SetOnFinishEvent( - [rootWeak = rootNodeWeak_, sheetWK = WeakClaim(RawPtr(sheetNode)), - weakOverlayManager = WeakClaim(this)] { + [rootWeak = rootNodeWeak_, sheetWK = WeakClaim(RawPtr(sheetNode)), weakOverlayManager = WeakClaim(this)] { auto sheet = sheetWK.Upgrade(); auto overlayManager = weakOverlayManager.Upgrade(); CHECK_NULL_VOID(sheet && overlayManager); @@ -2783,6 +2828,9 @@ void OverlayManager::PlayBubbleStyleSheetTransition(RefPtr sheetNode, auto sheetPattern = sheet->GetPattern(); CHECK_NULL_VOID(sheetPattern); sheetPattern->ProcessColumnRect(); + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + sheetPattern->OnAppear(); + } }); } else { sheetPattern->StartOffsetExitingAnimation(); @@ -3493,7 +3541,8 @@ int32_t OverlayManager::CreateModalUIExtension( modalStyle.modalTransition = NG::ModalTransition::NONE; modalStyle.isUIExtension = true; // Convert the sessionId into a negative number to distinguish it from the targetId of other modal pages - BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr, -(sessionId)); + BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, + nullptr, -(sessionId)); } else { auto bindModalCallback = [weak = WeakClaim(this), buildNodeFunc, sessionId, id = Container::CurrentId()]() { ContainerScope scope(id); @@ -3502,8 +3551,8 @@ int32_t OverlayManager::CreateModalUIExtension( ModalStyle modalStyle; modalStyle.modalTransition = NG::ModalTransition::NONE; modalStyle.isUIExtension = true; - overlayManager->BindContentCover( - true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr, -(sessionId)); + overlayManager->BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, + nullptr, nullptr, nullptr, -(sessionId)); }; ModalUIExtension::SetBindModalCallback(uiExtNode, std::move(bindModalCallback)); uiExtNodes_[sessionId] = WeakClaim(RawPtr(uiExtNode)); @@ -3522,7 +3571,7 @@ void OverlayManager::CloseModalUIExtension(int32_t sessionId) } ModalStyle modalStyle; modalStyle.modalTransition = NG::ModalTransition::NONE; - BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, nullptr, -(sessionId)); + BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, nullptr, nullptr, nullptr, -(sessionId)); } RefPtr OverlayManager::BindUIExtensionToMenu(const RefPtr& uiExtNode, diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h index 04d6e61c0919bcd5bb94d2a540bdf88b08475cbe..208ad7e8e29a9c892b99af7ad737c95ddba3936a 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h @@ -334,16 +334,18 @@ public: void BindContentCover(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear, const RefPtr& targetNode, int32_t sessionId = 0); - + std::function&& onDisappear, std::function&& onWillAppear, + std::function&& onWillDisappear, const RefPtr& targetNode, int32_t sessionId = 0); void BindSheet(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, std::function()>&& buildTitleNodeFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss, const RefPtr& targetNode); + std::function&& shouldDismiss, std::function&& onWillAppear, + std::function&& onWillDisappear, const RefPtr& targetNode); void OnBindSheet(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, std::function()>&& buildtitleNodeFunc, NG::SheetStyle& sheetStyle, std::function&& onAppear, std::function&& onDisappear, - std::function&& shouldDismiss, const RefPtr& targetNode); + std::function&& shouldDismiss, std::function&& onWillAppear, + std::function&& onWillDisappear, const RefPtr& targetNode); void CloseSheet(int32_t targetId); void DismissSheet(); diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp index 4b92617a97b0c146576a28ab895541f39233620a..4a60b0085741aa5bcbe8157f835bc47d3920dbbe 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp @@ -585,6 +585,7 @@ void SheetPresentationPattern::DismissTransition(bool isTransitionIn, float drag if (sheetType == SheetType::SHEET_POPUP) { BubbleStyleSheetTransition(isTransitionIn); } else { + OnWillDisappear(); SheetTransition(isTransitionIn, dragVelocity); } } diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h index 4cfdb8b46a4eca5353d961377f5aeb78735665c3..a82ced20aee376b053459bb5d77b0a86756ce679 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h @@ -111,6 +111,31 @@ public: } } + void UpdateOnWillDisappear(std::function&& onWillDisappear) + { + onWillDisappear_ = std::move(onWillDisappear); + } + + void OnWillDisappear() + { + if (onWillDisappear_) { + onWillDisappear_(); + } + } + + void UpdateOnAppear(std::function&& onAppear) + { + onAppear_ = std::move(onAppear); + } + + void OnAppear() + { + if (onAppear_) { + onAppear_(); + } + } + + void CallShouldDismiss() { if (shouldDismiss_) { @@ -339,7 +364,9 @@ private: std::string targetTag_; std::function callback_; std::function onDisappear_; + std::function onWillDisappear_; std::function shouldDismiss_; + std::function onAppear_; RefPtr panEvent_; float currentOffset_ = 0.0f; diff --git a/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp b/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp index b45f5f42aea8da4bcd3e795bc05be5b38c24333d..b58d4afb0618a437e9c0f66ce261e3cb222645a5 100644 --- a/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp @@ -265,7 +265,8 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover001, TestSize.Level1) modalStyle.modalTransition = ModalTransition::NONE; bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); overlayManager->PlayDefaultModalTransition(rootNode, false); auto topModalNode = overlayManager->modalStack_.top().Upgrade(); @@ -320,10 +321,11 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) */ ModalStyle modalStyle; bool isShow = true; + auto onWillAppear = []() {}; auto onAppear = []() {}; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->BindContentCover( - isShow, nullptr, std::move(builderFunc), modalStyle, onAppear, nullptr, targetNode); + isShow, nullptr, std::move(builderFunc), modalStyle, onAppear, nullptr, onWillAppear, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topModalNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_NE(topModalNode, nullptr); @@ -337,7 +339,8 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) * @tc.expected: the ModalTransition is updated successfully */ modalStyle.modalTransition = ModalTransition::NONE; - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); topModalNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_NE(topModalNode, nullptr); topModalPattern = topModalNode->GetPattern(); @@ -350,11 +353,13 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) * @tc.expected: the backgroundColor is updated successfully */ modalStyle.backgroundColor = Color::GREEN; - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); topModalNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_NE(topModalNode, nullptr); EXPECT_EQ(topModalNode->GetRenderContext()->GetBackgroundColorValue(), Color::GREEN); - overlayManager->BindContentCover(!isShow, nullptr, nullptr, modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + !isShow, nullptr, nullptr, modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); } /** @@ -395,15 +400,18 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover003, TestSize.Level1) modalStyle.modalTransition = ModalTransition::NONE; bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); /** * @tc.steps: step4. destroy modal page. * @tc.expected: destroy successfully */ + auto onWillDisappear = []() {}; auto onDisappear = []() {}; - overlayManager->BindContentCover(!isShow, nullptr, nullptr, modalStyle, nullptr, onDisappear, targetNode); + overlayManager->BindContentCover( + !isShow, nullptr, nullptr, modalStyle, nullptr, onDisappear, nullptr, onWillDisappear, targetNode); EXPECT_TRUE(overlayManager->modalStack_.empty()); } @@ -458,7 +466,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet001, TestSize.Level1) bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); @@ -576,7 +584,7 @@ HWTEST_F(OverlayManagerTestNg, RemoveAllModalInOverlay001, TestSize.Level1) bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_EQ(sheetNode->GetTag(), V2::SHEET_PAGE_TAG); @@ -588,11 +596,11 @@ HWTEST_F(OverlayManagerTestNg, RemoveAllModalInOverlay001, TestSize.Level1) overlayManager->modalList_.pop_back(); EXPECT_TRUE(overlayManager->RemoveAllModalInOverlay()); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_TRUE(overlayManager->RemoveAllModalInOverlay()); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); sheetNode->tag_ = V2::ROOT_ETS_TAG; EXPECT_TRUE(overlayManager->RemoveAllModalInOverlay()); @@ -646,10 +654,11 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) SheetStyle sheetStyle; CreateSheetStyle(sheetStyle); bool isShow = true; + auto onWillAppear = []() {}; auto onAppear = []() {}; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - onAppear, nullptr, nullptr, targetNode); + onAppear, nullptr, nullptr, onWillAppear, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); @@ -665,14 +674,14 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) sheetStyle.sheetMode = SheetMode::AUTO; sheetStyle.showDragBar = false; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); auto sheetPattern = sheetNode->GetPattern(); sheetPattern->InitialLayoutProps(); sheetStyle.sheetMode = SheetMode::MEDIUM; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); sheetPattern = sheetNode->GetPattern(); sheetPattern->InitialLayoutProps(); @@ -688,11 +697,12 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) */ sheetStyle.backgroundColor = Color::GREEN; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); EXPECT_EQ(sheetNode->GetRenderContext()->GetBackgroundColorValue(), Color::GREEN); - overlayManager->OnBindSheet(!isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, targetNode); + overlayManager->OnBindSheet( + !isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); } /** @@ -746,7 +756,7 @@ HWTEST_F(OverlayManagerTestNg, DestroySheet003, TestSize.Level1) bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_EQ(sheetNode->GetTag(), V2::SHEET_PAGE_TAG); @@ -773,10 +783,10 @@ HWTEST_F(OverlayManagerTestNg, DestroySheet003, TestSize.Level1) auto targetNodeSecond = CreateTargetNode(); targetNodeSecond->MountToParent(stageNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNodeSecond); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNodeSecond); EXPECT_FALSE(overlayManager->modalStack_.empty()); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); overlayManager->DestroySheet(sheetNode, targetId); EXPECT_FALSE(overlayManager->modalStack_.empty()); @@ -833,7 +843,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet003, TestSize.Level1) bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_EQ(sheetNode->GetTag(), V2::SHEET_PAGE_TAG); @@ -842,9 +852,10 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet003, TestSize.Level1) * @tc.steps: step4. destroy modal page. * @tc.expected: destroy modal successfully. */ + auto onWillDisappear = []() {}; auto onDisappear = []() {}; - overlayManager->OnBindSheet( - !isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, targetNode); + overlayManager->OnBindSheet(!isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, nullptr, + onWillDisappear, targetNode); overlayManager->modalList_.emplace_back(AceType::WeakClaim(AceType::RawPtr(stageNode))); overlayManager->DestroySheet(sheetNode, targetId); overlayManager->FindWindowScene(targetNode); @@ -903,7 +914,7 @@ HWTEST_F(OverlayManagerTestNg, GetSheetMask001, TestSize.Level1) bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_EQ(sheetNode->GetTag(), V2::SHEET_PAGE_TAG); @@ -913,12 +924,13 @@ HWTEST_F(OverlayManagerTestNg, GetSheetMask001, TestSize.Level1) * @tc.expected: if the color is set, Make sure the maskNode is exist and it's color is right. */ auto maskNode = overlayManager->GetSheetMask(sheetNode); + auto onWillDisappear = []() {}; auto onDisappear = []() {}; - overlayManager->OnBindSheet( - !isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, targetNode); + overlayManager->OnBindSheet(!isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, nullptr, + onWillDisappear, targetNode); sheetStyle.maskColor = Color::BLUE; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(sheetNode == nullptr); EXPECT_EQ(sheetNode->GetTag(), V2::SHEET_PAGE_TAG); @@ -931,8 +943,8 @@ HWTEST_F(OverlayManagerTestNg, GetSheetMask001, TestSize.Level1) * @tc.steps: step5. destroy sheetNode. * @tc.expected: Make sure the maskNode is destroyed. */ - overlayManager->OnBindSheet( - !isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, targetNode); + overlayManager->OnBindSheet(!isShow, nullptr, nullptr, nullptr, sheetStyle, nullptr, onDisappear, nullptr, nullptr, + onWillDisappear, targetNode); overlayManager->modalList_.emplace_back(AceType::WeakClaim(AceType::RawPtr(stageNode))); overlayManager->DestroySheet(sheetNode, targetId); overlayManager->FindWindowScene(targetNode); @@ -1378,14 +1390,14 @@ HWTEST_F(OverlayManagerTestNg, DeleteModal001, TestSize.Level1) CreateSheetStyle(sheetStyle); bool isShow = true; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); overlayManager->modalList_.emplace_back(nullptr); overlayManager->DeleteModal(targetId); EXPECT_EQ(overlayManager->modalList_.size(), 1); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); overlayManager->modalList_.emplace_back(nullptr); overlayManager->DeleteModal(targetId + 1); @@ -1540,7 +1552,8 @@ HWTEST_F(OverlayManagerTestNg, RemoveOverlayTest002, TestSize.Level1) modalStyle.modalTransition = ModalTransition::NONE; bool isShow = true; auto overlayManager = AceType::MakeRefPtr(rootNode); - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); EXPECT_TRUE(overlayManager->RemoveOverlay(false)); @@ -1549,7 +1562,8 @@ HWTEST_F(OverlayManagerTestNg, RemoveOverlayTest002, TestSize.Level1) * @tc.expected: remove successfully. */ modalStyle.modalTransition = ModalTransition::ALPHA; - overlayManager->BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, targetNode); + overlayManager->BindContentCover( + isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_TRUE(overlayManager->RemoveModalInOverlay()); } @@ -1789,19 +1803,12 @@ HWTEST_F(OverlayManagerTestNg, DialogTest003, TestSize.Level1) auto cancelFunc = [](const GestureEvent& info) { (void)info; }; std::map dialogCancelEvent; dialogCancelEvent["cancelId"] = cancelFunc; - auto lifeCycleFunc = []() {}; - std::map dialogLifeCycleEvent; - dialogLifeCycleEvent["didAppearId"] = lifeCycleFunc; - dialogLifeCycleEvent["didDisappearId"] = lifeCycleFunc; - dialogLifeCycleEvent["willAppearId"] = lifeCycleFunc; - dialogLifeCycleEvent["willDisappearId"] = lifeCycleFunc; /** * @tc.steps: step2. create overlayManager and call ShowDateDialog. * @tc.expected: dateDialogNode is created successfully */ auto overlayManager = AceType::MakeRefPtr(rootNode); - overlayManager->ShowDateDialog( - dialogProperties, datePickerSettingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent); + overlayManager->ShowDateDialog(dialogProperties, datePickerSettingData, dialogEvent, dialogCancelEvent); EXPECT_EQ(overlayManager->dialogMap_.size(), 1); /** @@ -1815,8 +1822,8 @@ HWTEST_F(OverlayManagerTestNg, DialogTest003, TestSize.Level1) std::map timePickerProperty; timePickerProperty["selected"] = PickerTime(1, 1, 1); - overlayManager->ShowTimeDialog(dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, - dialogCancelEvent, dialogLifeCycleEvent); + overlayManager->ShowTimeDialog( + dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, dialogCancelEvent); EXPECT_EQ(overlayManager->dialogMap_.size(), 2); /** @@ -1830,13 +1837,13 @@ HWTEST_F(OverlayManagerTestNg, DialogTest003, TestSize.Level1) * @tc.steps: step5. ShowTimeDialog again and call RemoveOverlay with isBackPressed * @tc.expected: remove successfully */ - overlayManager->ShowTimeDialog(dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, - dialogCancelEvent, dialogLifeCycleEvent); + overlayManager->ShowTimeDialog( + dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, dialogCancelEvent); EXPECT_EQ(overlayManager->dialogMap_.size(), 2); EXPECT_TRUE(overlayManager->RemoveOverlay(true)); EXPECT_EQ(overlayManager->dialogMap_.size(), 1); - overlayManager->ShowTimeDialog(dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, - dialogCancelEvent, dialogLifeCycleEvent); + overlayManager->ShowTimeDialog( + dialogProperties, timePickerSettingData, timePickerProperty, dialogEvent, dialogCancelEvent); EXPECT_TRUE(overlayManager->RemoveOverlay(true)); } @@ -1883,10 +1890,11 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern1, TestSize.Level1) SheetStyle sheetStyle; CreateSheetStyle(sheetStyle); bool isShow = true; + auto onWillAppear = []() {}; auto onAppear = []() {}; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - onAppear, nullptr, nullptr, targetNode); + onAppear, nullptr, nullptr, onWillAppear, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); @@ -1898,7 +1906,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern1, TestSize.Level1) sheetStyle.sheetMode = SheetMode::LARGE; sheetStyle.showDragBar = false; overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); auto sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr); auto geometryNode = sheetNode->GetGeometryNode(); @@ -1990,7 +1998,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet004, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); // assert EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); @@ -2038,7 +2046,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet005, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2150,7 +2158,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet006, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2190,7 +2198,7 @@ HWTEST_F(OverlayManagerTestNg, HandleDragUpdate001, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2496,7 +2504,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern2, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2542,7 +2550,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern3, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2645,7 +2653,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern4, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2710,7 +2718,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet007, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2751,7 +2759,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern5, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2792,7 +2800,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern6, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2849,7 +2857,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern7, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -2918,7 +2926,7 @@ HWTEST_F(OverlayManagerTestNg, SheetPresentationPattern8, TestSize.Level1) CreateSheetBuilder(); auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, - nullptr, nullptr, nullptr, targetNode); + nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); ASSERT_NE(topSheetNode, nullptr); @@ -3049,7 +3057,7 @@ HWTEST_F(OverlayManagerTestNg, ShowUIExtensionMenu, TestSize.Level1) */ auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr()); auto baseFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, - ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); + ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); auto uiExtId = ElementRegister::GetInstance()->MakeUniqueId(); auto uiExtNode = FrameNode::CreateFrameNode( V2::DIALOG_ETS_TAG, uiExtId, AceType::MakeRefPtr(AceType::MakeRefPtr(), nullptr)); @@ -3061,7 +3069,7 @@ HWTEST_F(OverlayManagerTestNg, ShowUIExtensionMenu, TestSize.Level1) */ auto overlayManager = AceType::MakeRefPtr(rootNode); ASSERT_NE(overlayManager, nullptr); - + RectF handleRect(3.0, 3.0, 100.0f, 75.0f); EXPECT_FALSE(overlayManager->ShowUIExtensionMenu(uiExtNode, handleRect, LONGEST_CONTENT, MENU_SIZE, baseFrameNode)); }