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

feat(popup): lockscroll 增加可选值 strict, 用于支持 iOS12 #2629

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Oct 9, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了 Overlay 组件的 lockScroll 属性,支持更灵活的滚动锁定选项(boolean | 'strict')。
    • Popup 组件的逻辑进行了优化,提升了代码的清晰度与组织性。
  • 改进

    • 更新了文档,反映了 lockScroll 属性的变化,确保使用示例和属性说明保持一致。
    • 增强了组件的灵活性,同时保持了核心功能不变。

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.99%. Comparing base (46abf45) to head (40d922f).
Report is 4 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2629      +/-   ##
==========================================
+ Coverage   82.92%   82.99%   +0.06%     
==========================================
  Files         219      219              
  Lines       17912    17914       +2     
  Branches     2544     2549       +5     
==========================================
+ Hits        14854    14867      +13     
+ Misses       3053     3042      -11     
  Partials        5        5              

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

Copy link

coderabbitai bot commented Oct 9, 2024

Walkthrough

此次更改涉及OverlayPopup组件的多个修改。在Overlay中,OverlayProps接口的lockScroll属性类型更新为boolean | 'strict',并初始化为true以保持向后兼容。引入了新变量shouldLockScroll来优化锁定滚动的逻辑。在Popup中,导入语句的顺序进行了调整,defaultProps现在包含defaultOverlayProps的扩展,锁定滚动的逻辑也使用了shouldLockScroll,增强了代码的清晰度。文档也相应更新以反映这些变化。

Changes

文件路径 更改摘要
src/packages/overlay/overlay.tsx 更新OverlayProps中的lockScroll属性类型为`boolean
src/packages/popup/popup.tsx 调整导入语句顺序,defaultProps现在包含defaultOverlayProps的扩展,更新锁定滚动逻辑以使用shouldLockScroll
src/packages/overlay/doc.en-US.md 更新文档以反映lockScroll属性类型的变化。
src/packages/overlay/doc.md 更新文档以反映lockScroll属性类型的变化。
src/packages/overlay/doc.zh-TW.md 更新文档以反映lockScroll属性类型的变化。
src/packages/popup/doc.en-US.md 更新文档以反映lockScroll属性类型的变化。
src/packages/popup/doc.md 更新文档以反映lockScroll属性类型的变化。
src/packages/popup/doc.zh-TW.md 更新文档以反映lockScroll属性类型的变化。

Possibly related PRs

Poem

在兔子洞里跳跃欢,
新组件如春花般。
滚动锁定更灵活,
代码清晰乐无边。
让我们一起庆祝吧,
兔子舞动乐无穷! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fdde051 and 40d922f.

📒 Files selected for processing (6)
  • src/packages/overlay/doc.en-US.md (1 hunks)
  • src/packages/overlay/doc.md (1 hunks)
  • src/packages/overlay/doc.zh-TW.md (1 hunks)
  • src/packages/popup/doc.en-US.md (1 hunks)
  • src/packages/popup/doc.md (1 hunks)
  • src/packages/popup/doc.zh-TW.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/packages/overlay/doc.en-US.md
  • src/packages/overlay/doc.md
  • src/packages/overlay/doc.zh-TW.md
  • src/packages/popup/doc.en-US.md
  • src/packages/popup/doc.md
  • src/packages/popup/doc.zh-TW.md

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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

@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

🧹 Outside diff range and nitpick comments (3)
src/packages/overlay/overlay.tsx (1)

69-70: shouldLockScroll 变量的引入是一个很好的改进。

新增的 shouldLockScroll 变量优化了决定何时锁定滚动的逻辑。这确保了当叠加层不可见时,无论 lockScroll 的值如何,都不会锁定滚动。这是一个很好的改进,可以提高组件的行为和性能。

小建议:考虑使用三元运算符来使代码更简洁:

const shouldLockScroll = innerVisible && lockScroll;

这样可以使逻辑更加清晰和简洁。

src/packages/popup/popup.tsx (2)

16-16: 导入顺序的变更

导入 OverlayProps 和 defaultOverlayProps 的顺序已经调整。虽然这是一个微小的变化,不会影响功能,但建议检查一下这是否符合项目的导入顺序约定。如果有特定的导入顺序规则,请确保整个代码库都保持一致。


107-110: 滚动锁定逻辑的改进

引入 shouldLockScroll 变量提高了代码的可读性和可维护性。这个改动确保了当弹出框不可见时不会锁定滚动,可以防止潜在的问题。这是一个很好的改进。

建议:

  1. 为了进一步提高代码的可读性,可以考虑添加一个简短的注释来解释 shouldLockScroll 的逻辑。例如:
// 只在弹出框可见且 lockScroll 为 true 时锁定滚动
const shouldLockScroll = !innerVisible ? false : lockScroll
  1. 考虑使用更简洁的条件表达式:
const shouldLockScroll = innerVisible && lockScroll

这样可以使逻辑更加直观。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 46abf45 and 2cecfb9.

📒 Files selected for processing (2)
  • src/packages/overlay/overlay.tsx (3 hunks)
  • src/packages/popup/popup.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/packages/overlay/overlay.tsx (4)

5-7: 导入语句的重新排序看起来不错。

这个变更不会影响功能,可能是为了保持代码风格的一致性。保持导入语句的良好组织有助于提高代码的可读性。


71-71: useLockScroll 钩子的使用更新很合适。

useLockScroll 钩子的参数从 lockScroll 更新为 shouldLockScroll 是一个很好的改变。这确保了滚动锁定行为会根据可见性和 lockScroll 属性正确应用。这个改动与之前引入 shouldLockScroll 变量的改动保持一致,提高了代码的整体逻辑性和可维护性。


Line range hint 1-124: 总体评价:代码改动质量高,逻辑清晰。

这次对 Overlay 组件的修改整体上是很好的改进:

  1. lockScroll 属性类型的扩展增加了灵活性,可能有助于支持 iOS 12。
  2. 引入 shouldLockScroll 变量优化了滚动锁定逻辑,提高了组件的行为和性能。
  3. useLockScroll 钩子的使用更新与新的逻辑保持一致。

建议:

  1. 更新相关文档,特别是关于新的 'strict' 选项的说明。
  2. 考虑使用三元运算符简化 shouldLockScroll 的赋值。

总的来说,这些改动提高了组件的质量和灵活性,同时保持了代码的清晰度和可维护性。好的工作!


20-20: lockScroll 属性类型的更新是个很好的改进。

lockScroll 的类型从 boolean 更改为 boolean | 'strict' 增加了更多的灵活性,这可能与 PR 目标中提到的 iOS 12 支持有关。这是一个很好的改进。

建议:

  1. 请确保更新相关文档,解释新的 'strict' 选项的用途和行为。
  2. 考虑在组件的 JSDoc 中添加对这个新选项的说明。

为了确保这个改动的一致性,我们可以检查其他文件中 lockScroll 的使用情况:

✅ Verification successful

lockScroll 属性类型更新验证通过。

所有 lockScroll 的使用情况均符合新的类型定义 boolean | 'strict',未发现不符合的赋值。建议更新相关文档,解释新的 'strict' 选项的用途和行为。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查其他文件中 lockScroll 的使用情况

# 测试:搜索 lockScroll 的使用。预期:可能会发现需要更新的地方。
rg --type typescript --type javascript 'lockScroll'

Length of output: 86


Script:

#!/bin/bash
# 描述:检查其他文件中 lockScroll 的使用情况

rg --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' 'lockScroll'

Length of output: 3936


Script:

#!/bin/bash
# 描述:查找 lockScroll 被赋值为非 boolean 或非 'strict' 的情况

rg --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' \
    "(lockScroll\s*=\s*(?!true|false|'strict').+)|(\<[^>]+lockScroll\s*=\s*(?!true|false|'strict').+\/?>)"

Length of output: 499


Script:

#!/bin/bash
# 描述:查找 lockScroll 被赋值为非 boolean 或非 'strict' 的情况,启用 PCRE2 支持

rg --pcre2 --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' \
    "(lockScroll\s*=\s*(?!true|false|'strict').+)|(<[^>]+lockScroll\s*=\s*(?!true|false|'strict').+\/?>)"

Length of output: 1385

src/packages/popup/popup.tsx (1)

4-9: 导入语句的改进

这些更改提高了代码的可读性和可维护性。通过明确导入所需的函数,可能会减少最终的打包大小。添加 ReactPortal 的导入表明它可能在组件的其他地方被使用。

@xiaoyatong
Copy link
Collaborator

需要补充一下文档

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 10, 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: 2

🧹 Outside diff range and nitpick comments (5)
src/packages/overlay/doc.md (1)

69-69: 建议添加对'strict'选项的解释

lockScroll属性的类型已更新为boolean|strict,这与PR的目标一致。然而,文档中缺少对'strict'选项的解释。

建议添加以下内容:

-| lockScroll | 背景是否锁定 | `boolean\|strict` | `true` |
+| lockScroll | 背景是否锁定。当设置为'strict'时,将使用更严格的滚动锁定方式,用于支持iOS 12 | `boolean\|strict` | `true` |

这将帮助用户理解新选项的用途和使用场景。

src/packages/overlay/doc.zh-TW.md (1)

69-69: 文档更新正确,但需要补充说明

lockScroll 属性类型的更新正确反映了组件 API 的变化。然而,对于新增的 'strict' 选项,应该提供更详细的解释。

建议添加以下说明:

-| lockScroll | 背景是否鎖定 | `boolean\|strict` | `true` |
+| lockScroll | 背景是否鎖定 | `boolean\|'strict'` | `true` |
+
+> 當設置為 'strict' 時,將使用更嚴格的滾動鎖定方式,特別適用於 iOS 12 等特殊情況。

这将帮助用户更好地理解新选项的用途和适用场景。

src/packages/popup/doc.zh-TW.md (1)

82-82: LGTM,但建議補充說明 "strict" 值的用途

lockScroll 屬性的類型更新正確反映了新增的 "strict" 選項。這與 PR 的目標一致,即為 lockscroll 功能添加新的可選值以支持 iOS 12。

建議在文檔中添加關於 "strict" 值的具體說明,例如:

- | lockScroll | 背景是否鎖定 | `boolean\|strict` | `true` |
+ | lockScroll | 背景是否鎖定 | `boolean\|strict` | `true` |
+ 當設置為 `'strict'` 時,將使用更嚴格的滾動鎖定機制,特別適用於 iOS 12 等特定環境。

這將幫助用戶更好地理解並正確使用新的選項。

src/packages/popup/doc.md (1)

Line range hint 13-19: 建议添加 'strict' 选项的使用示例

考虑在"基础用法"部分添加一个演示 lockScroll 属性 'strict' 选项的代码示例。这将帮助用户更好地理解新选项的用法和效果,特别是在 iOS 12 上的表现。

如果需要,我可以协助编写这个示例代码。

src/packages/popup/doc.en-US.md (1)

82-82: 更新了 lockScroll 属性的类型定义

lockScroll 属性的类型已从 boolean 更新为 boolean|strict。这个变更与 PR 的目标一致,即为 lockscroll 功能添加一个新的可选值 'strict',以支持 iOS 12。

然而,文档中缺少对这个新值的详细解释。建议添加一些说明来解释 'strict' 模式的作用以及何时使用它。

是否需要我协助编写关于 'strict' 模式的详细说明?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2cecfb9 and fdde051.

📒 Files selected for processing (6)
  • src/packages/overlay/doc.en-US.md (1 hunks)
  • src/packages/overlay/doc.md (1 hunks)
  • src/packages/overlay/doc.zh-TW.md (1 hunks)
  • src/packages/popup/doc.en-US.md (1 hunks)
  • src/packages/popup/doc.md (1 hunks)
  • src/packages/popup/doc.zh-TW.md (1 hunks)
🧰 Additional context used

src/packages/overlay/doc.en-US.md Outdated Show resolved Hide resolved
src/packages/popup/doc.md Outdated Show resolved Hide resolved
@xiaoyatong xiaoyatong merged commit d623224 into jdf2e:next Oct 11, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 27, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants