Skip to content
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

perf: 优化渲染节点 #2967

Merged
merged 3 commits into from
Feb 7, 2025
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Feb 6, 2025

🤔 这个变动的性质是?

1)优化了渲染节点
2)简化判断逻辑
3)修订函数名
4)合并样式代码

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 重构

    • 优化了徽章显示逻辑,确保数值和标记在符合条件时准确展现。
    • 集中调整了标签项标题的渲染方式,以实现一致而可靠的显示效果。
  • 样式

    • 简化了标签栏活动项的样式设置,使整体视觉效果更清晰、统一。

Copy link

coderabbitai bot commented Feb 6, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • src/packages/tabbar/__tests__/__snapshots__/tabbar.spec.tsx.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

本次更新主要对 Badge 与 TabbarItem 组件进行了逻辑和样式上的优化。Badge 组件中重命名并简化了处理 value 属性的逻辑,同时优化了定位样式的计算。TabbarItem 组件则新增了 renderTitleText 函数,用于统一和简化标题文本的渲染。此外,样式文件中对图标样式的嵌套规则进行了调整,简化了结构,保持了原有的视觉效果。

Changes

文件 变更概要
src/packages/badge/badge.taro.tsx
src/packages/badge/badge.tsx
重命名 contentgetContent,简化 value 属性判断逻辑;重构 getPositionStyle 函数以提高可读性;更新条件渲染逻辑,确保仅在合适条件下渲染。
src/packages/tabbaritem/tabbaritem.scss 调整 .nut-tabbar-item-active.nut-icon 选择器的规则,合并嵌套结构,并保留颜色逻辑。
src/packages/tabbaritem/tabbaritem.taro.tsx
src/packages/tabbaritem/tabbaritem.tsx
新增 renderTitleText 函数封装标题文本渲染逻辑,替换原有的内联渲染方式以统一组件标题处理。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant B as Badge组件
    participant GC as getContent
    participant PS as getPositionStyle

    U->>B: 渲染Badge组件
    B->>GC: 调用getContent获取内容
    GC-->>B: 返回处理后的内容
    B->>PS: 获取定位样式
    PS-->>B: 返回样式对象
    alt 内容有效或dot为true
        B->>B: 渲染内容与样式
    else
        B->>B: 不渲染内容
    end
Loading
sequenceDiagram
    participant U as 用户
    participant T as TabbarItem组件
    participant RTT as renderTitleText

    U->>T: 渲染TabbarItem组件
    T->>RTT: 调用renderTitleText获取标题
    RTT-->>T: 返回标题视图(如存在)
    T->>T: 根据图标与标题渲染组件
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud
  • Alex-huxiyang

Poem

我是一只快乐的小兔子,
蹦跶中轻唱新代码的诗,
Badge 内容显得更加明晰,
Tabbar标题闪耀着星辉,
欢庆变革,代码世界多美丽!
🐰💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@github-actions github-actions bot added the 3.x Target branch 3.x label Feb 6, 2025
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

🧹 Nitpick comments (2)
src/packages/tabbaritem/tabbaritem.tsx (1)

72-74: 提取标题渲染逻辑到独立函数

将标题渲染逻辑提取到独立函数可以提高代码的可维护性和复用性。

不过建议添加函数注释来说明其用途:

+  // 渲染标题文本,当title存在时返回带样式的div
   const renderTitleText = () => {
     return title && <div className={titleClass}>{title}</div>
   }
src/packages/tabbaritem/tabbaritem.taro.tsx (1)

74-87: Taro版本的标题渲染逻辑优化

将标题渲染逻辑提取为独立函数,并正确处理了Taro环境下的组件和样式。建议进行以下优化:

  1. 添加函数注释
  2. 考虑将样式对象提取到函数外部以避免重复创建
+  // 渲染标题文本,处理Taro环境下的组件和激活状态样式
+  const titleStyle = {
+    color: active ? ctx?.activeColor : ctx?.inactiveColor,
+  }
   const renderTitleText = () => {
     return (
       title && (
         <View
           className={titleClass}
-          style={{
-            color: active ? ctx?.activeColor : ctx?.inactiveColor,
-          }}
+          style={titleStyle}
         >
           {title}
         </View>
       )
     )
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c2b21ba and f80b078.

📒 Files selected for processing (5)
  • src/packages/badge/badge.taro.tsx (4 hunks)
  • src/packages/badge/badge.tsx (4 hunks)
  • src/packages/tabbaritem/tabbaritem.scss (1 hunks)
  • src/packages/tabbaritem/tabbaritem.taro.tsx (2 hunks)
  • src/packages/tabbaritem/tabbaritem.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (11)
src/packages/tabbaritem/tabbaritem.scss (1)

46-54: 代码简化与样式统一

此次修改通过合并 .nut-tabbar-item-icon-box.nut-icon 的样式规则,在激活状态下统一设置了颜色,既保留了条件预处理指令下的逻辑,又简化了嵌套结构。请确认合并后的规则对所有场景(包括非激活状态)不会引入意外副作用。

src/packages/tabbaritem/tabbaritem.tsx (1)

91-91: 优化了标题渲染的代码结构

通过调用 renderTitleText() 函数替代内联JSX,使代码更加清晰和统一。

Also applies to: 94-94

src/packages/tabbaritem/tabbaritem.taro.tsx (1)

109-109: 统一使用renderTitleText函数渲染标题

代码结构清晰,保持了与非Taro版本的一致性。

Also applies to: 112-112

src/packages/badge/badge.tsx (4)

31-32: 函数重命名和逻辑优化值得肯定!

content 重命名为 getContent 更好地表达了函数的用途,同时简化了判断逻辑,使代码更加清晰和易于维护。

Also applies to: 36-42


60-60: 使用可选链操作符提高了代码的健壮性!

使用 ?. 操作符可以安全地处理 getContent() 可能返回 null 的情况,避免了潜在的运行时错误。


67-70: 样式计算函数重构得更加简洁!

getPositionStyle 重构为箭头函数并直接返回样式对象,同时添加了 CSSProperties 类型注解,使代码更加简洁且类型安全。


86-89: 渲染条件优化更加清晰!

通过 getContent() || dot 条件判断,使渲染逻辑更加明确,同时保持了与 dot 模式的兼容性。

src/packages/badge/badge.taro.tsx (4)

39-40: 保持了与 React 版本的一致性!

Taro 版本的改动与 React 版本保持一致,这种统一性有助于代码的维护和理解。

Also applies to: 47-53


71-71: 类名计算逻辑与 React 版本保持一致!

使用相同的 getContent() 函数和可选链操作符,确保了跨平台的一致性。


84-92: 样式计算函数优化同时保持了平台特性!

重构后的 getPositionStyle 函数不仅更加简洁,还保留了对鸿蒙系统的特殊处理,使用 pxTransform 确保正确的单位转换。


108-111: 渲染逻辑优化与 React 版本保持一致!

使用相同的条件判断逻辑,同时正确使用了 Taro 的 View 组件,确保了在小程序平台的正确渲染。

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.73%. Comparing base (c2b21ba) to head (3f7c730).
Report is 2 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #2967      +/-   ##
=============================================
- Coverage      85.74%   85.73%   -0.01%     
=============================================
  Files            277      277              
  Lines          18110    18105       -5     
  Branches        2745     2745              
=============================================
- Hits           15528    15523       -5     
  Misses          2577     2577              
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oasis-cloud oasis-cloud merged commit 61955b9 into jdf2e:feat_v3.x Feb 7, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants