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: 弹出窗口因为浏览器窗口变化从bottomLeft对齐到topRight对齐时,箭头对齐错误 #491

Closed
wants to merge 1 commit into from

Conversation

three-water666
Copy link

@three-water666 three-water666 commented Nov 2, 2024

react-component/picker#886 (comment)
动画

Summary by CodeRabbit

  • 新功能

    • 改进了弹出框的对齐逻辑,确保在可见性和交集区域的基础上进行最佳对齐。
  • 修复

    • 优化了弹出框位置翻转的条件,提升了对齐的准确性。

Copy link

coderabbitai bot commented Nov 2, 2024

Walkthrough

此次更改涉及 src/hooks/useAlign.tsuseAlign 函数的多个修改。新增了临时变量 tmpTargetPointstmpPopupPoints 用于存储对齐计算中的修改点值。同时引入了新的辅助函数 updateTmpPopupPointsAndTmpTargetPoints,用于根据当前对齐信息更新这些临时变量。对齐逻辑经过精细化调整,特别是在处理弹出位置翻转的部分,更新了条件以使用新的临时变量。此外,增加了可见性和交集区域的检查,以确定最佳对齐位置。

Changes

文件路径 更改摘要
src/hooks/useAlign.ts - 添加临时变量 tmpTargetPointstmpPopupPoints
- 新增辅助函数 updateTmpPopupPointsAndTmpTargetPoints
- 精细化翻转逻辑,更新条件使用新临时变量。
- 扩展对齐逻辑,增加可见性和交集区域检查。
- 调整偏移量和最终对齐位置计算。

Possibly related PRs

  • fix: DOMRect value issues #481: 此PR也修改了 src/hooks/useAlign.ts 中的 useAlign 函数,特别增强了边界矩形坐标的获取,这与主要PR中精细化的对齐逻辑直接相关。

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

@three-water666 three-water666 changed the title fix: 弹出窗口因为窗口变化从bottomLeft对齐到topRight对齐时,箭头对齐错误 fix: 弹出窗口因为浏览器窗口变化从bottomLeft对齐到topRight对齐时,箭头对齐错误 Nov 2, 2024
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8abc4f9 and decac3c.

📒 Files selected for processing (1)
  • src/hooks/useAlign.ts (6 hunks)
🔇 Additional comments (5)
src/hooks/useAlign.ts (5)

326-327: 引入临时变量以保存原始对齐点,提升代码可维护性

通过新增 tmpTargetPointstmpPopupPoints 变量,避免了在对齐计算过程中对原始对齐点的直接修改,提升了代码的清晰度和可维护性。


453-456: 在翻转后更新临时对齐点,确保对齐计算准确

在对齐点翻转后,及时更新 tmpPopupPointstmpTargetPoints,确保后续计算使用最新的对齐点信息,避免可能的逻辑错误。


500-503: 处理顶部到底部的翻转,保持对齐逻辑一致性

在处理从顶部到底部的翻转时,更新了对齐点并调用了更新函数,保持了翻转逻辑的一致性和正确性。


554-557: 增加左右翻转的处理,增强组件对不同情况的适应性

在左右翻转时,更新了对齐点并调用更新函数,确保弹出层在屏幕边缘情况下也能正确对齐。


601-604: 完善从左到右的翻转逻辑,提升用户体验

通过处理从左到右的翻转,更新对齐点和临时变量,确保弹出层在各种对齐方式下都能正确显示,提高了组件的可靠性。

Comment on lines +404 to +408
function updateTmpPopupPointsAndTmpTargetPoints() {
tmpPopupPoints = splitPoints(nextAlignInfo.points[0]);
tmpTargetPoints = splitPoints(nextAlignInfo.points[1]);
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

将更新临时对齐点的逻辑封装成函数,减少代码重复

新增的 updateTmpPopupPointsAndTmpTargetPoints() 函数封装了更新临时对齐点的逻辑,避免了重复代码,提高了代码的复用性和可读性。

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.

1 participant