!44501 修复弹出其他二级菜单,再弹出STACK_EXPAND,此时点击STACK_EXPAND的关闭按钮,整个Menu都变为透明

Merge pull request !44501 from 林昊/menu_stack_200924
This commit is contained in:
openharmony_ci 2024-10-12 12:11:28 +00:00 committed by Gitee
commit 2b6d7de568
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 24 additions and 13 deletions

View File

@ -202,6 +202,25 @@ void MenuWrapperPattern::HideMenu()
HideMenu(menuNode);
}
void MenuWrapperPattern::GetExpandingMode(const RefPtr<UINode>& subMenu, SubMenuExpandingMode& expandingMode,
bool& hasAnimation)
{
CHECK_NULL_VOID(subMenu);
auto subMenuPattern = DynamicCast<FrameNode>(subMenu)->GetPattern<MenuPattern>();
CHECK_NULL_VOID(subMenuPattern);
hasAnimation = subMenuPattern->GetDisappearAnimation();
auto menuItem = FrameNode::GetFrameNode(subMenuPattern->GetTargetTag(), subMenuPattern->GetTargetId());
CHECK_NULL_VOID(menuItem);
auto menuItemPattern = menuItem->GetPattern<MenuItemPattern>();
CHECK_NULL_VOID(menuItemPattern);
auto menuNode = menuItemPattern->GetMenu();
CHECK_NULL_VOID(menuNode);
auto menuProperty = menuNode->GetLayoutProperty<MenuLayoutProperty>();
CHECK_NULL_VOID(menuProperty);
expandingMode = menuProperty->GetExpandingMode().value_or(SubMenuExpandingMode::SIDE);
menuItemPattern->SetIsSubMenuShowed (false);
}
void MenuWrapperPattern::HideSubMenu()
{
auto host = GetHost();
@ -216,16 +235,6 @@ void MenuWrapperPattern::HideSubMenu()
CHECK_NULL_VOID(menuPattern);
menuPattern->SetShowedSubMenu(nullptr);
auto subMenu = host->GetChildren().back();
auto subMenuPattern = DynamicCast<FrameNode>(subMenu)->GetPattern<MenuPattern>();
if (subMenuPattern) {
subMenuPattern->RemoveParentHoverStyle();
auto frameNode = FrameNode::GetFrameNode(subMenuPattern->GetTargetTag(), subMenuPattern->GetTargetId());
CHECK_NULL_VOID(frameNode);
auto menuItem = frameNode->GetPattern<MenuItemPattern>();
if (menuItem) {
menuItem->SetIsSubMenuShowed(false);
}
}
auto focusMenu = MenuFocusViewShow();
CHECK_NULL_VOID(focusMenu);
auto innerMenu = GetMenuChild(focusMenu);
@ -236,7 +245,6 @@ void MenuWrapperPattern::HideSubMenu()
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
return;
}
CHECK_NULL_VOID(innerMenu);
auto innerMenuPattern = innerMenu->GetPattern<MenuPattern>();
CHECK_NULL_VOID(innerMenuPattern);
auto layoutProps = innerMenuPattern->GetLayoutProperty<MenuLayoutProperty>();
@ -245,8 +253,11 @@ void MenuWrapperPattern::HideSubMenu()
auto outterMenuPattern = focusMenu->GetPattern<MenuPattern>();
CHECK_NULL_VOID(outterMenuPattern);
bool hasAnimation = outterMenuPattern->GetDisappearAnimation();
GetExpandingMode(subMenu, expandingMode, hasAnimation);
if (expandingMode == SubMenuExpandingMode::STACK && hasAnimation) {
HideStackExpandMenu(subMenu);
host->RemoveChild(subMenu);
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
} else {
UpdateMenuAnimation(host);
SendToAccessibility(subMenu, false);

View File

@ -111,7 +111,7 @@ public:
void HideSubMenu();
RefPtr<FrameNode> MenuFocusViewShow();
void HideStackExpandMenu(const RefPtr<UINode>& subMenu);
void GetExpandingMode(const RefPtr<UINode>& subMenu, SubMenuExpandingMode& expandingMode, bool& hasAnimation);
RefPtr<FrameNode> GetMenu() const
{
auto host = GetHost();

View File

@ -830,7 +830,7 @@ HWTEST_F(MenuWrapperTestNg, MenuWrapperPatternTestNg015, TestSize.Level1)
mainMenu->GetPattern<MenuPattern>()->SetDisappearAnimation(true);
subMenu->GetPattern<MenuPattern>()->SetDisappearAnimation(true);
wrapperPattern->HideSubMenu();
EXPECT_EQ(wrapperNode->GetChildren().size(), 2);
EXPECT_EQ(wrapperNode->GetChildren().size(), 1);
}
/**