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: add 1px tolerance for autoScroll #336

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

anzhou99
Copy link
Contributor

@anzhou99 anzhou99 commented Dec 11, 2024

修复:
BubbleList中autoScroll功能无法按预期运行的问题。

解决方案:
容忍1px以内的误差。

详见issue: #317

Summary by CodeRabbit

  • 新功能
    • 改进了滚动到底部的检测精度,提升用户体验。

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

📝 Walkthrough

Walkthrough

此次变更在 BubbleList 组件中引入了一个新的常量 TOLERANCE,其值设置为 1。该常量在 onInternalScroll 事件处理程序中使用,用于判断滚动位置是否到达列表底部。修改了设置 scrollReachEnd 状态的逻辑,从直接比较 scrollTopclientHeightscrollHeight,改为计算 scrollHeightscrollTopclientHeight 的绝对值之和的差值是否小于或等于 TOLERANCE。组件的整体结构和流程保持不变,未对组件的属性或外部接口进行修改。

Changes

文件路径 更改摘要
components/bubble/BubbleList.tsx 添加常量 TOLERANCE,并修改 onInternalScroll 事件处理逻辑以提高滚动到底部的检测精度。

Possibly related PRs

  • fix: attachment scrollX bug #295: 该PR与本PR均引入了一个名为 TOLERANCE 的常量,值为 1,并在各自的组件中利用该常量增强滚动状态检测逻辑(BubbleListFileList)。

Poem

在泡泡列表中,
新常量悄然生,
滚动到底部,
精确无比真。
小兔欢跳跃,
代码更灵活,
让我们一起庆祝这变化的美! 🐇✨


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

github-actions bot commented Dec 11, 2024

Preview is ready

Copy link

codecov bot commented Dec 11, 2024

Bundle Report

Bundle size has no change ✅

Copy link
Contributor

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

🧹 Outside diff range and nitpick comments (2)
components/bubble/BubbleList.tsx (2)

40-41: 建议为 TOLERANCE 常量添加注释说明

建议添加注释来解释这个容差值的用途和选择 1px 作为阈值的原因,这样可以帮助其他开发者更好地理解代码。

+// 滚动位置计算的容差值(像素),用于解决由于浮点数计算误差导致的自动滚动问题
const TOLERANCE = 1;

94-96: 滚动计算逻辑的改进建议

当前实现正确地解决了自动滚动的问题,使用 Math.abs 处理滚动值是个好做法。不过,为了提高代码的可读性,建议将计算逻辑提取为一个命名良好的变量。

+    const currentScrollDistance = target.scrollHeight - Math.abs(target.scrollTop) - target.clientHeight;
+    setScrollReachEnd(currentScrollDistance <= TOLERANCE);
-    setScrollReachEnd(
-      target.scrollHeight - Math.abs(target.scrollTop) - target.clientHeight <= TOLERANCE,
-    );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a6fb0b8 and 1edf278.

📒 Files selected for processing (1)
  • components/bubble/BubbleList.tsx (2 hunks)

Comment on lines +94 to +96
setScrollReachEnd(
target.scrollHeight - Math.abs(target.scrollTop) - target.clientHeight <= TOLERANCE,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

发现了不一致的滚动计算逻辑

在代码库中发现了两种不同的滚动位置计算实现:

  • components/bubble/BubbleList.tsx 使用 scrollHeight - Math.abs(scrollTop) - clientHeight <= TOLERANCE
  • components/attachments/FileList/index.tsx 使用 scrollHeight - clientHeight !== scrollTop

建议统一这两处实现的计算逻辑,以保持代码库的一致性:

  • FileList 组件中也建议使用 Math.abs(scrollTop) 来处理滚动位置
  • 考虑引入相同的 TOLERANCE 值来处理误差
🔗 Analysis chain

建议验证其他组件中的滚动计算逻辑

为了保持代码库的一致性,建议检查其他组件中是否存在类似的滚动位置计算逻辑,可能也需要应用相同的优化。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索代码库中其他可能需要类似优化的滚动位置计算
rg -l "scrollHeight.*scrollTop.*clientHeight" --type tsx --type jsx

# 查找其他可能的滚动到底部检测实现
ast-grep --pattern 'scrollHeight - $_ <= $_'

Length of output: 144


Script:

#!/bin/bash
# Search for scroll-related calculations in all files
rg "scrollHeight.*scrollTop.*clientHeight"

# Search for scroll position detection patterns
rg "scrollHeight.*clientHeight"

# Search for scroll-end detection implementations
rg "setScrollReachEnd|isScrollEnd"

Length of output: 826

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.36%. Comparing base (a6fb0b8) to head (ad9f652).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files          66       66           
  Lines        1447     1448    +1     
  Branches      368      383   +15     
=======================================
+ Hits         1322     1323    +1     
  Misses        125      125           

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

@YumoImer
Copy link
Collaborator

非常感谢积极参与!Attachment 组件也是踩了同样的坑~感谢你,我的朋友~

Copy link
Collaborator

@YumoImer YumoImer left a comment

Choose a reason for hiding this comment

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

感谢贡献!

@YumoImer YumoImer merged commit ffac314 into ant-design:main Dec 12, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants