Skip to content

Conversation

@xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Mar 4, 2025

1、修复多个元素出现时,第一条数据无法滚动到可视区的问题
2、滚动条显隐控制的增强处理
https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html

Summary by CodeRabbit

  • 重构
    • 优化了滚动体验,取消了多余的动画处理,实现直接定位以提升响应速度。
    • 调整了组件的配置,确保显示效果更加一致。

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

该 PR 对 src/packages/tabs/tabs.taro.tsx 文件中的滚动逻辑进行了简化。现在,scrollDirection 函数不再使用 requestAnimationFrame 循环动画,而是根据传入的方向直接更新滚动位置;同时,scrollIntoView 函数移除了对负的 to 值的检查,并始终将计算结果传入滚动处理函数。此外,对 React.cloneElement 调用中的 autoHeightClassName 参数做了调整,将不满足条件时设置为 undefined。无公开接口的变更。

Changes

文件 变更摘要
src/packages/.../tabs.taro.tsx 调整 scrollDirectionscrollIntoView:移除 RAF 动画循环和负值检查,更新 autoHeightClassName 处理

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant T as Tabs组件
    participant F as 滚动函数
    U->>T: 触发滚动操作
    T->>F: 调用 scrollIntoView (计算目标位置)
    F->>F: 调用 scrollDirection (根据方向直接更新滚动位置)
    F-->>T: 滚动位置已更新
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud

Poem

我是一只快乐的小兔子,
见证代码简化的奇迹。
动画消失如烟雾散尽,
滚动直达目标,犹如轻快飞跃,
我的心跳和代码共欢跃 🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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.

@xiaoyatong xiaoyatong requested review from irisSong and oasis-cloud and removed request for irisSong March 4, 2025 12:12
@github-actions github-actions bot added the action:review This PR needs more reviews (less than 2 approvals) label Mar 4, 2025
@xiaoyatong xiaoyatong requested a review from irisSong March 4, 2025 12:12
@github-actions github-actions bot added the 3.x Target branch 3.x label Mar 4, 2025
@codecov
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.05%. Comparing base (c5f27c5) to head (29345a3).
Report is 1 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3043   +/-   ##
==========================================
  Coverage      86.05%   86.05%           
==========================================
  Files            281      281           
  Lines          18255    18255           
  Branches        2749     2749           
==========================================
  Hits           15709    15709           
  Misses          2541     2541           
  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

🧹 Nitpick comments (1)
src/packages/tabs/tabs.taro.tsx (1)

302-302: 将空字符串替换为 undefined,优化条件属性

将条件不满足时的值从空字符串改为 undefined 是更符合 React 最佳实践的做法。当属性为 undefined 时,React 不会将其渲染到 DOM 中,而空字符串会被当作有效值处理。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5f27c5 and 29345a3.

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

163-165: 简化滚动方向逻辑,提高代码可读性

改动移除了之前使用的动画逻辑,改为直接设置滚动位置,这是一个好的简化。注释也清晰地解释了为什么不需要手动使用 raf 来控制 scrollLeft。


188-189: 删除了对负 to 值的检查,允许滚动到所有计算位置

之前的版本可能会忽略某些滚动位置(特别是负值),导致第一个项目无法滚动到可视区域。移除这个检查后,组件现在会尝试滚动到所有计算出的位置,解决了PR中提到的第一个项目不可滚动的问题。


234-234:

✅ Verification successful

添加 enhanced 属性优化滚动性能

添加 enhanced 属性可以增强 ScrollView 组件的滚动性能,这与 PR 目标中提到的"增强对滚动条可见性的控制"相符。根据微信小程序文档,enhanced 模式提供更强大的性能和滚动控制能力。


🌐 Web query:

微信小程序 ScrollView enhanced 属性有什么作用

💡 Result:

微信小程序中scroll-view组件的enhanced属性主要用于启用增强滚动特性,提供更丰富的交互控制和性能优化。以下是其主要作用:

核心功能

  1. 启用ScrollViewContext控制
    开启后可通过ScrollViewContext对象动态操作滚动视图,实现精准的滚动位置控制、边界检测等高级功能[1][5][9]。

  2. 支持扩展属性生效
    作为以下增强属性的前置条件,这些特性仅在enhanced=true时生效:

    • paging-enabled:分页滑动效果(类似轮播图)[1][2]
    • show-scrollbar:控制滚动条显隐[1][3]
    • bounces:iOS边界弹性效果开关[2][3]
    • fast-deceleration:滑动减速速率控制[3][7]

事件增强

开启后支持更精细的滚动事件监听:

<scroll-view enhanced binddragstart="onDragStart" 
  binddragging="onDragging" binddragend="onDragEnd">
  • binddragstart:滑动开始时触发,返回scrollTop/Left[1][3]
  • binddragging:滑动中持续触发,返回实时位置[1][7]
  • binddragend:滑动结束触发,额外返回velocity滑动速度[1][3]

性能优化

  • 通过enable-passive属性配合使用可提升滚动性能[1]
  • iOS下通过scroll-anchoring属性防止内容抖动(需同时开启)[5]

使用注意事项

  1. 版本要求
    需基础库版本≥2.12.0[5][9],建议在app.json中设置"enableEnhancedScroll": true全局配置。

  2. 嵌套限制
    增强模式下避免嵌套过多滚动容器,可能导致手势冲突[4][10]。

  3. 平台差异
    部分特性如bounces仅在iOS生效,安卓需通过CSS实现类似效果[3][5]。

典型配置示例:

<scroll-view 
  enhanced
  scroll-y 
  show-scrollbar="{{false}}"
  bounces="{{false}}"
  style="height: 300rpx;"
  binddragend="handleScrollEnd"
>
  <!-- 滚动内容 -->
</scroll-view>

Citations:


修改确认:ScrollView 组件增强滚动性能

在文件 src/packages/tabs/tabs.taro.tsx 的第 234 行添加 enhanced 属性后,该组件将启用微信小程序的增强滚动特性。启用后,ScrollView 可通过 ScrollViewContext 实现精准的滚动位置控制,同时支持分页滑动、滚动条控制、边界弹性和快速减速等扩展功能。这一改动符合 PR 中对“增强滚动条可见性控制”的优化目标,并能有效提升滚动性能。请确保全局配置(如 app.json 中的 "enableEnhancedScroll": true)满足该属性要求。

@oasis-cloud oasis-cloud merged commit 0082e19 into jdf2e:feat_v3.x Mar 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants