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

Add zoomSpeed-prop and use it to multiply the wheelzoom #21

Merged
merged 2 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class App extends React.Component {
| `maxZoom` | number | | maximum zoom of the image. Defaults to 3. |
| `cropShape` | 'rect' \| 'round' | | Shape of the crop area. Defaults to 'rect'. |
| `showGrid` | boolean | | Whether to show or not the grid (third-lines). Defaults to `true`. |
| `zoomSpeed` | number | | Multiplies the value by which the zoom changes. Defualts to 1. |
TheRealSlapshot marked this conversation as resolved.
Show resolved Hide resolved
| `onCropChange` | Function | ✓ | Called everytime the crop is changed. Use it to update your `crop` state.|
| `onZoomChange` | Function | | Called everytime the zoom is changed. Use it to update your `zoom` state. |
| [`onCropComplete`](#onCropCompleteProp) | Function | | Called when the user stops moving the image or stops zooming. It will be passed the corresponding cropped area on the image in percentages and pixels |
Expand Down
2 changes: 2 additions & 0 deletions examples/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class App extends React.Component {
aspect: 4 / 3,
cropShape: 'rect',
showGrid: true,
zoomSpeed: 1,
}

onCropChange = crop => {
Expand All @@ -40,6 +41,7 @@ class App extends React.Component {
aspect={this.state.aspect}
cropShape={this.state.cropShape}
showGrid={this.state.showGrid}
zoomSpeed={this.state.zoomSpeed}
onCropChange={this.onCropChange}
onCropComplete={this.onCropComplete}
onZoomChange={this.onZoomChange}
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Cropper extends React.Component {
onWheel = e => {
e.preventDefault()
const point = Cropper.getMousePoint(e)
const newZoom = this.props.zoom - e.deltaY / 200
const newZoom = this.props.zoom - (e.deltaY * this.props.zoomSpeed) / 200
Copy link
Owner

Choose a reason for hiding this comment

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

I don't really like the hardcoded 200 value. Do you think we could combine it with the zoomSpeed property (and keep "approximatively" the same behavior as today)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see, how we can combine this.
We could extract the hardcoded number to a class constant, but this is out of scope of this PR in my opinion.

Copy link
Owner

Choose a reason for hiding this comment

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

OK it's fine to me.

this.setNewZoom(newZoom, point)
}

Expand Down Expand Up @@ -300,6 +300,7 @@ Cropper.defaultProps = {
showGrid: true,
style: {},
classes: {},
zoomSpeed: 1,
}

export default Cropper