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

feat(Tabbar): harmony adaptation #2783

Merged
merged 1 commit into from
Nov 21, 2024
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Nov 21, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了多个组件的版本,提升了整体配置结构。
    • 在TabbarItem组件中,图标和标题的颜色根据活动状态进行了调整,以增强视觉一致性。
  • 样式

    • 根据harmony功能标志,条件性地调整了TabbarItem的样式。
  • 文档

    • addColorForHarmony函数的参数更新为可选,允许在不提供颜色值的情况下调用。

Copy link

coderabbitai bot commented Nov 21, 2024

Walkthrough

此次更改主要集中在多个组件的版本更新和样式调整上。src/config.json 文件中,多个组件的版本从 2.0.0 更新至 3.0.0。此外,tabbaritem.scss 文件引入了条件样式,依据 harmony 特性标志调整颜色。tabbaritem.taro.tsx 文件中新增了对 addColorForHarmony 函数的引用,并更新了图标和标题的渲染逻辑。最后,add-color-for-harmony.ts 文件中,addColorForHarmony 函数的参数类型进行了修改,使颜色参数变为可选。

Changes

文件路径 更改摘要
src/config.json 多个组件版本从 2.0.0 更新至 3.0.0:Tabbar、CalendarCard、Checkbox、CheckboxGroup、Input、InputNumber、Radio、RadioGroup、Range、Rate、SearchBar、Switch、TextArea、Video、AnimatingNumbers、Avatar、CountDown、Indicator、Pagination、Price、Progress、Swiper、Tag。
src/packages/tabbaritem/tabbaritem.scss 根据 harmony 特性标志调整 .nut-tabbar-item-active 类的颜色样式。
src/packages/tabbaritem/tabbaritem.taro.tsx 新增对 addColorForHarmony 的导入,更新图标和标题的渲染逻辑以匹配活动状态的颜色。
src/utils/add-color-for-harmony.ts addColorForHarmony 函数的颜色参数从必需的字符串改为可选字符串。

Possibly related PRs

Suggested labels

size/L, 3.x

Suggested reviewers

  • oasis-cloud

🐰 在草地上跳跃,版本更新真欢快,
组件们一起换新装,颜色鲜亮如花。
代码变得更灵活,样式随心而变,
小兔子欢呼雀跃,感谢每一位开发者! 🌼


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 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.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (beb7be2) to head (6251618).
Report is 1 commits behind head on V3.0.

Additional details and impacted files
@@           Coverage Diff           @@
##             V3.0    #2783   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         220      220           
  Lines       17881    17881           
  Branches     2676     2676           
=======================================
  Hits        15018    15018           
  Misses       2858     2858           
  Partials        5        5           

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


🚨 Try these New Features:

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

🧹 Outside diff range and nitpick comments (4)
src/utils/add-color-for-harmony.ts (1)

14-14: 参数类型更改正确,但需要更新文档

color 参数设置为可选是一个很好的改进,增加了函数的灵活性。不过建议更新 JSDoc 文档以反映这个变化。

建议按如下方式更新文档:

 /**
  * 为支持 Harmony 的 React 元素添加颜色属性
  * @param maybeElement - 要处理的 React 节点
- * @param color - 要添加的颜色值(如:'#ff0000')
+ * @param color - [可选] 要添加的颜色值(如:'#ff0000')
  * @returns 处理后的 React 节点
  */
src/packages/tabbaritem/tabbaritem.scss (1)

53-58: 建议优化条件样式复用

图标的颜色设置逻辑与容器完全相同,建议考虑将重复的条件样式抽取为混入(mixin)以提高代码复用性。

建议添加以下混入:

@mixin harmony-color($color) {
  /* #ifdef harmony*/
  color: $color;
  /* #endif*/
  /* #ifndef harmony*/
  color: inherit;
  /* #endif*/
}

然后这样使用:

.nut-tabbar-item-icon-box {
-  /* #ifdef harmony*/
-  color: $tabbar-active-color;
-  /* #endif*/
-  /* #ifndef harmony*/
-  color: inherit;
-  /* #endif*/
+  @include harmony-color($tabbar-active-color);

  .nut-icon {
-    /* #ifdef harmony*/
-    color: $tabbar-active-color;
-    /* #endif*/
-    /* #ifndef harmony*/
-    color: inherit;
-    /* #endif*/
+    @include harmony-color($tabbar-active-color);
  }
}
src/packages/tabbaritem/tabbaritem.taro.tsx (1)

94-112: 建议重构重复的样式代码

标题样式对象在有图标和无图标的情况下都重复定义了。建议提取共用样式以提高代码复用性。

建议应用以下改进:

+ const titleStyle = {
+   color: active ? ctx?.activeColor : ctx?.inactiveColor,
+ }

  return (
    // ...
    {icon ? (
      <>
        <Badge {...badgeProps}>
          <View className={boxPrefix}>
            {addColorForHarmony(
              icon,
              active ? ctx?.activeColor : ctx?.inactiveColor
            )}
          </View>
        </Badge>
        <View
          className={titleClass}
-         style={{
-           color: active ? ctx?.activeColor : ctx?.inactiveColor,
-         }}
+         style={titleStyle}
        >
          {title}
        </View>
      </>
    ) : (
      <Badge {...badgeProps}>
        <View
          className={titleClass}
-         style={{
-           color: active ? ctx?.activeColor : ctx?.inactiveColor,
-         }}
+         style={titleStyle}
        >
          {title}
        </View>
      </Badge>
    )}
src/config.json (1)

Line range hint 356-367: 注意 Tabbar 与 TabbarItem 组件版本不一致的问题

父组件 Tabbar 升级到了 3.0.0 版本,但子组件 TabbarItem 仍然保持在 2.0.0 版本。这种版本不一致可能会导致兼容性问题。建议同步更新 TabbarItem 的版本。

   {
     "version": "3.0.0",
     "name": "Tabbar",
     ...
   },
   {
-    "version": "2.0.0",
+    "version": "3.0.0",
     "name": "TabbarItem",
     ...
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between beb7be2 and 6251618.

📒 Files selected for processing (4)
  • src/config.json (1 hunks)
  • src/packages/tabbaritem/tabbaritem.scss (1 hunks)
  • src/packages/tabbaritem/tabbaritem.taro.tsx (2 hunks)
  • src/utils/add-color-for-harmony.ts (1 hunks)
🔇 Additional comments (5)
src/utils/add-color-for-harmony.ts (1)

Line range hint 14-20: 验证函数使用情况

由于 color 参数类型发生变化,建议验证所有调用此函数的地方是否需要适配。

运行以下脚本来检查函数的使用情况:

✅ Verification successful

Let me analyze the usage patterns more deeply by checking the type information of the parameters being passed:


函数类型变更验证完成,现有使用方式符合新类型定义

经过验证,addColorForHarmony 函数在代码库中有3处调用,均位于组件库中:

  • src/packages/tabbaritem/tabbaritem.taro.tsx 中传递 icon 和条件颜色
  • src/packages/pagination/pagination.taro.tsx 中有两处调用,传递分页按钮内容和条件颜色

所有调用都符合新的类型定义:第一个参数为 ReactNode,第二个参数为可选的颜色字符串。现有代码不需要做任何适配修改。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 addColorForHarmony 函数的所有调用位置

# 搜索所有调用 addColorForHarmony 的地方
rg -A 2 "addColorForHarmony\(" 

# 检查是否有直接导入
rg "import.*addColorForHarmony.*from"

Length of output: 1395


Script:

#!/bin/bash
# Check the implementation of TabBarItem and Pagination components
ast-grep --pattern 'interface $_ {
  $$$
}'  src/packages/tabbaritem/tabbaritem.taro.tsx src/packages/pagination/pagination.taro.tsx

# Check the actual implementation context of addColorForHarmony calls
rg -B 5 -A 5 "addColorForHarmony\(" src/packages/tabbaritem/tabbaritem.taro.tsx src/packages/pagination/pagination.taro.tsx

Length of output: 2823

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

45-50: 条件样式实现正确

图标容器的颜色根据harmony平台进行了合理的条件判断,实现了在不同平台下的差异化样式控制。

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

7-7: 导入语句正确添加

新增的 addColorForHarmony 工具函数导入位置恰当,使用了 @/ 别名路径。


87-92: 建议验证颜色和谐性适配的实现

图标渲染逻辑已更新为使用 addColorForHarmony,请确认:

  1. 颜色适配是否符合鸿蒙设计规范
  2. 在不同状态下的颜色过渡是否平滑
✅ Verification successful

Let me check the implementation of addColorForHarmony function to better understand the color harmony logic.


Let me check the actual implementation of the addColorForHarmony function to understand its color handling logic.


Let me check the platform-specific harmony detection implementation.


颜色和谐性适配实现已验证完成

addColorForHarmony 函数实现符合预期:

  • 正确检测鸿蒙环境
  • 为鸿蒙设备上的图标组件添加适当的颜色属性
  • 在 TabBarItem 和 Pagination 等组件中得到一致应用
  • 保持了与其他平台的兼容性

颜色状态切换逻辑合理:

  • TabBarItem 在激活/未激活状态下使用上下文提供的对应颜色
  • Pagination 在可用/禁用状态下使用恰当的颜色对比
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他组件是否也使用了相同的颜色处理方式
ast-grep --pattern 'addColorForHarmony($_, $_)'

Length of output: 1065


Script:

#!/bin/bash
# Search for addColorForHarmony function implementation
ast-grep --pattern 'function addColorForHarmony($$$)'

# Also check for any color-related utility functions
ast-grep --pattern 'function $name($$$) {
  $$$
  color
  $$$
}'

# Search for color-related constants or configurations
rg -g '!*.{test,spec}.*' -i 'harmony.*color|color.*harmony'

Length of output: 2006


Script:

#!/bin/bash
# Get the content of add-color-for-harmony.ts
cat src/utils/add-color-for-harmony.ts

# Check for harmony detection utility
ast-grep --pattern 'function harmony($$$)'

Length of output: 655


Script:

#!/bin/bash
# Check the platform detection implementation
cat src/utils/platform-taro.ts

# Look for any harmony-related tests
rg -g '*.{test,spec}.*' 'harmony'

Length of output: 552

src/config.json (1)

Line range hint 356-367: 验证 Harmony 适配相关改动

根据 PR 的目标,这次改动是为了适配 Harmony。需要确保相关的样式和功能改动已经完全覆盖。

✅ Verification successful

Let me gather more specific information about the Harmony adaptations in the Tabbar component.


Harmony 适配已完成且实现正确

TabbarItem 组件已经完成了 Harmony 平台的适配:

  • 样式文件中包含了 Harmony 平台特定的条件样式处理
  • 使用了专门的 addColorForHarmony 工具函数来处理图标颜色
  • Taro 版本的实现中正确引用了 Harmony 相关的工具和适配逻辑
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 Tabbar 相关文件中的 Harmony 适配改动

# 搜索 Tabbar 相关文件中的 Harmony 适配代码
rg -l "harmony" --glob "src/packages/tabbar*"

# 检查样式文件中的条件样式
rg -l "harmony" --glob "*.scss"

Length of output: 482


Script:

#!/bin/bash
# 检查 Tabbar 组件相关文件的具体内容
rg -p "harmony" src/packages/tabbaritem/tabbaritem.scss

# 检查 Tabbar 组件的主要实现文件
fd "tabbar" src/packages -t f -E "*.test.*" -E "*.md" --exec cat {}

# 检查是否有 Harmony 相关的条件判断
rg -p "@supports\s+\(\s*-harmony" src/packages/tabbaritem/

Length of output: 18278


Script:

#!/bin/bash
# 检查 Harmony 相关的工具函数
cat src/utils/add-color-for-harmony.ts

# 检查其他可能的 Harmony 相关适配代码
rg -p "harmony" src/packages/tabbar/

Length of output: 647

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

Successfully merging this pull request may close these issues.

2 participants