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

perf: 优化 popover 显隐过渡效果 #3140

Open
wants to merge 3 commits into
base: v4
Choose a base branch
from

Conversation

daiwanxing
Copy link
Contributor

@daiwanxing daiwanxing commented Jul 13, 2024

这个 PR 做了什么? (简要描述所做更改)

<popover /> 组件第一次渲染,会有很明显的延时,并且显隐过渡动画有顿挫感,此 PR 修复了这个问题。

修复前:

NutUI.-.Vue.webm

修复后:

2024-07-13.144829.mp4

这个 PR 是什么类型? (至少选择一个)

  • feat: 新特性提交
  • fix: bug 修复
  • docs: 文档改进
  • style: 组件样式/交互改进
  • type: 类型定义更新
  • perf: 性能、包体积优化
  • refactor: 代码重构、代码风格优化
  • test: 测试用例
  • chore(deps): 依赖升级
  • chore(demo): 演示代码改进
  • chore(locale): 国际化改进
  • chore: 其他改动(是关于什么的改动?)

这个 PR 涉及以下平台:

  • NutUI H5 @nutui/nutui
  • NutUI Taro @nutui/nutui-taro

这个 PR 是否已自测:

Summary by CodeRabbit

  • 新功能

    • 更新了弹出框的过渡动画效果,使得弹出和消失的动画更加平滑自然。
  • 错误修复

    • 修正了 <slot> 元素中缺失的闭合标签。
    • 修改了 transition 属性值,以确保弹出内容的动画效果。
  • 重构

    • 优化了函数命名,以提高代码可读性。
    • 使用 async/await 改写了部分函数,增强了错误处理和代码简洁性。

Copy link

coderabbitai bot commented Jul 13, 2024

Walkthrough

这些更改涉及对 src/packages/__VUE/popover 目录下的 index.scssindex.taro.vue 文件的修改。主要包括对弹出框动画的 CSS 调整,以及在 Vue 组件中修复标签、修改过渡属性、重命名函数和优化代码以提高可读性和错误处理。

Changes

文件路径 更改摘要
src/packages/__VUE/popover/index.scss 调整了弹出框动画的 CSS 类,修改了进入和离开弹出框的过渡和样式,包括缩放、不透明度和过渡计时函数的变化。
src/packages/__VUE/popover/index.taro.vue 修复了 <slot> 元素中的缺少闭合标签问题,将 transition 属性值从 "nut-popover" 修改为 "nut-popover-content",并添加了 nextTick 函数的导入。重命名了函数 useTaroRectuseTaroRectById,优化了 upperCaseFirst 函数的可读性,转换 getPopoverContentWgetContentWidth 函数为 async/await 形式以改进错误处理和可读性。

Poem

在代码的世界里,我们欢呼雀跃,
弹出框的动画,闪耀如星辉;
CSS 优雅转变,Vue 组件重整,
函数优化,错误不再相随。
在夏日的代码森林中,小兔子吟唱着,
技术的美丽,如梦如诗。

(\(\ 

( -.-)
o_(")(")


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.20%. Comparing base (a415d0b) to head (d975eb9).

Additional details and impacted files
@@           Coverage Diff           @@
##               v4    #3140   +/-   ##
=======================================
  Coverage   81.20%   81.20%           
=======================================
  Files         226      226           
  Lines       18139    18139           
  Branches     2485     2486    +1     
=======================================
  Hits        14729    14729           
  Misses       3392     3392           
  Partials       18       18           

☔ 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a415d0b and 25459b9.

Files selected for processing (2)
  • src/packages/__VUE/popover/index.scss (2 hunks)
  • src/packages/__VUE/popover/index.taro.vue (4 hunks)
Additional comments not posted (8)
src/packages/__VUE/popover/index.scss (2)

110-114: 优化显示/隐藏过渡效果

这些更改通过在显示和隐藏时添加缩放和透明度过渡效果来优化 popover 的动画效果。确保这些更改在所有浏览器和设备上都能正常工作。


116-119: 使用 ease 过渡效果

这些更改为进入和离开动画添加了 ease 过渡效果,以使动画更平滑。确保这些更改在所有浏览器和设备上都能正常工作。

src/packages/__VUE/popover/index.taro.vue (6)

9-9: 修复缺失的闭合标签

修复了 <slot> 元素的缺失闭合标签,确保了组件的正确渲染。


17-17: 更新过渡属性值

将过渡属性值从 "nut-popover" 更改为 "nut-popover-content",确保与更新的 CSS 类匹配。


43-43: 添加 nextTick 导入

添加了 nextTick 导入,以确保在 DOM 更新后执行某些操作。


45-45: 重命名函数

useTaroRect 重命名为 rectTaro,确保在代码中一致使用新的函数名称。


133-133: 重构 upperCaseFirst 函数

重构了 upperCaseFirst 函数以提高可读性,确保其保持原有功能。


194-229: 重构异步函数

getPopoverContentWgetContentWidth 函数重构为 async/await 以改进错误处理和可读性,确保其保持原有功能。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 25459b9 and 59d9fef.

Files selected for processing (1)
  • src/packages/__VUE/popover/index.taro.vue (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/packages/__VUE/popover/index.taro.vue

@eiinu
Copy link
Member

eiinu commented Jul 17, 2024

修改之后,组件初次加载时获取到的元素定位有点问题,比如「自定义目标元素」这个 demo
image

@daiwanxing
Copy link
Contributor Author

daiwanxing commented Jul 17, 2024

修改之后,组件初次加载时获取到的元素定位有点问题,比如「自定义目标元素」这个 demo image

嗯嗯,debug 了一会儿,发现是因为使用了 transform: scale 影响到了获取 popoverContentRef 的实际渲染宽高。从而导致计算偏移值出现了问题。

@daiwanxing
Copy link
Contributor Author

示例文档中的 <popover /> 弹出的下拉列表渲染出来的高度是 118px,由于过渡进场之前设置了 transform: scale(0.8) 所以代码实际通过 getBoundingClientRect 拿到的值约 118 * 0.8 = 94px

我想到的办法是既然 scale 的值是已知的,那么可以通过 getBoundingClientRect 拿到的 宽高 / scale 就能得到最终渲染到页面的元素大小了。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 59d9fef and d975eb9.

Files selected for processing (2)
  • src/packages/__VUE/popover/index.scss (2 hunks)
  • src/packages/__VUE/popover/index.taro.vue (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/packages/__VUE/popover/index.taro.vue
Additional comments not posted (2)
src/packages/__VUE/popover/index.scss (2)

110-114: 优化过渡效果

修改了 .nut-popover-content&-enter-from&-leave-to 类,增加了 transform: scale(var(--transform-scale));opacity: 0;。这些改变应该是为了使弹出和隐藏的动画更加平滑和迅速。确保这些改变与组件的性能优化目标一致。


116-119: 调整过渡时间函数

.nut-popover-content&-enter-active&-leave-active 类进行了修改,设置了 transition-timing-function: ease;。这种缓动函数通常用于在视觉上更平滑的过渡效果,有助于改善用户体验。

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.

None yet

2 participants