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: 支持图片旋转 #1

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

Conversation

Envl
Copy link

@Envl Envl commented Jul 1, 2021

  • 增加一个 state: rotate 控制图片旋转 css
  • 新增 1 个 prop: enableRotate ,默认为 true
  • 新增 1 个 event prop: onImageRotate 图片旋转后,会将顺时针旋转角度作为参数执行回调
    • 可能取值如下:090180270
  • css 中增加两个表示旋转的 svg 按钮

核心改动看下面链接那个 PR 就行,这边多出来的改动都是因为加上了旋转动画(因为实际体验发现没有旋转动画有时候看到突然的图片方向变动有些错愕,一下子识别不出来图片的朝向)
https://github.com/frontend-collective/react-image-lightbox/pull/438/files

x = 0,
y = 0,
zoom = 1,
rotate = 0,
Copy link
Author

Choose a reason for hiding this comment

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

增加的参数,控制旋转。本函数用来生成 transform css。

@Envl Envl force-pushed the feat-rotate-image-css branch 3 times, most recently from f0985f2 to 25d4f5f Compare July 1, 2021 15:08
const isRotateRight270 = direction === 'right' && rotate === 270;
const isRotateLeft0 = direction === 'left' && rotate === 0;

if (isRotateRight270 || isRotateLeft0) {
Copy link
Author

Choose a reason for hiding this comment

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

避免出现旋转 270/360 度的动画

degree = 360 - (-degree % 360);
}

if (this.props.animationDisabled) {
Copy link
Author

Choose a reason for hiding this comment

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

现有代码其他地方就是这么做的,保持一致。
做的事是这样:

  1. 开启动画(css 加上 transition)
  2. 等动画播完后,关闭动画
  3. 再让按钮重获 focus,以响应键盘事件
    • ESC、左右方向键

this.setTimeout(() => this.requestMove(direction, event));
return;
}
// Reset the zoom level & rotation on image move
Copy link
Author

Choose a reason for hiding this comment

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

避免切换图片时发生 270 度旋转动画

let transitionStyle = {};
let transitionStyle = {
transition: 'transform 0s',
};

Copy link
Author

Choose a reason for hiding this comment

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

在 chromium 中,如果 transition 属性本来为空,临时加上的话,不会播放旋转动画。所以放入一个 placeholder。

- added 2 buttons with icons ( rotate left & rotate right)

fix: 避免 0 --> 270 度旋转动画的产生

feat: demo 打印旋转后的角度

fix: typo & bind this & focus on button & aria label

fix: typo & bind this & focus on button & aria label
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.

1 participant