nutui-react icon indicating copy to clipboard operation
nutui-react copied to clipboard

feat: imagepreview taro 增加缩放, 优化代码

Open xiaoyatong opened this issue 11 months ago • 5 comments

🤔 这个变动的性质是?

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

🔗 相关 Issue

https://github.com/jdf2e/nutui-react/issues/784 https://github.com/jdf2e/nutui-react/issues/1255

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 样式更新

    • 优化了图片预览组件的样式布局
    • 调整了关闭图标和图像/视频容器的显示方式
    • 确保图片预览组件宽度自适应且居中
  • 组件改进

    • 增强了图片预览组件的类型安全性
    • 简化了触摸事件和图像缩放的处理逻辑
    • 优化了图像和视频的渲染方式
  • 测试调整

    • 增强了图片预览组件的测试覆盖率,特别是交互和状态管理
    • 更新了自动播放和关闭图标相关的测试用例
    • 调整了测试中的超时时间和预期行为

xiaoyatong avatar Jan 14 '25 12:01 xiaoyatong

概述

演练

这个拉取请求主要修改了图像预览组件的样式和代码实现。在 imagepreview.scss 中,更新了 .nut-close.nut-pop.nut-imagepreview-swiper-item.nut-swiper-item 的样式,增加了嵌套类和响应式属性。在 imagepreview.taro.tsximagepreview.tsx 中,优化了类型定义、状态管理和事件处理逻辑,提高了组件的类型安全性和代码可读性。

变更

文件 变更摘要
src/packages/imagepreview/imagepreview.scss 新增嵌套类 .nut-icon,调整 .nut-pop 的样式,更新 .nut-imagepreview-swiper-item.nut-swiper-item 的嵌套样式
src/packages/imagepreview/imagepreview.taro.tsx 更新 onChange 方法签名,优化 useRef 类型,简化状态管理,重构触摸事件处理
src/packages/imagepreview/imagepreview.tsx 修改 ImagePreviewProps 接口,更新 defaultProps,简化 maxNo 计算,重构渲染逻辑
src/packages/imagepreview/__test__/imagepreview.spec.tsx 更新测试用例以反映组件行为的变化,包括 autoPlay 属性的移除和样式的修改

可能相关的问题

  • #2578: 解决图片预览组件中图片缩放问题
  • #2313: 改善图片预览时的图片显示和自适应性

可能相关的 PR

  • #2791: 修改图像和视频类的样式
  • #2793: 优化图像和视频元素布局
  • #2796: 更新图像预览组件的版本

建议标签

size/L

建议审阅者

  • xiaoyatong
  • oasis-cloud

诗歌

兔子的图像预览魔法,
样式优化,代码轻盈,
缩放自如,布局精妙,
响应迅速,性能飞扬,
预览世界,尽在掌握!🐰✨


📜 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 03236a315ff87b52726eb5e6f5630b9e9cbc3aca and 74448461ff6c20449e2b445523591528ec0c484c.

📒 Files selected for processing (1)
  • src/packages/imagepreview/__test__/imagepreview.spec.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/imagepreview/test/imagepreview.spec.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

coderabbitai[bot] avatar Jan 14 '25 12:01 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (36220ef) to head (37eecab). Report is 8 commits behind head on next.

Files with missing lines Patch % Lines
src/packages/imagepreview/imagepreview.tsx 96.36% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2941      +/-   ##
==========================================
+ Coverage   84.19%   84.67%   +0.48%     
==========================================
  Files         267      267              
  Lines       18099    18054      -45     
  Branches     2661     2672      +11     
==========================================
+ Hits        15238    15288      +50     
+ Misses       2856     2761      -95     
  Partials        5        5              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 14 '25 12:01 codecov[bot]

@coderabbitai

Miles-hxy avatar Jan 15 '25 12:01 Miles-hxy

@alex-huxiyang i'll review the changes in your pr that adds zoom functionality and optimizes the imagepreview component for taro.

:white_check_mark: Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jan 15 '25 12:01 coderabbitai[bot]

image 应该类似图中的缩放,只控制 img 或它的直接父亲容器。

小程序和 H5 中快速滑动会触发双击放大的交互

oasis-cloud avatar Jan 16 '25 01:01 oasis-cloud