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/backtop 适配 JDRN、鸿蒙端 #2374

Merged
merged 10 commits into from
Jul 22, 2024

Conversation

lyxuncle
Copy link

@lyxuncle lyxuncle commented Jun 20, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • BackTop 组件引入 scrollRes 属性,以支持 RN 和 HarmonyOS 平台的滚动事件处理。
    • 添加了 scrollToTop 功能,改进了返回顶部的体验。
    • 新增 Demo5 组件,实现可滚动视图和返回顶部功能。
  • 样式

    • 修改了 .nut-backtop.show.nut-backtop-rn,和 .nut-backtop-show.nut-backtop-show-active,改进视觉效果。
    • 调整了 border-radiusz-index 属性,以提升样式一致性。
  • 文档

    • 更新了英文、中文、繁体中文文档,详细说明了新增加的 scrollRes 属性及其用法。
  • 重构

    • 使用 useCallbackuseMemo 钩子来优化性能。
    • 重构了滚动逻辑和样式计算部分代码。

Copy link

coderabbitai bot commented Jun 20, 2024

Walkthrough

这些更改涉及多个文件,对 backtop 功能进行了全面的修改和增强。主要变更包括导入新的钩子、添加新的属性和方法、重构 CSS 样式、更新配置文件以及调整文档以支持 React Native 和 HarmonyOS。总的来说,这些更改旨在提高代码性能、增加功能和改善用户体验。

Changes

文件 修改摘要
packages/nutui-taro-demo-rn/scripts/taro/adapted.js 添加 backtop 到导出的实体列表中
packages/nutui-taro-demo-rn/src/nav/pages/backtop/index.config.ts 修改导航栏标题文本,从 BackTop 改为 Backtop
packages/nutui-taro-demo-rn/src/nav/pages/backtop/index.tsx 替换默认出口按钮,导入并导出 Demo
src/config.json BackTop 包版本从 2.0.0 升级到 3.0.0
src/packages/backtop/backtop.harmony.css 修改和重命名 CSS 选择器,调整样式属性
src/packages/backtop/backtop.scss 添加和修改 CSS 选择器和样式,调整边框半径,新样式状态
src/packages/backtop/backtop.taro.tsx 增加新钩子、属性和方法,重构滚动逻辑和样式计算
src/packages/backtop/backtop.tsx 引入 useCallbackuseMemo 钩子,更新事件监听处理
src/packages/backtop/demo.taro.tsx 基于不同平台条件渲染 Demo5Demo1
src/packages/backtop/demo5.tsx 新增文件,引入带有滚动事件处理的组件 Demo5
src/packages/backtop/doc.*.md 为 RN 和 HarmonyOS 使用添加指导,新增 scrollRes 属性

代码新气象,功能更强盛,
回顶按钮跃然生,
钩子相伴,属性齐全,
滚动流畅,用户欢,
文档指引清晰展,
优化之路快乐行。
🐇✨


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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: 5

Outside diff range and nitpick comments (2)
src/packages/backtop/backtop.tsx (2)

Line range hint 58-69: 对于scrollListener函数的实现,你已经使用了useCallback来包裹,这是一个好的实践,可以避免不必要的重渲染。不过,此函数依赖于threshold变量,但是没有包括scrollElSetScrollTop,这可能会导致在这些依赖变化时,回调不会更新。

-  }, [threshold])
+  }, [threshold, scrollEl, SetScrollTop])

Line range hint 146-158: 对于可点击的元素,应该同时提供键盘事件处理函数,以支持键盘导航。这是为了增强应用的无障碍性(a11y)。建议添加相应的键盘事件处理逻辑。

+  onKeyUp={(e) => {
+    if (e.key === 'Enter') {
+      goTop(e)
+    }
+  }}

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 (1)
src/packages/backtop/backtop.tsx (1)

Line range hint 146-158: 建议增加键盘事件以提高可访问性。

当前组件在点击事件上触发动作,但为了支持键盘导航,建议添加键盘事件处理。

+ onKeyUp={(e) => {
+   if (e.key === 'Enter') goTop(e);
+ }}

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

28-31: 添加对scrollRes属性的文档说明

虽然代码中添加了对scrollRes属性的注释,但建议进一步完善文档,说明其使用场景和值的具体含义,以提高代码的可读性和易用性。

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: 4

@@ -52,6 +62,7 @@ import { BackTop } from '@nutui/nutui-react-taro'
| threshold | 页面垂直滚动多高后出现 | `number` | `200` |
| zIndex | 设置组件页面层级 | `number` | `900` |
| duration | 设置动画持续时间,为 0 时表示无动画 | `number` | `1000` |
| scrollRes | 被监听容器滚动时的回调参数,主要用于 rn、鸿蒙端 | `PageScrollObejct` | `-` |
Copy link

Choose a reason for hiding this comment

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

修正拼写错误:PageScrollObejct

scrollRes 属性的类型拼写错误,应为 PageScrollObject

- | scrollRes | 被监听容器滚动时的回调参数,主要用于 rn、鸿蒙端 | `PageScrollObejct` | `-` |
+ | scrollRes | 被监听容器滚动时的回调参数,主要用于 rn、鸿蒙端 | `PageScrollObject` | `-` |
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| scrollRes | 被监听容器滚动时的回调参数,主要用于 rn、鸿蒙端 | `PageScrollObejct` | `-` |
| scrollRes | 被监听容器滚动时的回调参数,主要用于 rn、鸿蒙端 | `PageScrollObject` | `-` |

@@ -62,6 +72,7 @@ import { BackTop } from '@nutui/nutui-react';
| threshold | 頁面垂直滾動多高後出現 | `number` | `200` |
| zIndex | 設置組件頁面層級 | `number` | `900` |
| duration | 設置動畫持續時間,為 0 時表示無動畫 | `number` | `1000` |
| scrollRes | 被監聽容器滾動時的回調參數,主要用於 RN、鴻蒙端 | `PageScrollObejct` | `-` |
Copy link

Choose a reason for hiding this comment

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

修正拼写错误:PageScrollObejct

scrollRes 属性的类型拼写错误,应为 PageScrollObject

- | scrollRes | 被監聽容器滾動時的回調參數,主要用於 RN、鴻蒙端 | `PageScrollObejct` | `-` |
+ | scrollRes | 被監聽容器滾動時的回調參數,主要用於 RN、鴻蒙端 | `PageScrollObject` | `-` |
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| scrollRes | 被監聽容器滾動時的回調參數,主要用於 RN、鴻蒙端 | `PageScrollObejct` | `-` |
| scrollRes | 被監聽容器滾動時的回調參數,主要用於 RN、鴻蒙端 | `PageScrollObject` | `-` |

@@ -62,6 +72,7 @@ import { BackTop } from '@nutui/nutui-react';
| threshold | How high to scroll the page vertically | `number` | `200` |
| zIndex | Set the component z-index | `number` | `900` |
| duration | Set animation duration | `number` | `1000` |
| scrollRes | Callback parameters of a ScrollView listener, mainly used for RN and HarmonyOS | `PageScrollObejct` | `-` |
Copy link

Choose a reason for hiding this comment

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

修正拼写错误:PageScrollObejct

scrollRes 属性的类型拼写错误,应为 PageScrollObject

- | scrollRes | Callback parameters of a ScrollView listener, mainly used for RN and HarmonyOS | `PageScrollObejct` | `-` |
+ | scrollRes | Callback parameters of a ScrollView listener, mainly used for RN and HarmonyOS | `PageScrollObject` | `-` |
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| scrollRes | Callback parameters of a ScrollView listener, mainly used for RN and HarmonyOS | `PageScrollObejct` | `-` |
| scrollRes | Callback parameters of a ScrollView listener, mainly used for RN and HarmonyOS | `PageScrollObject` | `-` |

Comment on lines +55 to +57
### RN, HarmonyOS version usage

Due to the lack of support for fixed positioning, it needs to be used in conjunction with ScrollView.
Copy link

Choose a reason for hiding this comment

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

简化措辞:in conjunction with

为了提高可读性,可以将 "in conjunction with" 简化为 "with"。

- Due to the lack of support for fixed positioning, it needs to be used in conjunction with ScrollView.
+ Due to the lack of support for fixed positioning, it needs to be used with ScrollView.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### RN, HarmonyOS version usage
Due to the lack of support for fixed positioning, it needs to be used in conjunction with ScrollView.
### RN, HarmonyOS version usage
Due to the lack of support for fixed positioning, it needs to be used with ScrollView.
Tools
LanguageTool

[style] ~57-~57: ‘in conjunction with’ might be wordy. Consider a shorter alternative.
Context: ... fixed positioning, it needs to be used in conjunction with ScrollView. :::demo <CodeBlock src='t...

(EN_WORDINESS_PREMIUM_IN_CONJUNCTION_WITH)

@xiaoyatong xiaoyatong merged commit cf4e118 into jdf2e:dev-harmony Jul 22, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants