Arkui menu debug

From openharmonyinsight/openharmony-skills · View interactive version

Arkui menu debug is an AI agent skill from the GitHub repository openharmonyinsight/openharmony-skills. This skill should be used when user asks to "Menu宽度为0", "Menu宽度问题", "Menu显示异常", "Menu子窗口问题", "Menu layout异常", "recreate subwindow", "快速打开Menu问题", "Menu闪退", "Menu位置错误", "子窗口recreate", "Menu崩溃", "Menu打印recreate", "点击无响应", "点击菜单关闭", "菜单位置左上角", "菜单方向不对", "菜单避让坑", "宽度高度为0", or mentions any Menu component

How to use this skill

Skill file

Menu Component Debugging Skill

Systematic debugging and problem diagnosis for Menu component issues in OpenHarmony ACE Engine. This skill provides structured troubleshooting guidance for Menu-related problems with automatic log enhancement patch generation.

Overview

Menu component debugging requires analyzing multiple layers:

Critical Requirements:

Problem Categories

1. Menu Width Issues

Symptoms:

Common Causes:

2. Subwindow Recreation Issues

Symptoms:

Common Causes:

3. Menu Layout Issues

Symptoms:

Common Causes:

4. Menu Crash/Instability

Symptoms:

Common Causes:

5. Click Response Issues

Symptoms:

Common Causes:

6. Menu Auto-Close Issues

Symptoms:

Common Causes:

7. Menu Positioning Issues

Symptoms:

Common Causes:

8. Safe Area/Navigation Bar Issues

Symptoms:

Common Causes:

9. Menu Dimension Issues

Symptoms:

Common Causes:

Debugging Workflow

Step 1: Identify Problem Category

Based on symptoms, identify which problem category:

Width/Dimension Issues → Look for:

Menu width is 0
menuMaxWidth = 0
displayWindowRectInfo.Width() = 0

Subwindow Issues → Look for:

recreate subwindow
DETACHING state
MenuWindowRect

Layout Issues → Look for:

MenuOffset incorrect
position calculation error
menuWindowRect

Crash Issues → Look for:

Segmentation fault
Null pointer
CHECK_NULL_*

Click/Auto-Close Issues → Look for:

HideMenu called
state transition
gesture event not received

Positioning Issues → Look for:

anchorPoint calculation
MenuWindowRect values
offset errors

Step 2: Locate Key Code Locations

For Width/Dimension Issues:

For Subwindow Issues:

For Layout Issues:

For Click/Auto-Close Issues:

For Positioning Issues:

Step 3: Collect Existing Logs

Key log tags to filter:

# Menu-related logs
cat xxx.log | grep "ACE_MENU"
cat xxx.log | grep "ACE_SUB_WINDOW"
cat xxx.log | grep "ACE_OVERLAY"

# Specific issues
cat xxx.log | grep "recreate subwindow"
cat xxx.log | grep "DisplayWindowRectInfo"
cat xxx.log | grep "MenuWindowRect"
cat xxx.log | grep "HideMenu"
cat xxx.log | grep "OnClick"

Critical log patterns:

New Problem Analysis (v0.2.0)

Problem 1: 点击无响应/点击弹不出来菜单 (Click No Response)

Symptoms:

Possible Causes:

  1. 事件中心未正确初始化
  1. 菜单状态不正确
  1. 点击区域被遮挡
  1. 事件被消费

Debug Steps:

  1. 检查事件注册

```bash

# 查找菜单事件相关日志

cat xxx.log | grep "OnClick"

cat xxx.log | grep "GestureEventHub"

```

  1. 检查菜单状态

```bash

# 查找菜单状态

cat xxx.log | grep "MenuWrapper"

cat xxx.log | grep "MenuState"

```

  1. 检查 window 状态

```bash

# 查找子窗口状态

cat xxx.log | grep "ACE_SUB_WINDOW"

cat xxx.log | grep "MenuWindowRect"

```

Code Locations:

Solutions:

  1. 确保事件正确注册
  1. 检查菜单状态机
  1. 验证点击区域
  1. 添加调试日志

```cpp

// 在点击处理中添加日志

TAG_LOGI(AceLogTag::ACE_MENU, "OnClick called: menuId=%{public}d", menuId);

```


Problem 2: 点击菜单立马就关闭了 (Menu Closes Immediately)

Symptoms:

Possible Causes:

  1. 状态机错误
  1. 触摸事件冲突
  1. Window 焦点问题
  1. 超时配置错误

Debug Steps:

  1. 检查状态转换日志

```bash

# 查找快速的状态变化

cat xxx.log | grep -E "ATTACHING|DETACHING" | head -20

```

  1. 检查 HideMenu 调用

```bash

# 查找谁调用了 HideMenu

cat xxx.log | grep "HideMenu" | grep -B 5 "ShowMenu"

```

  1. 检查触摸事件

```bash

# 查找触摸事件

cat xxx.log | grep "Touch"

cat xxx.log | grep "Click"

```

  1. 检查窗口生命周期

```bash

# 查找子窗口创建和销毁

cat xxx.log | grep "GetOrCreateMenuSubWindow"

cat xxx.log | grep "RemoveMenuSubWindow"

```

Code Locations:

Solutions:

  1. 修复状态转换逻辑
  1. 优化事件处理
  1. 检查焦点管理
  1. 增加状态保护

```cpp

// 添加状态检查

if (menuWrapperPattern->GetState() != MenuWrapperState::DETACHING) {

TAG_LOGW(AceLogTag::ACE_MENU,

"Invalid HideMenu call, current state=%{public}d",

static_cast<int>(state));

return;

}

```


Problem 3: 弹出菜单位置在屏幕左上角 (Menu Positioned at Top-Left)

Symptoms:

Possible Causes:

  1. Offset 计算错误
  1. 锚点配置错误
  1. MenuWindowRect 计算错误
  1. Placement 配置未生效

Debug Steps:

  1. 检查位置相关日志

```bash

# 查找菜单位置计算

cat xxx.log | grep "MenuOffset"

cat xxx.log | grep "MenuPosition"

cat xxx.log | grep "targetOffset"

```

  1. 检查窗口 Rect 信息

```bash

# 查找窗口矩形

cat xxx.log | grep "MenuWindowRect"

cat xxx.log | grep "DisplayWindowRectInfo"

```

  1. 检查 placement 配置

```bash

# 查找 placement 配置

cat xxx.log | grep "placement"

cat xxx.log | grep "anchor"

```

Code Locations:

Solutions:

  1. 验证 Offset 计算
  1. 检查锚点配置
  1. 验证 Placement
  1. 添加位置调试日志

```cpp

// 添加位置日志

TAG_LOGI(AceLogTag::ACE_MENU,

"Menu position: offset=(%{public}f,%{public}f), target=(%{public}f,%{public}f)",

offsetX, offsetY, targetOffsetX, targetOffsetY);

```


Problem 4: 菜单弹出方向不对 (Menu Direction Incorrect)

Symptoms:

Possible Causes:

  1. Direction 参数错误
  1. Placement 计算错误
  1. Target 位置计算错误
  1. 布局算法方向错误

Debug Steps:

  1. 检查方向相关配置

```bash

# 查找方向配置

cat xxx.log | grep -E "direction|font|arrow"

```

  1. 检查 placement 配置

```bash

cat xxx.log | grep "placement"

cat xxx.log | grep "AlignDirection"

```

  1. 检查布局方向

```bash

cat xxx.log | grep "mainAxisSize"

cat xxx.log | grep "crossAxis"

```

Code Locations:

Solutions:

  1. 验证 Direction 参数
  1. 修正 Placement 计算
  1. 检查目标位置
  1. 添加方向调试日志

```cpp

TAG_LOGI(AceLogTag::ACE_MENU,

"Menu direction: placement=%{public}d, direction=%{public}d",

placement, direction);

```


Problem 5: 菜单没有避让挖坑/导航条 (Menu Overlaps System UI)

Symptoms:

Possible Causes:

  1. SafeArea 未应用
  1. Window Rect 计算错误
  1. Z-Order 问题
  1. Maximize 设置错误

Debug Steps:

  1. 检查 SafeArea 相关日志

```bash

cat xxx.log | grep -i "safe|safeArea"

```

  1. 检查 Window Mode

```bash

cat xxx.log | grep "LayoutFullScreen"

cat xxx.log | grep "WindowMode"

```

  1. 检查 Window Rect

```bash

cat xxx.log | grep "DisplayWindowRectInfo"

```

Code Locations:

Solutions:

  1. 应用 SafeArea 约束
  1. 调整 Window Mode
  1. 修正 Window Rect 计算
  1. 验证 Z-Order

Problem 6: 菜单弹出宽度为0/高度为0 (Menu Width/Height is 0)

Symptoms:

Possible Causes:

  1. 异步初始化未完成
  1. Pipeline Context 来源错误
  1. MenuParam 配置错误
  1. 计算公式错误

Debug Steps:

  1. 检查 displayWidth 相关日志

```bash

# 查找宽度计算

cat xxx.log | grep "displayWidth"

cat xxx.log | grep "displayWindowRect.Width"

cat xxx.log | grep "menuMaxWidthRatio"

```

  1. 检查 MenuParam

