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 ffa2feaa2f6aa5aaaff87488ee871486b3814baf..70620f8a1c7e6ef385f496a3f1ec26ffa5ce461d 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 @@ -311,18 +311,7 @@ void AppBarView::BindContentCover(const RefPtr& targetNode) }; // Create parameters of UIExtension. - auto missionId = AceApplicationInfo::GetInstance().GetMissionId(); - std::map params; - params.try_emplace("bundleName", AceApplicationInfo::GetInstance().GetProcessName()); - params.try_emplace("abilityName", AceApplicationInfo::GetInstance().GetAbilityName()); - params.try_emplace("module", Container::Current()->GetModuleName()); - if (missionId != -1) { - params.try_emplace("missionId", std::to_string(missionId)); - } - params.try_emplace("ability.want.params.uiExtensionType", "sys/commonUI"); - LOGI("BundleName: %{public}s, AbilityName: %{public}s, Module: %{public}s", - AceApplicationInfo::GetInstance().GetProcessName().c_str(), - AceApplicationInfo::GetInstance().GetAbilityName().c_str(), Container::Current()->GetModuleName().c_str()); + std::map params = CreateUIExtensionParams(); // Create UIExtension node. auto appGalleryBundleName = OHOS::Ace::AppBarHelper::QueryAppGalleryBundleName(); @@ -343,6 +332,23 @@ void AppBarView::BindContentCover(const RefPtr& targetNode) true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); } +std::map AppBarView::CreateUIExtensionParams() +{ + auto missionId = AceApplicationInfo::GetInstance().GetMissionId(); + std::map params; + params.try_emplace("bundleName", AceApplicationInfo::GetInstance().GetProcessName()); + params.try_emplace("abilityName", AceApplicationInfo::GetInstance().GetAbilityName()); + params.try_emplace("module", Container::Current()->GetModuleName()); + if (missionId != -1) { + params.try_emplace("missionId", std::to_string(missionId)); + } + params.try_emplace("ability.want.params.uiExtensionType", "sys/commonUI"); + LOGI("BundleName: %{public}s, AbilityName: %{public}s, Module: %{public}s", + AceApplicationInfo::GetInstance().GetProcessName().c_str(), + AceApplicationInfo::GetInstance().GetAbilityName().c_str(), Container::Current()->GetModuleName().c_str()); + return params; +} + std::optional AppBarView::GetAppBarRect() { auto pipeline = PipelineContext::GetCurrentContext(); diff --git a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.h b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.h index 79f41da9b1ab7325b7b2e7160b5ea14aeac53dd2..0b5783d74d02fa4e594198ef24a08849ab7f48e5 100644 --- a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.h +++ b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.h @@ -54,6 +54,7 @@ private: void BindMenuCallback(const RefPtr& menuButton); void BindCloseCallback(const RefPtr& closeButton); static void BindContentCover(const RefPtr& targetNode); + static std::map CreateUIExtensionParams(); WeakPtr atomicService_; diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 0ec518e14c1e88667db066d06848b6d47bdf6cf9..1c9993a46b4be00a04623a68cc449df029a0a847 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -2270,11 +2270,12 @@ void OverlayManager::BindContentCover(bool isShow, std::functionAddChild(builder); FireModalPageShow(); rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE) || + modalTransition == ModalTransition::NONE) { modalPagePattern->OnAppear(); + // Fire hidden event of navdestination under the appeared modal + FireNavigationStateChange(false); } - // Fire hidden event of navdestination under the appeared modal - FireNavigationStateChange(false); if (modalTransition == ModalTransition::DEFAULT) { PlayDefaultModalTransition(modalNode, true); } else if (modalTransition == ModalTransition::ALPHA) { @@ -2402,53 +2403,70 @@ void OverlayManager::PlayDefaultModalTransition(const RefPtr& modalNo auto showHeight = rootHeight - modalPositionY; 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]() { + PlayDefaultModalIn(modalNode, context, option, showHeight); + } else { + PlayDefaultModalOut(modalNode, context, option, showHeight); + } +} + +void OverlayManager::PlayDefaultModalIn( + const RefPtr& modalNode, const RefPtr& context, AnimationOption option, float showHeight) +{ + context->OnTransformTranslateUpdate({ 0.0f, showHeight, 0.0f }); + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + option.SetOnFinishEvent([modalWK = WeakClaim(RawPtr(modalNode)), overlayWeak = WeakClaim(this)] { + auto modal = modalWK.Upgrade(); + auto overlayManager = overlayWeak.Upgrade(); + CHECK_NULL_VOID(modal && overlayManager); + modal->GetPattern()->OnAppear(); + // Fire hidden event of navdestination on the disappeared modal + overlayManager->FireNavigationStateChange(false); + }); + } + 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); - auto lastModalContext = lastModalNode->GetRenderContext(); - CHECK_NULL_VOID(lastModalContext); - lastModalContext->UpdateOpacity(1.0); - option.SetOnFinishEvent( - [rootWeak = rootNodeWeak_, modalWK = WeakClaim(RawPtr(modalNode)), overlayWeak = WeakClaim(this)] { - auto modal = modalWK.Upgrade(); - auto overlayManager = overlayWeak.Upgrade(); - CHECK_NULL_VOID(modal && overlayManager); - auto root = overlayManager->FindWindowScene(modal); - CHECK_NULL_VOID(root); - if (!modal->GetPattern()->IsExecuteOnDisappear()) { - modal->GetPattern()->OnDisappear(); - // Fire hidden event of navdestination on the disappeared modal - overlayManager->FireNavigationStateChange(false, modal); - } - root->RemoveChild(modal); - root->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - // Fire shown event of navdestination under the disappeared modal - overlayManager->FireNavigationStateChange(true); - }); - context->OnTransformTranslateUpdate({ 0.0f, 0.0f, 0.0f }); - AnimationUtils::Animate( - option, - [context, showHeight]() { - if (context) { - context->OnTransformTranslateUpdate({ 0.0f, showHeight, 0.0f }); - } - }, - option.GetOnFinishEvent()); - } + }, + option.GetOnFinishEvent()); +} + +void OverlayManager::PlayDefaultModalOut( + const RefPtr& modalNode, const RefPtr& context, AnimationOption option, float showHeight) +{ + auto lastModalNode = lastModalNode_.Upgrade(); + CHECK_NULL_VOID(lastModalNode); + auto lastModalContext = lastModalNode->GetRenderContext(); + CHECK_NULL_VOID(lastModalContext); + lastModalContext->UpdateOpacity(1.0); + option.SetOnFinishEvent( + [rootWeak = rootNodeWeak_, modalWK = WeakClaim(RawPtr(modalNode)), overlayWeak = WeakClaim(this)] { + auto modal = modalWK.Upgrade(); + auto overlayManager = overlayWeak.Upgrade(); + CHECK_NULL_VOID(modal && overlayManager); + auto root = overlayManager->FindWindowScene(modal); + CHECK_NULL_VOID(root); + if (!modal->GetPattern()->IsExecuteOnDisappear()) { + modal->GetPattern()->OnDisappear(); + // Fire hidden event of navdestination on the disappeared modal + overlayManager->FireNavigationStateChange(false, modal); + } + root->RemoveChild(modal); + root->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + // Fire shown event of navdestination under the disappeared modal + overlayManager->FireNavigationStateChange(true); + }); + context->OnTransformTranslateUpdate({ 0.0f, 0.0f, 0.0f }); + AnimationUtils::Animate( + option, + [context, showHeight]() { + if (context) { + context->OnTransformTranslateUpdate({ 0.0f, showHeight, 0.0f }); + } + }, + option.GetOnFinishEvent()); } void OverlayManager::PlayAlphaModalTransition(const RefPtr& modalNode, bool isTransitionIn) @@ -2468,12 +2486,14 @@ void OverlayManager::PlayAlphaModalTransition(const RefPtr& modalNode 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(); - }); + option.SetOnFinishEvent([modalWK = WeakClaim(RawPtr(modalNode)), overlayWeak = WeakClaim(this)] { + auto modal = modalWK.Upgrade(); + auto overlayManager = overlayWeak.Upgrade(); + CHECK_NULL_VOID(modal && overlayManager); + modal->GetPattern()->OnAppear(); + // Fire hidden event of navdestination on the disappeared modal + overlayManager->FireNavigationStateChange(false); + }); } // current modal page animation context->OpacityAnimation(option, 0, 1); @@ -2781,13 +2801,14 @@ void OverlayManager::PlaySheetTransition( option.SetDuration(0); option.SetCurve(Curves::LINEAR); } - option.SetOnFinishEvent([sheetWK = WeakClaim(RawPtr(sheetNode))] { + option.SetOnFinishEvent([sheetWK = WeakClaim(RawPtr(sheetNode)), isFirst = isFirstTransition] { auto sheetNode = sheetWK.Upgrade(); CHECK_NULL_VOID(sheetNode); auto context = sheetNode->GetRenderContext(); CHECK_NULL_VOID(context); context->UpdateRenderGroup(false, true, true); - if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE) && + isFirst) { sheetNode->GetPattern()->OnAppear(); } }); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h index 208ad7e8e29a9c892b99af7ad737c95ddba3936a..87becb62aa81b393e6a9d6bef6db3ae40e8d5f55 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h @@ -466,6 +466,10 @@ private: void PlayBubbleStyleSheetTransition(RefPtr sheetNode, bool isTransitionIn); void CheckReturnFocus(RefPtr node); void MountPopup(int32_t targetId, const PopupInfo& popupInfo); + void PlayDefaultModalIn(const RefPtr& modalNode, const RefPtr& context, + AnimationOption option, float showHeight); + void PlayDefaultModalOut(const RefPtr& modalNode, const RefPtr& context, + AnimationOption option, float showHeight); // Key: target Id, Value: PopupInfo std::unordered_map popupMap_; 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 aa426b403086de16dcf94df5ee431b5e562eb130..82655c7c7c7c7fb568cde837d680ec87e1288b8c 100644 --- a/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/overlay_manager_test_ng.cpp @@ -103,6 +103,7 @@ protected: static RefPtr CreateTargetNode(); static void CreateSheetStyle(SheetStyle& sheetStyle); void CreateSheetBuilder(); + RefPtr BindTargetNode(RefPtr rootNode); }; void OverlayManagerTestNg::SetUpTestCase() @@ -182,6 +183,18 @@ void OverlayManagerTestNg::CreateSheetBuilder() builderFunc_ = builderFunc; titleBuilderFunc_ = buildTitleNodeFunc; } + +RefPtr OverlayManagerTestNg::BindTargetNode(RefPtr rootNode) +{ + auto targetNode = CreateTargetNode(); + auto stageNode = FrameNode::CreateFrameNode( + V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + stageNode->MountToParent(rootNode); + targetNode->MountToParent(stageNode); + rootNode->MarkDirtyNode(); + return targetNode; +} + /** * @tc.name: PopupTest001 * @tc.desc: Test OverlayManager::ShowPopup. @@ -306,15 +319,7 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) /** * @tc.steps: step2. create target node. */ - auto builderFunc = []() -> RefPtr { - auto frameNode = - FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), - []() { return AceType::MakeRefPtr(true); }); - auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, - ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); - frameNode->AddChild(childFrameNode); - return frameNode; - }; + CreateSheetBuilder(); /** * @tc.steps: step3. create modal node and get modal node, get pattern. @@ -326,7 +331,7 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) auto onAppear = []() {}; auto overlayManager = AceType::MakeRefPtr(rootNode); overlayManager->BindContentCover( - isShow, nullptr, std::move(builderFunc), modalStyle, onAppear, nullptr, onWillAppear, 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); @@ -341,7 +346,7 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) */ modalStyle.modalTransition = ModalTransition::NONE; overlayManager->BindContentCover( - isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); + isShow, nullptr, std::move(builderFunc_), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); topModalNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_NE(topModalNode, nullptr); topModalPattern = topModalNode->GetPattern(); @@ -355,7 +360,7 @@ HWTEST_F(OverlayManagerTestNg, BindContentCover002, TestSize.Level1) */ modalStyle.backgroundColor = Color::GREEN; overlayManager->BindContentCover( - isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr, nullptr, targetNode); + 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); @@ -617,36 +622,13 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) /** * @tc.steps: step1. create target node. */ - auto targetNode = CreateTargetNode(); - auto stageNode = FrameNode::CreateFrameNode( - V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr()); - stageNode->MountToParent(rootNode); - targetNode->MountToParent(stageNode); - rootNode->MarkDirtyNode(); + auto targetNode = BindTargetNode(rootNode); /** * @tc.steps: step2. create builder. */ - auto builderFunc = []() -> RefPtr { - auto frameNode = - FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), - []() { return AceType::MakeRefPtr(true); }); - auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, - ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); - frameNode->AddChild(childFrameNode); - return frameNode; - }; - - auto buildTitleNodeFunc = []() -> RefPtr { - auto frameNode = - FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), - []() { return AceType::MakeRefPtr(true); }); - auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, - ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); - frameNode->AddChild(childFrameNode); - return frameNode; - }; + CreateSheetBuilder(); /** * @tc.steps: step3. create sheet node and get sheet node, get pattern. @@ -658,7 +640,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) auto onWillAppear = []() {}; auto onAppear = []() {}; auto overlayManager = AceType::MakeRefPtr(rootNode); - overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, + overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, onAppear, nullptr, nullptr, onWillAppear, nullptr, targetNode); EXPECT_FALSE(overlayManager->modalStack_.empty()); auto topSheetNode = overlayManager->modalStack_.top().Upgrade(); @@ -674,14 +656,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, + overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, 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, + overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); sheetPattern = sheetNode->GetPattern(); @@ -697,7 +679,7 @@ HWTEST_F(OverlayManagerTestNg, OnBindSheet002, TestSize.Level1) * @tc.expected: the backgroundColor is updated successfully */ sheetStyle.backgroundColor = Color::GREEN; - overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle, + overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); sheetNode = overlayManager->modalStack_.top().Upgrade(); EXPECT_FALSE(topSheetNode == nullptr);