Skip to content

feat: mouse down to scroll #293

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

Merged
merged 2 commits into from
Dec 4, 2024
Merged

feat: mouse down to scroll #293

merged 2 commits into from
Dec 4, 2024

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Dec 4, 2024

resolve ant-design/ant-design#51888

Summary by CodeRabbit

  • 新功能
    • 引入了 useScrollDrag 自定义钩子,支持通过鼠标拖动进行滚动。
    • 更新了 RawList 组件以使用新的拖动滚动功能,提升用户交互体验。
  • 测试
    • 增强了 List.Scroll 组件的测试覆盖,新增了模拟鼠标拖动事件的测试用例。

Copy link

vercel bot commented Dec 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
virtual-list ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2024 10:01am

Copy link

coderabbitai bot commented Dec 4, 2024

Walkthrough

此次更改引入了一个新的自定义钩子 useScrollDrag,用于在 RawList 组件中实现鼠标拖动滚动功能。该钩子通过调整 offsetTop 来修改滚动位置,并更新了 onWheelDelta 函数以更有效地处理水平和垂直滚动。同时,ScrollBar 组件中的 getPageXY 函数被重构为从 useScrollDrag 中导入,增强了代码组织。测试文件也进行了相应的更新,以增强对滚动行为的测试覆盖。

Changes

文件路径 更改摘要
src/List.tsx 新增钩子 useScrollDrag,更新 RawList 组件以支持拖动滚动,调整 onWheelDeltasyncScrollTop 函数。
src/ScrollBar.tsx 移除内联 getPageXY 函数,改为从 ./hooks/useScrollDrag 导入,保持功能一致。
src/hooks/useScrollDrag.ts 新增钩子 useScrollDrag,实现拖动滚动功能,包含事件处理和清理逻辑,新增 getPageXY 函数。
tests/scroll.test.js 更新测试以增强对滚动行为的覆盖,新增鼠标拖动事件的测试用例。

Assessment against linked issues

Objective Addressed Explanation
自动向下滚动(#51888)

Possibly related PRs

🐰 在滚动中跳跃,鼠标轻轻拖,
新钩子来助力,体验更流畅。
滚动条不再烦,轻松随意拖,
兔子欢快舞,乐在其中哦! 🌟

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/List.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

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 Dec 4, 2024

Codecov Report

Attention: Patch coverage is 95.91837% with 2 lines in your changes missing coverage. Please review.

Project coverage is 98.32%. Comparing base (776411b) to head (1f3f704).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/hooks/useScrollDrag.ts 95.74% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
- Coverage   98.49%   98.32%   -0.17%     
==========================================
  Files          18       19       +1     
  Lines         732      778      +46     
  Branches      177      187      +10     
==========================================
+ Hits          721      765      +44     
- Misses         11       13       +2     

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

🧹 Outside diff range and nitpick comments (1)
src/hooks/useScrollDrag.ts (1)

68-69: 考虑为 stopScroll() 调用添加测试覆盖

第 68-69 行的 stopScroll() 调用未被测试覆盖。建议添加测试用例,覆盖在拖动过程中鼠标移动回组件内部时调用 stopScroll() 的场景,以确保此逻辑的可靠性。

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 68-69: src/hooks/useScrollDrag.ts#L68-L69
Added lines #L68 - L69 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 776411b and 1f3f704.

📒 Files selected for processing (4)
  • src/List.tsx (2 hunks)
  • src/ScrollBar.tsx (1 hunks)
  • src/hooks/useScrollDrag.ts (1 hunks)
  • tests/scroll.test.js (3 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/hooks/useScrollDrag.ts

[warning] 68-69: src/hooks/useScrollDrag.ts#L68-L69
Added lines #L68 - L69 were not covered by tests

🔇 Additional comments (3)
src/ScrollBar.tsx (1)

4-4: 成功重构并导入 getPageXY 函数

已从 './hooks/useScrollDrag' 导入 getPageXY 函数,优化了代码复用性和组织结构。

tests/scroll.test.js (1)

559-602: “mouse down drag”测试用例完善,正确模拟了拖拽事件

新增的测试用例有效地测试了鼠标拖动滚动功能,确保了向下和向上拖动的场景得到正确覆盖。

src/List.tsx (1)

440-443: 正确集成了 useScrollDrag 钩子,实现了鼠标拖动滚动

在组件中使用了 useScrollDrag 钩子,并正确处理了滚动偏移,实现了鼠标拖动滚动的功能,提升了用户体验。

Comment on lines +4 to +6
function smoothScrollOffset(offset: number) {
return Math.floor(offset ** 0.5);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

处理 smoothScrollOffset 函数中的负偏移值

offset 为负数时,smoothScrollOffset 函数将返回 NaN,因为在 JavaScript 中,负数的 0.5 次幂结果为 NaN。这可能导致当 offset 为负数时出现问题。建议在计算前对 offset 取绝对值,并根据原始符号返回结果。

建议修改如下:

 function smoothScrollOffset(offset: number) {
-  return Math.floor(offset ** 0.5);
+  const result = Math.floor(Math.sqrt(Math.abs(offset)));
+  return offset >= 0 ? result : -result;
 }
📝 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
function smoothScrollOffset(offset: number) {
return Math.floor(offset ** 0.5);
}
function smoothScrollOffset(offset: number) {
const result = Math.floor(Math.sqrt(Math.abs(offset)));
return offset >= 0 ? result : -result;
}

@zombieJ zombieJ merged commit 4f1221d into master Dec 4, 2024
10 of 12 checks passed
@zombieJ zombieJ deleted the click-scroll branch December 4, 2024 10:48
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.

virtual table 自定义srcollBar(禁用原生)后无法自动滚动跟随选中项。
1 participant