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

Conversation

Lucklj521
Copy link
Contributor

Problem Description:
When using the "reset" to reset the image, we believe that setAspectRatio should be set to the initialAspectRatio of cropperOptions, instead of 0. The rationality of this behavior is questionable.

Use Case:
In the scenario of uploading a profile picture using Uppy's imageEditor, the initial aspect ratio of Uppy is set to 1/1. Within this setting, we only retained the three buttons: "reset", "zoomIn", and "zoomOut". However, after clicking the "revert" button on the image, the aspect ratio becomes ineffective.

Suggested Improvement:
To maintain the stability of the aspect ratio after the "reset" operation, we suggest setting setAspectRatio to the initialAspectRatio of cropperOptions, so as to maintain the aspect ratio in its initial state instead of setting it to 0. This way, the image can maintain its original aspect ratio after the "revert" operation, which aligns better with user expectations.

@@ -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!

@Murderlon Murderlon changed the title Suggestion on Rationality of Setting setAspectRatio upon “reset” Action @uppy/image-editor: respect cropperOptions.initialAspectRatio Nov 27, 2023
@@ -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
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!

} else {
this.cropper.setAspectRatio(0);
}
this.cropper.setAspectRatio(opts.cropperOptions.initialAspectRatio);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it go through the linter fine? I think it should compain about ;

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'm sorry, it was my oversight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I pass the review now?

@Murderlon Murderlon merged commit f2cce79 into transloadit:main Nov 27, 2023
19 checks passed
Murderlon added a commit that referenced this pull request Dec 5, 2023
* main:
  Migrate to AWS-SDK V3 syntax (#4810)
  @uppy/utils: fix import in test files (#4806)
  Fix onBeforeFileAdded with Golden Retriever (#4799)
  @uppy/image-editor: respect `cropperOptions.initialAspectRatio` (#4805)
  Release: uppy@3.20.0 (#4804)
@github-actions github-actions bot mentioned this pull request Dec 12, 2023
github-actions bot added a commit that referenced this pull request Dec 12, 2023
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3           |   3.6.0 | @uppy/instagram        |   3.2.0 |
| @uppy/aws-s3-multipart |  3.10.0 | @uppy/onedrive         |   3.2.0 |
| @uppy/box              |   2.2.0 | @uppy/provider-views   |   3.8.0 |
| @uppy/companion        |  4.12.0 | @uppy/store-default    |   3.2.0 |
| @uppy/companion-client |   3.7.0 | @uppy/tus              |   3.5.0 |
| @uppy/core             |   3.8.0 | @uppy/url              |   3.5.0 |
| @uppy/dropbox          |   3.2.0 | @uppy/utils            |   5.7.0 |
| @uppy/facebook         |   3.2.0 | @uppy/xhr-upload       |   3.6.0 |
| @uppy/google-drive     |   3.4.0 | @uppy/zoom             |   2.2.0 |
| @uppy/image-editor     |   2.4.0 | uppy                   |  3.21.0 |

- @uppy/provider-views: fix uploadRemoteFile undefined (Mikael Finstad / #4814)
- @uppy/companion: fix double tus uploads (Mikael Finstad / #4816)
- @uppy/companion: fix accelerated endpoints for presigned POST  (Mikael Finstad / #4817)
- @uppy/companion: fix `authProvider` property inconsistency (Mikael Finstad / #4672)
- @uppy/companion:  send certain onedrive errors to the user (Mikael Finstad / #4671)
- meta: fix typo in `lockfile_check.yml` name (Antoine du Hamel)
- @uppy/aws-s3: change Companion URL in tests (Antoine du Hamel)
- @uppy/set-state: fix types (Antoine du Hamel)
- @uppy/companion: Provider user sessions (Mikael Finstad / #4619)
- meta: fix `js2ts` script on Node.js 20+ (Merlijn Vos / #4802)
- @uppy/companion-client: avoid unnecessary preflight requests (Antoine du Hamel / #4462)
- meta: Migrate to AWS-SDK V3 syntax (Artur Paikin / #4810)
- @uppy/utils: fix import in test files (Antoine du Hamel / #4806)
- @uppy/core: Fix onBeforeFileAdded with Golden Retriever (Merlijn Vos / #4799)
- @uppy/image-editor: respect `cropperOptions.initialAspectRatio` (Lucklj521 / #4805)
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