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

fix: fix the error of image rotating too many times after reseting image #3108

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

sylsaint
Copy link
Contributor

@sylsaint sylsaint commented Sep 18, 2024

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

要解决的问题:修复图片预览旋转多次之后,点击重置后,图片旋转太多次的问题

实现方案:修改 useRotate 这个 hooks, 旋转多次之后, 寻找到离整除 360° 最近的角度,进行旋转, 而不是强制的将角度设置为 0

修改前:
screencast-tdesign_tencent_com-2024_09_18-17_41_37.webm

修改后:
screencast-localhost_15000-2024_09_18-17_42_35.webm

📝 更新日志

  1. 修复图片预览旋转多次之后,点击重置后,图片旋转太多次的问题
  • fix(组件名称): ImageViewer

  • 本条 PR 不需要纳入 Changelog

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

Copy link
Contributor

完成

@uyarn uyarn merged commit d41a2db into Tencent:develop Sep 18, 2024
7 checks passed
}, []);

const onResetRotate = useCallback(() => setRotateZ(0), []);
const onResetRotate = useCallback(() => {
let degreeToRotate = rotRef.current % 360;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should take the remainder of 360 every time we rotate, instead of calculating it when resetting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purpose of calculating the degree is to get the minimal rotating degree to which can be divided by 360° exactly. In Tdesign react, the image rotate anti-clockwise, so there are four angle remainders which are 0, -90, -180, -270. If remainder is -270, it will cause image to rotate 270°, that's why calculating happens. The calculating will always get the minimal degree to rotate.

@github-actions github-actions bot mentioned this pull request Sep 26, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants