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

ImageEditor crop but don't reset state therefore closing everything #27

Open
vanniktech opened this issue Nov 28, 2024 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@vanniktech
Copy link

My use case is the following, users can either pick an image from the Gallery or take an Image with the Camera. I want to constrain the aspect ratio to 1:1 (which I can already do!). The user can select which part of the image should be selected and if wanted, zoom into a specific part. Now comes the important part, when the user uses that images I want to upload it right away to the backend. This would happen right now when pressing the check icon:

Screenshot 2024-11-28 at 16 18 31

I've provided my custom toolbar and I am calling cropState.done(true). Now if the backend decides the picture isn't good enough for any of the reasons (like it's too small, too blurry etc), I want that the user can stay in that same picker and give it another try. As far as I can see this isn't possible. The problem is here:

val newCrop = cropState(src) { cropState = null }

By setting the crop state to null, the moment the image has been cropped it closes. Would you be open to change the behavior such that you can crop but the user is responsable for tearing the image picker down?

@tamimattafi
Copy link
Owner

@vanniktech This seems like a very common use-case and needs to be addressed.

Do you have any suggestions on how the crop api should look like?

Maybe we should add another crop function that accepts a lambda and closes the dialog only if we return true (as valid).

Or maybe we should make the state more exportable so we can save it, and restore it if the backend returns an error. So the same image with the same grid positions will be loaded.

@tamimattafi tamimattafi added the enhancement New feature or request label Nov 28, 2024
@vanniktech
Copy link
Author

Do you have any suggestions on how the crop api should look like?

Not yet. I'm new in Compose land and haven't gotten enough understanding of how an ideal API would look like.

Or maybe we should make the state more exportable so we can save it, and restore it if the backend returns an error. So the same image with the same grid positions will be loaded.

From gut feeling this feels like the better solution. At least the fact that the state of the image cropping should be preserved and you should not need to start from scratch again.

@vanniktech
Copy link
Author

Maybe something along the lines of: https://mohamedrejeb.github.io/Calf/ui/

Screenshot 2024-12-10 at 18 34 20

Where inside of state you have a boolean if the button (done) has been pressed and also a way to obtain the BitMap. And then you can do whatever you want and if you want to close it you could call some function on state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants