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

refactor(fixednav): support harmony #3095

Merged
merged 3 commits into from
Mar 19, 2025

Conversation

irisSong
Copy link
Collaborator

@irisSong irisSong commented Mar 18, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • New Features

    • 新增对右到左文本方向的支持,以及根据平台条件优化组件的展示逻辑。
  • Refactor

    • 改进了导航组件的定位方式,实现了动态计算展示位置,确保在不同场景下表现更符合预期。
  • Style

    • 优化了导航组件的整体样式和排版,调整了左右对齐效果和图标显示,提升了跨平台的一致性和视觉效果。

Sorry, something went wrong.

Copy link

coderabbitai bot commented Mar 18, 2025

Walkthrough

此次提交主要针对 FixedNav 组件及其相关示例、测试、样式文件和组件文件进行了多处更新。配置文件中将 "dd" 属性值从 false 修改为 true;测试文件中更新了类名前缀的断言;示例文件中引入了 harmonypxTransform 功能,通过条件渲染和动态样式调整优化了不同平台的适配;样式文件统一了类名命名规则;组件文件中调整了图片渲染和类名生成逻辑,确保组件在 Taro 与 React 环境下均能正常工作。

Changes

文件 变更摘要
src/config.json 将 FixedNav 组件的 "dd" 属性值从 false 改为 true
src/packages/fixednav/__tests__/fixednav.spec.tsx 更新测试中 FixedNav 组件的类名断言(如 rightnut-fixednav-rightleftnut-fixednav-left)。
src/packages/fixednav/demo.taro.tsx 新增对 harmony 的导入,并使用条件渲染在 harmony() 返回值为 true 时不渲染 Demo5。
src/packages/fixednav/demos/h5/demo5.tsx 引入 useRtl 钩子,根据文本方向决定 Drag 组件样式中 leftright 属性的设置。
src/packages/fixednav/demos/taro/demo1.tsx, demo2.tsx, demo3.tsx, demo4.tsx 新增 pxTransform 导入并替换静态的 top 位移值;demo4 中替换 <span><Text> 以及 <ul><View>,实现动态列表生成。
src/packages/fixednav/fixednav.scss 更新样式规则,去除直接设置 right 属性,统一使用 nut-fixednav-left/right 和新增 nut-fixednav-image 类,调整按钮与列表的样式。
src/packages/fixednav/fixednav.taro.tsx, fixednav.tsx 调整组件中类名生成逻辑(由 type 变为模板字符串 ${classPrefix}-${type}),同时更新图标渲染:Taro 文件采用 <Image> 替换 <img>,React 文件为 <img> 增加指定 className

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Demo as FixedNavDemo
    participant Harmony as harmony()
    participant Comp as Demo5 Component

    Demo->>Harmony: 调用 harmony()
    alt harmony 返回 true
        Harmony-->>Demo: 返回 true
        Demo->>Demo: 不渲染 Demo5(返回 null)
    else harmony 返回 false
        Harmony-->>Demo: 返回 false
        Demo->>Comp: 渲染 Demo5 组件
    end

Possibly related PRs

Suggested reviewers

  • xiaoyatong
  • oasis-cloud

Poem

我是一只小兔子,跳跃在代码林间,
FixedNav的新貌,变更悄然绽放灿然。
条件逻辑细如丝,样式清晰映晨曦,
每行代码皆跳跃,见证着创新的奇迹。
欢快似春风拂面,这变更载着梦想飞扬!
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ 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.
    • 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.
  • @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.

Sorry, something went wrong.

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) labels Mar 18, 2025
@irisSong irisSong changed the title fix(fixednav): harmony refactor(fixednav): support harmony Mar 18, 2025
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.48%. Comparing base (3fd5483) to head (aa5fcc5).
Report is 2 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3095   +/-   ##
==========================================
  Coverage      86.48%   86.48%           
==========================================
  Files            280      280           
  Lines          18489    18489           
  Branches        2774     2774           
==========================================
  Hits           15991    15991           
  Misses          2493     2493           
  Partials           5        5           

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

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

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 (1)
src/packages/fixednav/demos/taro/demo2.tsx (1)

40-49: 使用 pxTransform 函数替代硬编码像素值并简化 JSX 结构

将硬编码的像素值 '140px' 替换为 pxTransform(140) 函数调用有助于组件在不同设备上的适配。此外,移除了不必要的 Fragment 包装,使代码结构更加简洁明了。

建议:为了提高代码的可读性和一致性,可以考虑将类似的 pxTransform 转换应用到其他硬编码的像素值,如 Badge 组件的 top 和 right 属性等。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3fd5483 and a2ac78b.

📒 Files selected for processing (11)
  • src/config.json (1 hunks)
  • src/packages/fixednav/__tests__/fixednav.spec.tsx (1 hunks)
  • src/packages/fixednav/demo.taro.tsx (2 hunks)
  • src/packages/fixednav/demos/h5/demo5.tsx (2 hunks)
  • src/packages/fixednav/demos/taro/demo1.tsx (2 hunks)
  • src/packages/fixednav/demos/taro/demo2.tsx (2 hunks)
  • src/packages/fixednav/demos/taro/demo3.tsx (2 hunks)
  • src/packages/fixednav/demos/taro/demo4.tsx (2 hunks)
  • src/packages/fixednav/fixednav.scss (3 hunks)
  • src/packages/fixednav/fixednav.taro.tsx (3 hunks)
  • src/packages/fixednav/fixednav.tsx (2 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
src/packages/fixednav/demos/taro/demo3.tsx (6)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
src/packages/fixednav/demos/taro/demo2.tsx (2)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
src/packages/fixednav/demos/taro/demo1.tsx (4)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
src/packages/fixednav/fixednav.taro.tsx (1) (1)
  • FixedNav (27:128)
src/packages/fixednav/fixednav.tsx (1) (1)
  • FixedNav (26:129)
🔇 Additional comments (29)
src/config.json (1)

333-333: 配置更新符合组件系统化要求

将 FixedNav 组件的 "dd" 属性从 false 更改为 true,这样可以确保组件遵循设计系统的一致性规范。这种变更对于保持组件库的整体一致性至关重要。

src/packages/fixednav/demos/h5/demo5.tsx (3)

2-2: 适当引入 useRtl 增强国际化支持

从 @nutui/nutui-react 中导入 useRtl 钩子,为组件增加了从右到左(RTL)文本方向的支持,提升了组件的国际化能力。


5-5: 良好使用 useRtl 钩子

通过调用 useRtl() 钩子获取当前文本方向,为后续样式条件渲染提供了基础。


41-47: 优雅处理 RTL 布局适配

根据 rtl 值动态设置组件位置,如果是 RTL 模式则靠左显示,否则靠右显示,确保了在不同文本方向下的正确展示。这种条件渲染方式简洁高效。

src/packages/fixednav/demos/taro/demo1.tsx (2)

3-3: 引入像素转换工具提高适配性

添加 pxTransform 工具函数的导入,为后续适配不同设备像素密度做准备。


40-48: 使用 pxTransform 优化位置适配

将固定的像素值 '70px' 替换为 pxTransform(70),使组件在不同设备像素密度下保持一致的视觉效果,增强了组件的跨设备适配能力。

src/packages/fixednav/demo.taro.tsx (2)

4-4: 引入平台检测工具增强兼容性

从 @/utils/platform-taro 导入 harmony 函数,用于检测当前运行环境是否为鸿蒙系统,为后续的条件渲染提供支持。


21-22: 适当处理鸿蒙系统兼容性

基于 harmony() 的检测结果进行条件渲染,在鸿蒙系统环境下不显示 Demo5 组件,有效避免了不支持的功能在特定环境中导致的问题。注释清晰地说明了原因:鸿蒙系统暂不支持拖拽功能。

src/packages/fixednav/fixednav.taro.tsx (3)

4-4: 导入 Taro 组件库中的 Image 组件以支持跨平台图片渲染

引入 @tarojs/components 中的 Image 组件是合理的改进,这将使组件在 Taro 环境中能够正确渲染图片元素,提高了组件在小程序平台的兼容性。


58-58: 优化了类名生成逻辑,增强了可维护性

将类名从直接使用 type 更改为使用模板字符串 ${classPrefix}-${type} 是一个很好的改进。这种方式生成的类名更加规范和一致,有利于样式隔离和防止样式冲突。


72-72: 使用 Taro 专用 Image 组件替换 HTML img 标签

将 HTML img 标签替换为 Taro 专用的 Image 组件是必要的更改,这确保了组件在小程序环境中能够正常工作,同时保持了与 React 版本相同的功能。

src/packages/fixednav/__tests__/fixednav.spec.tsx (2)

33-35: 更新测试用例以匹配新的类名命名规则

测试断言已正确更新,从检查 right 类改为检查完整的类名 nut-fixednav-right,这与组件代码中类名生成逻辑的变更保持一致。


40-42: 更新左侧导航测试断言以匹配新的类名命名规则

测试断言已正确更新,从检查 left 类改为检查完整的类名 nut-fixednav-left,确保测试用例与更新后的组件行为一致。

src/packages/fixednav/demos/taro/demo3.tsx (2)

3-3: 引入 pxTransform 工具函数优化像素单位转换

添加 pxTransform 工具函数的导入是一个很好的做法,它能帮助在不同屏幕密度的设备上实现一致的视觉效果,提高了组件在多平台环境下的适配能力。


40-47: 使用 pxTransform 函数替代硬编码像素值并简化 JSX 结构

将硬编码的像素值 '210px' 替换为 pxTransform(210) 函数调用是一个很好的改进,这样可以确保在不同设备上显示的一致性。同时,移除了不必要的 Fragment 包装,使代码更加简洁。

src/packages/fixednav/demos/taro/demo2.tsx (1)

3-3: 引入 pxTransform 工具函数优化像素单位转换

添加 pxTransform 工具函数的导入是一个很好的做法,它能帮助在不同屏幕密度的设备上实现一致的视觉效果,提高了组件在多平台环境下的适配能力。

src/packages/fixednav/fixednav.tsx (2)

58-58: 改进了类名生成逻辑

使用模板字符串 ${classPrefix}-${type} 替代直接使用 type 更为规范,保证了类名的命名空间隔离,增强了样式选择器的特异性,避免与其他组件样式冲突。


72-72: 为图片添加了专用类名

为图片元素添加 ${classPrefix}-list-image 类名是一个良好的实践,便于统一管理图片样式,提高了组件的可维护性和样式的可预测性。

src/packages/fixednav/demos/taro/demo4.tsx (4)

4-5: 导入Taro组件和工具函数

引入 Taro 的 ViewText 组件以及 pxTransform 工具函数,有助于提升组件在 Taro 环境下的兼容性和一致性。


21-21: 使用 pxTransform 替换硬编码像素值

使用 pxTransform(280) 代替硬编码的像素值 '280px' 是一个很好的改进,这样可以确保组件在不同设备和分辨率下有一致的显示效果。


29-29: 使用 Taro 的 Text 组件代替 span

将 HTML 的 span 元素替换为 Taro 的 Text 组件,符合 Taro 跨平台开发的最佳实践,提高了组件的平台兼容性。


33-41: 优化列表渲染结构

使用 Taro 的 View 组件和 map 方法动态渲染列表项,增加了 key 属性以提高列表渲染性能,符合 React 的最佳实践。

src/packages/fixednav/fixednav.scss (7)

21-25: 优化活动状态下左侧导航的样式

为活动状态下的左侧导航添加了特定的类名和图标旋转样式,使得左右布局的样式结构更加统一和可预测。


81-85: 添加了图片专用样式类

新增 &-list-image 类,统一设置了图片的尺寸和边距,使样式结构更加清晰,便于维护。


88-107: 规范化右侧导航样式

创建了完整的 &-right 样式类,明确设置了右侧定位、边框半径和内边距,确保了样式的一致性和可预测性。


109-110: 规范化左侧导航样式

使用 &-left 样式类并明确设置 left: 0,与右侧导航结构对称,提高了代码的可读性和一致性。


117-117: 调整图标旋转角度

明确设置图标的旋转角度为 180 度,确保在不同导航状态下图标的显示效果一致。


135-147: 完善RTL布局支持

优化了右到左(RTL)布局下的导航样式,包括位置调整和图标旋转逻辑,提高了组件的国际化支持能力。


181-208: 完善RTL布局下的左侧导航样式

在RTL环境下调整了左侧导航的位置、边框和内边距,确保了组件在不同文字方向下的正确显示。

@oasis-cloud oasis-cloud merged commit 72d74c0 into jdf2e:feat_v3.x Mar 19, 2025
8 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 action:review This PR needs more reviews (less than 2 approvals) size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants