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

@uppy/image-editor: respect cropperOptions.initialAspectRatio #4805

Merged
merged 8 commits into from
Nov 27, 2023
8 changes: 6 additions & 2 deletions packages/@uppy/image-editor/src/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class Editor extends Component {
}

renderRevert () {
const { i18n } = this.props
const { i18n, opts } = this.props

return (
<label
Expand All @@ -140,7 +140,11 @@ export default class Editor extends Component {
className="uppy-u-reset uppy-c-btn"
onClick={() => {
this.cropper.reset()
this.cropper.setAspectRatio(0)
if (opts.cropperOptions.initialAspectRatio) {
Copy link
Member

@Murderlon Murderlon Nov 27, 2023

Choose a reason for hiding this comment

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

Instead of doing this conditionally here, probably better to set a default in the constructor and then we can just pass the option.

const defaultCropperOptions = {
viewMode: 0,
background: false,
autoCropArea: 1,
responsive: true,
minCropBoxWidth: 70,
minCropBoxHeight: 70,
croppedCanvasOptions: {},
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! I also think that setting default values in the constructor and then passing options to override these default values may be a clearer and more maintainable approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, let's do

const defaultCropperOptions = {
   //...current stuff,
  initialAspectRatio: 0
}

and then do

this.cropper.reset()
this.cropper.setAspectRatio(opts.cropperOptions.initialAspectRatio)

Agreed with the change otherwise!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for accepting my suggestion!

this.cropper.setAspectRatio(opts.cropperOptions.initialAspectRatio);
} else {
this.cropper.setAspectRatio(0);
}
this.setState({ angle90Deg: 0, angleGranular: 0 })
}}
>
Expand Down