Skip to content

Comments

fix(pickerview): 解决小程序获取高度计算错误#3120

Merged
xiaoyatong merged 12 commits intojdf2e:feat_v3.xfrom
irisSong:feat_add_pickerview
Mar 26, 2025
Merged

fix(pickerview): 解决小程序获取高度计算错误#3120
xiaoyatong merged 12 commits intojdf2e:feat_v3.xfrom
irisSong:feat_add_pickerview

Conversation

@irisSong
Copy link
Collaborator

@irisSong irisSong commented Mar 25, 2025

…rview

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能
    • 更新了组件高度计算逻辑,新增了一个占位视图,现在可以根据元素实际尺寸动态调整高度,同时实现了动态标识。
  • 样式
    • 为新增的占位视图整合了专属样式,使其与整体界面风格保持一致。

@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2025

Walkthrough

这次修改主要更新了组件的高度计算逻辑和样式定义。在 pickerroller.taro.tsx 中,引入了新的引用 placeholderRef 来替代原有的 rollerRef,进而计算占位元素的高度,并更新了 useEffect 的依赖。同时,组件的返回输出中增加了一个带动态 ID 的 View 元素。而在 pickerview.scss 中,新添加了嵌套类 &-placeholder,设置其高度为 $picker-item-height

Changes

文件 变更摘要
src/.../pickerroller.taro.tsx 新增 placeholderRef 替换 rollerRef;更新 useEffect 依赖;新增带动态 ID 的 View 元素。
src/.../pickerview.scss 新增嵌套类 &-placeholder,设置高度为 $picker-item-height

Sequence Diagram(s)

sequenceDiagram
    participant C as 组件
    participant E as useEffect
    participant P as placeholderRef
    participant G as getRectByTaro

    C->>E: 组件挂载
    E->>P: 获取 placeholder 元素
    E->>G: 调用 getRectByTaro(placeholderRef.current)
    G-->>E: 返回元素高度
    E->>C: 应用高度计算结果
Loading

Suggested reviewers

  • xiaoyatong
  • oasis-cloud

Poem

我是一只快乐的小兔,
在代码森林中轻快穿行;
placeholderRef 为我指引新径,
SCSS 的草坪铺就高度清新。
变更之风,轻拂编程世界,喜悦洒满每一行!


📜 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 384bca0 and 17a3376.

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

52-54: 添加占位元素样式,确保高度一致性

新增的 &-placeholder 类将占位元素的高度设置为与 picker 项目相同,保证了计算高度时的一致性和准确性。这是解决小程序高度计算问题的关键部分。

src/packages/pickerview/pickerroller.taro.tsx (4)

47-47: 添加新的引用用于高度计算

添加了 placeholderRef 引用,用于后续获取占位元素的高度,这是修复小程序高度计算错误的基础。


161-161: 更新高度获取逻辑,使用占位元素

将高度获取方法从使用 rollerRef 改为使用 placeholderRef,这样可以更准确地获取固定高度的占位元素尺寸,避免了之前计算错误的问题。


191-191: 更新依赖数组,确保高度变化时重新计算

在 useEffect 的依赖数组中添加 placeholderRef.current,确保当占位元素变化时能重新计算高度,增强了代码的响应性。


250-254: 添加占位元素,提供稳定的高度参考

添加了带有唯一ID和类名的占位元素 View,并绑定了 placeholderRef。这个元素的高度是固定的,为小程序环境下的高度计算提供了稳定可靠的参考点,有效解决了原有的高度计算错误问题。

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 plan to trigger planning for file edits and PR creation.
  • @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 action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Mar 25, 2025
@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.95%. Comparing base (384bca0) to head (17a3376).
Report is 3 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3120   +/-   ##
==========================================
  Coverage      86.95%   86.95%           
==========================================
  Files            280      280           
  Lines          18456    18456           
  Branches        2785     2786    +1     
==========================================
  Hits           16049    16049           
  Misses          2402     2402           
  Partials           5        5           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@irisSong irisSong requested a review from xiaoyatong March 25, 2025 06:44
@xiaoyatong xiaoyatong merged commit c56941d into jdf2e:feat_v3.x Mar 26, 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.

3 participants