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 e811a2aafc44ec22b35c7d335196b8c770c983ab..af3af24ce29951da3734a253c1b9a25ab1a7eff4 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp @@ -313,7 +313,7 @@ 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->GetId()); + std::move(onAppear), std::move(onDisappear), targetNode); } void ViewAbstractModelNG::RegisterContextMenuKeyEvent( @@ -376,7 +376,7 @@ 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->GetId()); + sheetStyle, std::move(onAppear), std::move(onDisappear), std::move(shouldDismiss), targetNode); } void ViewAbstractModelNG::DismissSheet() 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 8691d0b8b2b7fab62bf8f699a44165201bc7f010..cad19cca7524e2e417e7af895d1fdc90fe233075 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 @@ -162,8 +162,7 @@ RefPtr AppBarView::BuildFaButton() auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, nullptr); auto appBarTheme = pipeline->GetTheme(); - auto buttonId = buttonNode->GetId(); - auto clickCallback = [pipeline, appBarTheme, buttonId](GestureEvent& info) { + auto clickCallback = [pipeline, appBarTheme, buttonNode](GestureEvent& info) { #ifdef PREVIEW LOGW("[Engine Log] Unable to show the SharePanel in the Previewer. Perform this operation on the " "emulator or a real device instead."); @@ -176,7 +175,7 @@ RefPtr AppBarView::BuildFaButton() appBarTheme->GetBundleName().c_str(), appBarTheme->GetAbilityName().c_str()); pipeline->FireSharePanelCallback(appBarTheme->GetBundleName(), appBarTheme->GetAbilityName()); } else { - BindContentCover(buttonId); + BindContentCover(buttonNode); } #endif }; @@ -238,7 +237,7 @@ RefPtr AppBarView::BuildIconButton( return buttonNode; } -void AppBarView::BindContentCover(int32_t targetId) +void AppBarView::BindContentCover(const RefPtr& targetNode) { if (OHOS::Ace::AppBarHelper::QueryAppGalleryBundleName().empty()) { LOGE("UIExtension BundleName is empty."); @@ -257,13 +256,13 @@ void AppBarView::BindContentCover(int32_t targetId) } NG::ModalStyle modalStyle; modalStyle.modalTransition = NG::ModalTransition::NONE; - auto buildNodeFunc = [targetId, overlayManager, &modalStyle, &stageAbilityName]() -> RefPtr { - auto onRelease = [overlayManager, &modalStyle, targetId](int32_t releaseCode) { - overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetId); + auto buildNodeFunc = [targetNode, overlayManager, &modalStyle, &stageAbilityName]() -> RefPtr { + auto onRelease = [overlayManager, &modalStyle, targetNode](int32_t releaseCode) { + overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetNode); }; - auto onError = [overlayManager, &modalStyle, targetId]( + auto onError = [overlayManager, &modalStyle, targetNode]( int32_t code, const std::string& name, const std::string& message) { - overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetId); + overlayManager->BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, targetNode); }; // Create parameters of UIExtension. @@ -295,7 +294,7 @@ void AppBarView::BindContentCover(int32_t targetId) uiExtNode->MarkModifyDone(); return uiExtNode; }; - overlayManager->BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, targetId); + overlayManager->BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, targetNode); } void AppBarView::SetVisible(bool visible) 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 7bc737e106a544633078b9413f3f266f7d9b7977..db11ccb4cea24aafe90cec8110b815f48a3ebfb3 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 @@ -60,7 +60,7 @@ private: static RefPtr BuildBarTitle(); static RefPtr BuildIconButton( InternalResource::ResourceId icon, GestureEventFunc&& clickCallback, bool isBackButton); - static void BindContentCover(int32_t targetId); + static void BindContentCover(const RefPtr& targetNode); static RefPtr BuildFaButton(); static void SetEachIconColor( RefPtr icon, const std::optional& color, InternalResource::ResourceId image); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 8990743a12887a0314ef4e3529b0ddd0d4bdd0ad..2e0fa58a588f54d2afd1e58d648064deddab5a18 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -1498,8 +1498,6 @@ bool OverlayManager::RemoveOverlay(bool isBackPressed, bool isPageRouter) bool OverlayManager::RemoveModalInOverlay() { - auto rootNode = rootNodeWeak_.Upgrade(); - CHECK_NULL_RETURN(rootNode, true); auto topModalNode = modalStack_.top().Upgrade(); CHECK_NULL_RETURN(topModalNode, false); if (topModalNode->GetTag() == V2::SHEET_PAGE_TAG) { @@ -1510,6 +1508,10 @@ bool OverlayManager::RemoveModalInOverlay() return true; } } + + auto rootNode = FindWindowScene(topModalNode); + CHECK_NULL_RETURN(rootNode, true); + ModalPageLostFocus(topModalNode); auto pattern = topModalNode->GetPattern(); if (isProhibitBack_ && pattern->GetTargetId() < 0) { @@ -1533,7 +1535,7 @@ bool OverlayManager::RemoveModalInOverlay() auto modalTransition = modalPattern->GetType(); if (modalTransition == ModalTransition::NONE || builder->GetRenderContext()->HasTransition()) { // Fire shown event of navdestination under the disappeared modal - FireNavigationStateChange(true); + FireNavigationStateChange(rootNode, true); } } @@ -1544,14 +1546,14 @@ bool OverlayManager::RemoveModalInOverlay() bool OverlayManager::RemoveAllModalInOverlay() { - auto rootNode = rootNodeWeak_.Upgrade(); - CHECK_NULL_RETURN(rootNode, true); while (!modalStack_.empty()) { auto topModalNode = modalStack_.top().Upgrade(); if (!topModalNode) { modalStack_.pop(); continue; } + auto rootNode = FindWindowScene(topModalNode); + CHECK_NULL_RETURN(rootNode, true); auto builder = AceType::DynamicCast(topModalNode->GetFirstChild()); CHECK_NULL_RETURN(builder, false); ModalPageLostFocus(topModalNode); @@ -1571,7 +1573,7 @@ bool OverlayManager::RemoveAllModalInOverlay() auto modalTransition = modalPattern->GetType(); if (modalTransition == ModalTransition::NONE || builder->GetRenderContext()->HasTransition()) { // Fire shown event of navdestination under the disappeared modal - FireNavigationStateChange(true); + FireNavigationStateChange(rootNode, true); } } @@ -1583,7 +1585,7 @@ bool OverlayManager::RemoveAllModalInOverlay() bool OverlayManager::ModalExitProcess(const RefPtr& topModalNode) { - auto rootNode = rootNodeWeak_.Upgrade(); + auto rootNode = FindWindowScene(topModalNode); CHECK_NULL_RETURN(rootNode, true); if (topModalNode->GetTag() == V2::MODAL_PAGE_TAG) { auto builder = AceType::DynamicCast(topModalNode->GetFirstChild()); @@ -1593,7 +1595,7 @@ bool OverlayManager::ModalExitProcess(const RefPtr& topModalNode) if (!topModalNode->GetPattern()->IsExecuteOnDisappear()) { topModalNode->GetPattern()->OnDisappear(); // Fire hidden event of navdestination on the disappeared modal - FireNavigationStateChange(false, topModalNode); + FireNavigationStateChange(rootNode, false, topModalNode); } topModalNode->Clean(false, true); topModalNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); @@ -1605,7 +1607,7 @@ bool OverlayManager::ModalExitProcess(const RefPtr& topModalNode) } else if (!builder->GetRenderContext()->HasTransition()) { topModalNode->GetPattern()->OnDisappear(); // Fire hidden event of navdestination on the disappeared modal - FireNavigationStateChange(false, topModalNode); + FireNavigationStateChange(rootNode, false, topModalNode); rootNode->RemoveChild(topModalNode); rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } @@ -1812,7 +1814,7 @@ void OverlayManager::SaveLastModalNode() } } -void OverlayManager::FireNavigationStateChange(bool show, const RefPtr& node) +void OverlayManager::FireNavigationStateChange(const RefPtr& root, bool show, const RefPtr& node) { if (!show && node) { // Only check node When it is appointed @@ -1828,9 +1830,7 @@ void OverlayManager::FireNavigationStateChange(bool show, const RefPtr& return; } - auto rootNode = rootNodeWeak_.Upgrade(); - CHECK_NULL_VOID(rootNode); - const auto& children = rootNode->GetChildren(); + const auto& children = root->GetChildren(); for (auto iter = children.begin(); iter != children.end(); ++iter) { auto& child = *iter; if (!show && child == topModalNode) { @@ -1843,9 +1843,10 @@ void OverlayManager::FireNavigationStateChange(bool show, const RefPtr& void OverlayManager::BindContentCover(bool isShow, std::function&& callback, std::function()>&& buildNodeFunc, NG::ModalStyle& modalStyle, std::function&& onAppear, - std::function&& onDisappear, int32_t targetId) + std::function&& onDisappear, const RefPtr& targetNode, int32_t sessionId) { - auto rootNode = rootNodeWeak_.Upgrade(); + int32_t targetId = targetNode ? targetNode->GetId() : sessionId; + auto rootNode = FindWindowScene(targetNode); CHECK_NULL_VOID(rootNode); auto modalTransition = modalStyle.modalTransition; if (!modalTransition.has_value()) { @@ -1893,7 +1894,7 @@ void OverlayManager::BindContentCover(bool isShow, std::function