```bash

cat xxx.log | grep "MenuParam"

cat xxx.log | grep "fontSize"

```

  1. 检查 Pipeline Context

```bash

cat xxx.log | grep "PipelineContext"

cat xxx.log | grep "GetMainPipelineContext"

```

Code Locations:

Solutions:

  1. 添加初始化检查

```cpp

// 在 GetMenuWindowRectInfo 中添加检查

auto displayWidth = displayWindowRectInfo.Width();

if (displayWidth <= 0.0f) {

TAG_LOGE(AceLogTag::ACE_MENU,

"Invalid displayWidth=%{public}f, waiting for async init",

displayWidth);

return menuWindowRect;

}

```

  1. 验证 Context 来源
  1. 延迟宽度计算
  1. 添加异步初始化日志

```cpp

TAG_LOGI(AceLogTag::ACE_MENU,

"Async display init: displayWidth=%{public}f, ready=%{public}d",

displayWidth, IsDisplayReady());

```


Log Enhancement Reference

Key Logging Patterns

1. State Transition Logging

TAG_LOGI(AceLogTag::ACE_SUB_WINDOW,
    "Subwindow state transition: %{public}d -> %{public}d",
    static_cast<int>(oldState), static_cast<int>(newState));

2. Value Context Logging

TAG_LOGI(AceLogTag::ACE_MENU,
    "Calculation: displayWidth=%{public}f, menuMaxWidthRatio=%{public}f, result=%{public}f",
    displayWidth, menuMaxWidthRatio, menuMaxWidth);

3. Code Path Logging

TAG_LOGI(AceLogTag::ACE_MENU,
    "GetMenuWindowRectInfo: host=%{public}p, menuId=%{public}d, targetTag=%{public}d, targetNodeId=%{public}d",
    host.Get(), menuPattern->GetMenuId(), targetTag_, targetNodeId_);

4. Error Context Logging

if (displayWidth <= 0.0f) {
    TAG_LOGE(AceLogTag::ACE_MENU,
        "Invalid displayWidth=%{public}f, expected>%{public}f",
        displayWidth, expectedWidth);
    return;
}

Critical Variables to Log

For Width/Height Issues:

For Subwindow Issues:

For Layout Issues:

Quick Reference Code Locations

| Problem Type | File | Line(s) | Function | Key Variables |

|-------------|------|----------|----------|---------------|

| Click issues | menu_wrapper_pattern.cpp | - | OnDetach / OnAttach | state_ |

| Auto-close | menu_pattern.cpp | - | State machine | isShowing_ |

| Position (top-left) | menu_layout_algorithm.cpp | 3611-3659 | GetMenuWindowRectInfo | menuWindowRect |

| Direction | menu_pattern.cpp | - | direction_ / placement | - |

| Safe area | subwindow_manager.cpp | - | Window creation params | - |

| Width=0/Height=0 | menu_layout_algorithm.cpp | 920-966 | UpdateChildConstraintByDevice | displayWidth |

Log Filtering Commands

Extract all Menu-related logs:

# Comprehensive Menu logs
grep -E "ACE_MENU|ACE_SUB_WINDOW|ACE_OVERLAY" xxx.log > menu_debug.log

# Width-specific logs
grep -E "DisplayWindowRectInfo|menuMaxWidth|displayWidth" xxx.log

# Subwindow recreation logs
grep -E "recreate subwindow|DETACHING|MenuWindowState" xxx.log

# Positioning logs
grep -E "MenuOffset|MenuPosition|targetOffset|placement" xxx.log

# Click/Event logs
grep -E "OnClick|TouchEvent|GestureEvent" xxx.log

Filter by specific instance:

# For specific container ID
grep "instanceId: 123" xxx.log

# For specific menu node
grep "menuId: 456" xxx.log

Best Practices

Log Enhancement Principles

DO:

DON'T:

Patch Generation Guidelines

  1. Minimal Changes - Only add logging, don't modify logic
  2. Preserve Formatting - Follow existing code style
  3. Use Existing Macros - TAG_LOGI/W/E with correct tags
  4. Test Compilation - Verify syntax before applying
  5. Document Changes - Note what and why for each log
  6. Contextual Logging - Include surrounding code state in logs

Analysis Workflow

  1. Gather baseline - Collect logs without issue if possible
  2. Apply patch - Add targeted logging
  3. Reproduce issue - Trigger problem with enhanced logging
  4. Extract relevant logs - Filter specific log tags
  5. Trace execution flow - Follow log sequence through code
  6. Identify root cause - Find where unexpected behavior occurs
  7. Implement fix - Address identified issue
  8. Verify resolution - Confirm fix works, remove debug logs if needed

Integration with Other Skills

This skill complements:

Version History

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.