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(imagePreview): Added image preview ability to rotate images #13205

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

lzxiaoqi
Copy link
Contributor

Before submitting a pull request, please read the contributing guide.

在提交 pull request 之前,请阅读 贡献指南

#13153
上面issue中提到的ImagePreview组件增加图片的旋转功能
rotate

@codecov-commenter
Copy link

codecov-commenter commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 24 lines in your changes missing coverage. Please review.

Project coverage is 89.50%. Comparing base (e46ad73) to head (648dbac).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ckages/vant/src/image-preview/ImagePreviewItem.tsx 61.81% 19 Missing and 2 partials ⚠️
packages/vant/src/image-preview/ImagePreview.tsx 72.72% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13205      +/-   ##
==========================================
- Coverage   89.64%   89.50%   -0.14%     
==========================================
  Files         257      257              
  Lines        7008     7071      +63     
  Branches     1733     1745      +12     
==========================================
+ Hits         6282     6329      +47     
- Misses        382      396      +14     
- Partials      344      346       +2     

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

@inottn
Copy link
Collaborator

inottn commented Nov 16, 2024

感谢你的 PR!这个功能的实现可能比表面看起来更复杂,需要注意以下几点:

  1. 在 ImagePreview 组件中,图片预览会根据图片的长宽比例以 contain 或 cover 的方式显示。旋转图片时,也应遵循这一规则。仅调整旋转角度可能会导致四周出现黑边,或图片超出可视区域的问题。
  2. 使用 matrix 替代 rotate 属性值,同时保留原注释,避免因 Safari 的内部优化问题导致元素不渲染。
  3. 新增的 rotate 和 rotateAngle 属性可能显得冗余,考虑是否可以合并为一个属性。

@lzxiaoqi
Copy link
Contributor Author

@inottn 您好 按照优化建议调整了下。看是否可行
rotate

@inottn
Copy link
Collaborator

inottn commented Nov 24, 2024

抱歉回复晚了。我查看了许多相关的应用后,觉得我们可以将旋转行为限定为 90 度,不支持其他角度。暂时没有想到用户需要非 90 度旋转的场景,这样的设计也能让代码更简洁。

@lzxiaoqi
Copy link
Contributor Author

@inottn 有道理 已经调整

@inottn
Copy link
Collaborator

inottn commented Nov 30, 2024

测试了下,当旋转后双击放大,拖动时的边界似乎有问题。

@lzxiaoqi
Copy link
Contributor Author

lzxiaoqi commented Dec 2, 2024

确实是有这个问题,这次修改 maxMoveX 和 maxMoveY 的计算逻辑,考虑旋转后的尺寸和缩放比例,我试了下应该是正常的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants