Skip to content

fix(harmony): 修复 harmony_cpp 在开启 tabbar 后无法正常编译的问题 #17797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 7, 2025

Conversation

xuanzebin
Copy link
Member

@xuanzebin xuanzebin commented Jun 4, 2025

这个 PR 做了什么? (简要描述所做更改)

  • 修复 harmony_cpp 在开启 tabbar 后无法正常编译的问题

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

Summary by CodeRabbit

  • 新功能

    • 增强了对多页面支持,允许同时处理多个页面的渲染和初始化。
    • 多标签栏页面支持独立管理每个标签的标题栏、背景色及状态,提升页面切换体验。
    • 页面样式导入和状态管理支持数组形式,适配多页面场景。
  • 修复

    • 优化了多标签栏页面在状态栏高度和页面生命周期事件中的处理逻辑,提升稳定性和一致性。

@xuanzebin xuanzebin requested a review from ZakaryCode June 4, 2025 08:50
Copy link

coderabbitai bot commented Jun 4, 2025

"""

Walkthrough

本次更改在鸿蒙平台的页面生成逻辑中,针对 tabbar 页添加了分支处理。涉及页面状态、节点引用、生命周期方法等多个环节,均新增了对 tabbar 页的数组化处理和组件包裹,确保多个 tab 页能正确生成、渲染和响应事件。

Changes

文件/分组 变更摘要
packages/taro-platform-harmony-cpp/src/program/vite/page.ts 支持多页面(数组)输入,新增 isPure 标记,针对 tabbar 页实现状态、节点、方法数组化,页面构建包裹于 Tabs 组件,生命周期方法支持索引处理
packages/taro-platform-harmony-cpp/src/program/vite/render.ts 修改 modifyPageImport 方法签名支持单页或多页,内部逻辑保持不变
packages/taro-platform-harmony-cpp/src/program/vite/style.ts 修改 modifyPageImport 支持单页或多页,数组时循环导入对应样式并注册,单页逻辑保持

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant PageParser
    participant Tabs
    participant TabPage

    App->>PageParser: 初始化页面
    alt 非 tabbar 页
        PageParser->>TabPage: 构建单一页面节点
    else tabbar 页
        PageParser->>Tabs: 创建 Tabs 组件
        Tabs->>TabPage: ForEach 遍历 tabBarList 构建多个页面节点
    end
    PageParser->>TabPage: 生命周期方法(如 handlePageAppear)按索引处理
Loading

Assessment against linked issues

Objective Addressed Explanation
修复鸿蒙平台下使用 tabbar 时编译异常,支持 tabbar 页面的正确生成与渲染(#17768

Suggested reviewers

  • Single-Dancer

Poem

兔子挥笔写新篇,
Tabbar 页面不再难。
数组化节点巧处理,
Tabs 组件来包揽。
鸿蒙编译无异常,
跳跃前行更轻安!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot requested a review from yoturg June 4, 2025 08:50
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7185605 and 162c1d8.

📒 Files selected for processing (1)
  • packages/taro-platform-harmony-cpp/src/program/vite/page.ts (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (5)
packages/taro-platform-harmony-cpp/src/program/vite/page.ts (5)

174-184: 正确处理了 tabbar 页面的配置索引

foreach 回调的修改正确地区分了 tabbar 页面和普通页面的处理逻辑,为每个 tab 页面维护独立的导航栏隐藏状态。


355-374: 正确实现了 tabbar 页面的索引访问

页面构建代码正确地使用了数组索引来访问 tabbar 页面的各个状态,包括 isReadynodenodeContent、背景色和 isHideTitleBar。这确保了每个 tab 页面能够独立管理自己的状态。

Also applies to: 395-406


413-445: Tabs 组件实现完善

新增的 Tabs 组件包装代码完整实现了 tabbar 页面的功能:

  • 正确使用 ForEach 渲染各个 tab 内容
  • onChange 事件恰当地处理了页面切换时的生命周期(onHide/onShow)
  • 考虑了底部安全区域的适配

456-473: handlePageAppear 正确处理了 tabbar 页面

方法修改正确地为 tabbar 页面使用了数组索引来访问 nodeContent 和设置 isReady 状态,确保每个 tab 页面的初始化独立进行。


504-506: 方法正确适配了 tabbar 页面

getNavHeighthandlePageDetach 方法都正确地使用了索引来访问 tabbar 页面的状态,确保了每个 tab 页面的独立性。

Also applies to: 513-516

Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.36%. Comparing base (0997d9e) to head (15519cd).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #17797    +/-   ##
========================================
  Coverage   59.36%   59.36%            
========================================
  Files         387      387            
  Lines       23420    23420            
  Branches     5166     5151    -15     
========================================
  Hits        13904    13904            
+ Misses       8149     8018   -131     
- Partials     1367     1498   +131     
Flag Coverage Δ
taro-cli 72.42% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ZakaryCode ZakaryCode marked this pull request as ready for review June 7, 2025 07:32
@coderabbitai coderabbitai bot requested a review from Single-Dancer June 7, 2025 07:33
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/taro-platform-harmony-cpp/src/program/vite/page.ts (1)

150-150: 修正 renderState 的第二个参数

这几处将 this.isTabbarPage 改为 false 可能是错误的。根据代码的其他部分,当页面是 tabbar 页面时,这些状态应该被渲染为数组形式。

建议恢复原有逻辑:

               this.renderState(
                 {
                   name: '__layoutSize',
                   type: 'TaroAny',
                   foreach: () => 'null',
                   disabled: !this.buildConfig.isBuildNativeComp && isPure,
                 },
-                false
+                this.isTabbarPage
               ),

areaChangeparams 的 renderState 调用也应做同样修改。

Also applies to: 158-158, 177-177

🧹 Nitpick comments (6)
packages/taro-platform-harmony-cpp/src/program/vite/style.ts (1)

55-67: 逻辑正确,但建议修复数组检查方式

多页面处理逻辑实现正确,为每个页面生成独立的样式导入和注册。但应使用 Array.isArray() 替代 instanceof Array

应用此修复:

-          if (page instanceof Array) {
+          if (Array.isArray(page)) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 55-55: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)

packages/taro-platform-harmony-cpp/src/program/vite/page.ts (5)

42-50: 修复数组检查方式

函数逻辑正确,但应使用 Array.isArray() 替代 instanceof Array

应用此修复:

-        if (page instanceof Array) return false
+        if (Array.isArray(page)) return false
🧰 Tools
🪛 Biome (1.9.4)

[error] 43-44: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


113-138: 多页面导入逻辑实现正确

正确处理单页面和多页面场景的路由名称和入口选项设置,但需要修复数组检查方式。

应用此修复:

-              if (page instanceof Array) {
+              if (Array.isArray(page)) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 125-125: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


293-299: 多页面初始化逻辑正确,但需修复数组检查

正确处理多页面的 EtsBuilder 初始化和页面名称设置,但应使用标准数组检查方法。

应用此修复:

-                ...(page instanceof Array ? [
+                ...(Array.isArray(page) ? [
🧰 Tools
🪛 Biome (1.9.4)

[error] 294-294: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


303-307: 样式表初始化逻辑正确,但需修复数组检查

多页面样式表初始化逻辑实现正确,为每个页面使用对应的 styleJson 索引。

应用此修复:

-                ...(page instanceof Array ? [
+                ...(Array.isArray(page) ? [
🧰 Tools
🪛 Biome (1.9.4)

[error] 304-304: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


338-350: 避免区域变化处理逻辑正确,但需修复数组检查

正确实现了 tabbar 页面的状态栏高度更新和环境规则更新逻辑。

应用此修复:

-                ...(page instanceof Array
+                ...(Array.isArray(page)
🧰 Tools
🪛 Biome (1.9.4)

[error] 340-340: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0670c4f and 15519cd.

📒 Files selected for processing (3)
  • packages/taro-platform-harmony-cpp/src/program/vite/page.ts (15 hunks)
  • packages/taro-platform-harmony-cpp/src/program/vite/render.ts (1 hunks)
  • packages/taro-platform-harmony-cpp/src/program/vite/style.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/taro-platform-harmony-cpp/src/program/vite/render.ts (1)
packages/taro-vite-runner/src/harmony/template/page.ts (1)
  • TaroHarmonyPageMeta (24-42)
🪛 Biome (1.9.4)
packages/taro-platform-harmony-cpp/src/program/vite/style.ts

[error] 55-55: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)

packages/taro-platform-harmony-cpp/src/program/vite/page.ts

[error] 43-44: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 125-125: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 294-294: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 304-304: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 340-340: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Testing on Rust
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (6)
packages/taro-platform-harmony-cpp/src/program/vite/render.ts (1)

89-89: 类型签名更新正确

page 参数类型更新为支持数组,与 TaroHarmonyPageMeta 接口定义保持一致,为 tabbar 多页面场景提供支持。

packages/taro-platform-harmony-cpp/src/program/vite/style.ts (1)

48-48: 类型签名更新正确

更新 page 参数类型以支持数组,与其他文件保持一致。

packages/taro-platform-harmony-cpp/src/program/vite/page.ts (4)

12-14: 新类型定义合理

添加 TCPageMeta 类型扩展 TPageMeta 并包含可选的 isPure 标志,有助于区分纯组件页面。


98-99: 类型签名更新正确

更新 modifyInstantiate 以支持页面数组,逻辑中正确检查非数组情况。


193-203: tabbar 页面状态处理逻辑正确

正确实现了 tabbar 页面的导航栏样式状态处理,根据页面索引动态获取配置。


447-479: tabbar 页面构建逻辑实现完整

正确实现了 tabbar 页面的 Tabs 组件包装,包含所有必要的配置项如位置、控制器、索引等,以及页面切换的生命周期处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: 使用taro4.1.1,init一个项目,编译出鸿蒙之后,在使用tabbar的情况下,鸿蒙无法编译,没有tabbar则正常
2 participants