Skip to content

refactor(overlay): 替换csstransition #3227

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

Open
wants to merge 3 commits into
base: feat_v3.x
Choose a base branch
from

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented May 20, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 优化
    • 叠加层(Overlay)动画效果由原先的 CSS 过渡切换为更流畅的弹簧动画,提升显示与隐藏时的视觉体验。
    • 动画持续时间可通过参数自定义,动画结束后依然支持回调处理。
    • 组件对外接口与用法保持不变。

Copy link

coderabbitai bot commented May 20, 2025

"""

Walkthrough

本次更改将 Overlay 组件的动画方式由原本基于 CSS 过渡(使用 CSSTransition)切换为基于弹簧动画(使用 @react-spring/webuseSpring)。组件的可见性和动画状态通过 animated.div 控制,并根据动画状态回调对应的生命周期函数。

Changes

文件/路径 变更摘要
src/packages/overlay/overlay.tsx 将动画实现从 CSSTransition 替换为 @react-spring/web 的弹簧动画;移除 CSSTransition,改为条件渲染 animated.div;动画完成后调用相应回调;保持滚动锁定和点击处理逻辑不变。
src/packages/overlay/overlay.taro.tsx 使用 @react-spring/web 的弹簧动画替代部分 CSSTransition 动画,调整渲染结构以直接返回带动画的 animated.div,保留滚动锁定与点击处理,动画完成时触发回调。

Sequence Diagram(s)

sequenceDiagram
    participant Parent
    participant Overlay
    participant ReactSpring

    Parent->>Overlay: 设置 visible 状态
    Overlay->>ReactSpring: 调用 useSpring 动画 opacity
    ReactSpring-->>Overlay: 动画完成回调 (onRest)
    Overlay->>Parent: 调用 afterShow/afterClose 回调
Loading

Suggested reviewers

  • oasis-cloud
  • irisSong

Poem

🐇
弹簧轻舞替换旧时光,
叠影浮现随状态扬。
回调如风送消息,
代码之间跃新章。
兔子欢喜跳一场!
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) and removed 3.x Target branch 3.x labels May 20, 2025
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/overlay/overlay.tsx (1)

65-75: 使用Spring动画替代CSS过渡

使用useSpring实现的动画效果比CSS过渡更加灵活,但目前只实现了透明度渐变。如果原先的CSS过渡包含其他变换(如位移或缩放),这些效果会丢失。

建议:

  1. 检查原有CSS过渡是否包含了其他动画效果
  2. 如有必要,将这些效果也添加到Spring配置中

另外,当前实现使用了固定的duration作为动画时长,这与Spring的物理模型设计理念不太一致。Spring动画通常使用tensionfriction参数获得更自然的效果。

  const springProps = useSpring({
    opacity: innerVisible ? 1 : 0,
-   config: { duration },
+   config: { 
+     tension: 280,
+     friction: 20,
+     // 仍然支持duration作为备选
+     duration: props.useDuration ? duration : undefined 
+   },
    onRest: () => {
      if (innerVisible) {
        afterShow()
      } else {
        afterClose()
      }
    },
  })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba6dfb and 0fe2815.

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

53-53: 类名逻辑变更

原先的实现可能是通过CSSTransition动态添加类名,现在改为始终包含nut-overlay-slide类。请确认这个变更不会对现有样式产生负面影响,特别是在不同状态下(显示/隐藏)的样式表现。


78-88: 渲染逻辑变更

使用animated.div替代CSSTransition是个好的改进,但需要确保以下几点:

  1. 原有的CSS类在不同动画阶段的应用逻辑是否需要保留
  2. 确认动画完成前的点击事件处理是否一致
  3. 验证在不同设备和浏览器上的动画性能表现

当前实现只有在innerVisible为true时才渲染组件,这与原有的CSSTransition行为可能不同。请确认这不会导致用户体验不一致。


82-82: 样式合并方式的更改

springProps直接合并到样式对象中是正确的做法,但需要注意useSpring返回的对象中可能包含不应传递给DOM的属性。


8-8:

✅ Verification successful

新增了 React Spring 依赖,用于动画效果实现。

从CSS过渡动画切换到基于Spring的动画实现是一个不错的改进,可以提供更平滑的动画效果。但请确认这个新依赖已经被添加到项目的package.json中,并考虑其对包体积的影响。

请运行以下命令验证依赖是否已正确添加:


🏁 Script executed:

#!/bin/bash
grep -r "@react-spring/web" package.json

Length of output: 75


确认 @react-spring/web 已添加

  • 已在 package.json 中找到 "@react-spring/web": "~9.6.1"
  • 请继续关注该依赖对打包体积的影响,必要时可使用打包分析工具进行评估

@github-actions github-actions bot added 3.x Target branch 3.x and removed 3.x Target branch 3.x labels May 20, 2025
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

🔭 Outside diff range comments (1)
src/packages/overlay/overlay.taro.tsx (1)

54-58: ⚠️ Potential issue

事件类型不匹配导致 TS2322

handleClick 参数类型为 ITouchEvent,但在 animated.div / View 上通过 onClick 透传时,类型期望分别为 MouseEventBaseEventOrig,CI 已报错。

-const handleClick = (e: ITouchEvent) => {
+// 兼容 H5 & 小程序事件类型
+const handleClick = (e: any) => {

或为 onClick 显式断言:

onClick={handleClick as unknown as React.MouseEventHandler<HTMLDivElement>}

如最终保留 View,可改为 (e: any) 并在实现内部做 run-time 判断。

🧰 Tools
🪛 Biome (1.9.4)

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🧹 Nitpick comments (2)
src/packages/overlay/overlay.taro.tsx (2)

60-71: useSpring 配置与生命周期回调耦合过紧

  • config: { duration } 会覆盖默认的缓动函数,导致线性动画;若想保持与旧版一致的缓动效果,可使用 config: { duration, easing: easings.easeInOutCubic }(或保持默认张弛动画,去掉 duration)。
  • onRest 中依据 innerVisible 判定回调存在竞态:快速点击显示→隐藏可能导致 afterShow/afterClose 顺序颠倒。可采用 useEffect 监听 innerVisible 并在 spring.start(() => …) 的回调里分支判断,降低竞态概率。

48-48: 类名中保留 -slide 修饰符可能产生歧义

现已改用弹簧渐隐动画,但仍附带 nut-overlay-slide 类;若样式文件中存在与滑动相关的 transform,将产生不必要的样式冲突。考虑改为 nut-overlay-fade 或去掉该修饰符。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe2815 and d4b98de.

📒 Files selected for processing (1)
  • src/packages/overlay/overlay.taro.tsx (4 hunks)
🧰 Additional context used
🪛 GitHub Check: build
src/packages/overlay/overlay.taro.tsx

[failure] 79-79:
Type '(e: ITouchEvent) => void' is not assignable to type 'MouseEventHandler'.

🪛 GitHub Actions: CI
src/packages/overlay/overlay.taro.tsx

[error] 79-79: TypeScript error TS2322: Type '(e: ITouchEvent) => void' is not assignable to type 'MouseEventHandler'.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

@xiaoyatong xiaoyatong closed this May 23, 2025
@xiaoyatong
Copy link
Collaborator Author

暂时还不能替换~ 无法支持其他端

@xiaoyatong xiaoyatong reopened this Jun 11, 2025
@github-actions github-actions bot added the 3.x Target branch 3.x label Jun 11, 2025
@xiaoyatong xiaoyatong changed the title refactor(Overlay): 替换csstransition refactor(overlay): 替换csstransition Jun 26, 2025
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/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant