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

fix(backtop): 恢复icon #2724

Merged
merged 2 commits into from
Nov 12, 2024
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Nov 10, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了 BackTopDemo 组件的布局和结构,提升了可读性。
    • Demo1 组件中替换了图标,使用了新的 Top 组件。
    • 简化了 Demo5 组件的属性,增强了静态头部和列表的呈现。
  • 样式

    • 改进了 ScrollView 组件的样式,支持动态类名。

Copy link

coderabbitai bot commented Nov 10, 2024

Walkthrough

该拉取请求对 BackTopDemoDemo1Demo5 组件进行了修改。主要更改包括调整 JSX 结构、更新图标组件以及简化组件的属性和渲染逻辑。BackTopDemo 组件的布局更清晰,Demo1 组件移除了不再使用的 Icon 组件并引入了 Top 组件,而 Demo5 组件则简化了其属性并更新了图标的使用。整体上,组件的结构更加简洁,渲染逻辑更为直观。

Changes

文件路径 更改摘要
src/packages/backtop/demo.taro.tsx 修改 BackTopDemo 组件,调整 JSX 结构,使用 React 片段,更新条件渲染逻辑,简化布局。
src/packages/backtop/demos/taro/demo1.tsx 移除 Icon 组件的导入,添加 Top 组件,更新 BackTop 组件的渲染逻辑。
src/packages/backtop/demos/taro/demo5.tsx 移除 children 属性,更新导入,使用 Top 组件替换 Icon,简化组件结构,动态更新 ScrollView 的类名。

Possibly related PRs

Suggested labels

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.

@github-actions github-actions bot added the 3.x label Nov 10, 2024
Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (d92c50a) to head (b63e1c0).
Report is 11 commits behind head on V3.0.

Additional details and impacted files
@@           Coverage Diff           @@
##             V3.0    #2724   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         221      221           
  Lines       17867    17867           
  Branches     2676     2676           
=======================================
  Hits        15005    15005           
  Misses       2857     2857           
  Partials        5        5           

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

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

Line range hint 1-31: 建议优化组件的类型定义

虽然组件功能正常,但建议添加 TypeScript 接口定义来提高代码的可维护性。

建议添加以下类型定义:

interface Demo1Props {}

const Demo1: React.FC<Demo1Props> = () => {
  // ... 现有实现
}
src/packages/backtop/demo.taro.tsx (1)

28-48: 代码结构优化建议

当前的条件渲染逻辑使用了嵌套的 React.Fragment,可以进一步简化:

-    <>
      {harmonyAndRn() ? (
-        <>
          <View style={{ position: 'relative' }}>
            <Header />
            <Demo5 />
          </View>
-        </>
      ) : (
-        <>
          <Header />
          <ScrollView
            className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}
            style={demoStyle}
          >
            <View className="h2">{translated.title}</View>
            <Demo1 />
          </ScrollView>
-        </>
      )}
-    </>
+    {harmonyAndRn() ? (
+      <View style={{ position: 'relative' }}>
+        <Header />
+        <Demo5 />
+      </View>
+    ) : (
+      <>
+        <Header />
+        <ScrollView
+          className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}
+          style={demoStyle}
+        >
+          <View className="h2">{translated.title}</View>
+          <Demo1 />
+        </ScrollView>
+      </>
+    )}
src/packages/backtop/demos/taro/demo5.tsx (2)

32-34: ScrollView 的类名处理可以优化

当前实现正确,但可以考虑将环境判断逻辑提取为一个可复用的工具函数。

建议添加如下工具函数:

const isWebEnv = () => Taro.getEnv() === 'WEB'

然后这样使用:

-className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}
+className={`demo ${isWebEnv() ? 'web' : ''}`}

62-62: 图标大小建议使用主题变量

当前硬编码的图标大小值(12)建议改用主题变量以提高可维护性。

建议将图标大小定义为主题变量:

-<Top size={12} />
+<Top size={theme.iconSizeSmall} />

需要在文件顶部添加:

import { useTheme } from '@nutui/nutui-react-taro'

然后在组件内部:

const theme = useTheme()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d92c50a and b63e1c0.

📒 Files selected for processing (3)
  • src/packages/backtop/demo.taro.tsx (1 hunks)
  • src/packages/backtop/demos/taro/demo1.tsx (2 hunks)
  • src/packages/backtop/demos/taro/demo5.tsx (3 hunks)
🔇 Additional comments (7)
src/packages/backtop/demos/taro/demo1.tsx (2)

2-2: 导入声明更新正确!

移除了 @tarojs/componentsIcon 导入,改用 @nutui/icons-react-taroTop 组件,这样的改动更符合 NutUI React 的设计规范。

Also applies to: 4-4


26-26: 图标组件替换合理!

使用 Top 组件替代原来的 Icon 组件,并设置了合适的尺寸(size={12}),使其与文字"顶部"搭配得当。

✅ Verification successful

图标组件使用统一且合理!

验证显示所有 demo 文件(demo1、demo3、demo4、demo5)都统一使用了 Top 组件,并且都采用了相同的尺寸设置(size={12}),与"顶部"文字搭配统一。这种一致性的实现确保了良好的用户体验。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证其他 demo 文件中是否也进行了类似的图标替换
# 预期:其他 demo 文件应该也采用了相同的 Top 组件

# 检查其他 demo 文件中的图标使用情况
fd --type f "demo.*\.tsx$" "src/packages/backtop" --exec rg -l "Top.*size="

Length of output: 243


Script:

#!/bin/bash
# 检查这些文件中 Top 组件的具体使用情况
rg -U "Top.*size=" src/packages/backtop/demos/taro/demo*.tsx -B 2 -A 2

Length of output: 1539

src/packages/backtop/demo.taro.tsx (3)

23-23: 请验证高度样式更改的影响

将 height 从 '100%' 更改为 'auto' 可能会影响组件的滚动行为。建议验证在不同设备和屏幕尺寸下的显示效果。

#!/bin/bash
# 检查其他文件中是否有依赖固定高度的样式或逻辑
rg -g '*.{less,scss,css}' -A 3 'demo\s*{[^}]*height'

39-45: 检查滚动视图的事件处理

在非 harmony/RN 环境下使用了 ScrollView,建议确保相关的滚动事件和回到顶部功能正常工作。

#!/bin/bash
# 检查 Demo1 组件中的滚动相关代码
ast-grep --pattern 'onScroll|scrollTo|scrollTop'

30-34: 建议验证 Demo5 组件在 harmony/RN 环境下的兼容性

由于在 harmony/RN 环境下使用了不同的渲染逻辑,建议确保 Demo5 组件在这些平台上能正常工作。

✅ Verification successful

从搜索结果来看,我可以得出以下结论:

  1. BackTop组件已经针对 harmony/RN 环境做了特殊处理和适配:
  • 有专门的 backtop.taro.tsx 实现
  • 使用了 harmonyAndRn()rn() 工具函数判断平台
  • 有特定的 RN 样式类 .nut-backtop-rn
  • 提供了 scrollRes 参数专门用于 RN 和鸿蒙端的滚动处理
  1. Demo5 组件也做了相应适配:
  • 使用了 harmonyAndRn() 进行平台判断
  • 针对不同平台提供了不同的实现

因此可以确定 Demo5 组件在 harmony/RN 环境下是兼容的。

Demo5 组件已经做好了跨平台适配,无需额外验证

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 Demo5 组件是否有特定于平台的代码
rg -g '*/demo5.{tsx,jsx}' -A 5 'Platform|harmony|rn'

Length of output: 200


Script:

#!/bin/bash
# 搜索 Demo5 组件的定义和实现
fd -e tsx -e jsx -e ts -e js demo5 --exec cat {}

# 搜索 backtop 包中的平台特定代码
rg -g 'src/packages/backtop/*' 'Platform|harmony|rn'

# 检查是否存在平台特定的样式或组件
ast-grep --pattern 'Platform.select|Platform.OS'

Length of output: 103316

src/packages/backtop/demos/taro/demo5.tsx (2)

5-8: 导入声明和组件签名的更改看起来不错!

导入声明的更改符合组件的新实现需求,组件签名的简化也使代码更加清晰。

Also applies to: 12-12


35-38: 内容结构实现清晰简洁!

使用数组方法生成测试数据的方式非常优雅,代码易于理解和维护。

@oasis-cloud oasis-cloud merged commit 304fd2f into jdf2e:V3.0 Nov 12, 2024
6 checks passed
This was referenced Nov 12, 2024
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