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(tabs): 修复tabs数量过多时的滚动操作bug #3014

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

mikasayw
Copy link
Member

@mikasayw mikasayw commented Feb 24, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 重构
    • 优化了滚动处理逻辑,取消了原先采用动画过渡的方式,现直接设置滚动位置,实现更迅速、直接的定位。
    • 简化了视图滚动判断,确保内容在滚动时能够稳定、准确地显示。

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

此次变更简化了滚动逻辑。在 scrollDirection 函数中,移除了原先通过 requestAnimationFrame 循环实现动画的机制,直接根据滚动方向调用 setScrollLeftsetScrollTop 设置滚动位置。同时在 scrollIntoView 函数中,删除了对 to 值小于 0 时的提前返回判断,始终将 to 值传递给 scrollDirection。代码中还增加了中文注释,说明使用 ScrollView 不需要手动处理 raf。

Changes

文件路径 变更概述
src/.../tabs.taro.tsx 1. 在 scrollDirection 中移除 raf 动画逻辑,直接设置水平或垂直滚动。
2. 在 scrollIntoView 中删除对 to < 0 的判断,总是调用 scrollDirection

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户触发事件
    participant SI as scrollIntoView
    participant SD as scrollDirection
    participant SC as 滚动组件

    U->>SI: 请求滚动至位置
    SI->>SD: 调用 scrollDirection(to, direction)
    alt direction == horizontal
        SD->>SC: 调用 setScrollLeft(to)
    else direction == vertical
        SD->>SC: 调用 setScrollTop(to)
    end
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud
  • Alex-huxiyang

Poem

🐇 啊哈,新代码,摆脱旧套路,
轻捷跳跃,滚动直接无阻拦。
优化逻辑,小跳大步不停转,
从此页面飞梭如风般。
快乐代码,兔子歌声悠然扬!
🌟🐰


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 994800f and 376f691.

📒 Files selected for processing (1)
  • src/packages/tabs/tabs.taro.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
src/packages/tabs/tabs.taro.tsx (2)

163-165: 代码简化得当!

移除了手动动画处理逻辑,直接使用 ScrollView 组件的内置滚动功能是正确的做法。这样可以:

  • 减少代码复杂度
  • 提高滚动的可靠性
  • 让组件的行为更加可预测

188-189:

❓ Verification inconclusive

请验证边界情况下的滚动行为

移除了对滚动位置的预检查,直接调用 scrollDirection。虽然这样可以解决当前的滚动问题,但建议验证以下场景:

  • 首个标签页的滚动行为
  • 最后一个标签页的滚动行为
  • 快速切换标签页时的滚动表现

🏁 Script executed:

#!/bin/bash
# 搜索相关测试用例,确保边界情况已被覆盖
rg -l "test.*scroll.*tab" "test.*first.*tab" "test.*last.*tab"

Length of output: 177


请手动验证边界滚动表现

当前代码在移除了边界预检查后直接调用 scrollDirection(to, direction),可能会带来以下风险:

  • 首个标签页的滚动行为是否正常(存在因缺少预检查而导致的异常)
  • 最后一个标签页的滚动表现是否符合预期
  • 快速切换标签页时滚动动作是否存在遗漏或异常

注意:自动搜索测试用例的命令未返回预期结果,请手动检查或补充相应的测试用例,以确保上述边界情况均得到妥善处理。

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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 2.x Target branch 2.x label Feb 24, 2025
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.56%. Comparing base (994800f) to head (376f691).
Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3014   +/-   ##
=======================================
  Coverage   85.56%   85.56%           
=======================================
  Files         267      267           
  Lines       18003    18003           
  Branches     2726     2726           
=======================================
  Hits        15405    15405           
  Misses       2595     2595           
  Partials        3        3           

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

@mikasayw
Copy link
Member Author

#2554 此PR的错乱问题从逻辑上看起来与父级tab的滚动距离没有关系

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Target branch 2.x size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants