Make initial state setup
distivi opened this issue · comments
Hi there, cool library! Thanks for that.
For my use case would be super nice to have initial state setup before actually presenting the dialog.
Basically what I need in method CropState
put my custom properties:
internal fun CropState(
src: ImageSrc,
transform: ImgTransform = ImgTransform.Identity, // add
shape: CropShape = RectCropShape, // add
// ... here the rest of parameters like aspectLock, initialAspectRatio, region etc.
onDone: () -> Unit = {},
): CropState = object : CropState {
val defaultTransform: ImgTransform = transform // modify
val defaultShape: CropShape = shape // modify
val defaultAspectLock: Boolean = false
override val src: ImageSrc get() = src
private var _transform: ImgTransform by mutableStateOf(defaultTransform)
override var transform: ImgTransform
get() = _transform
set(value) {
onTransformUpdated(transform, value)
_transform = value
}
val defaultRegion = src.size.toSize().toRect()
Or maybe having separate data class with initial values, then it could be used in reset function as well.
Thanks for the suggestion.
Currently, the CropState constuctor function is not part of the public api, also ImageCropper creates the instance internally. I guess in a future release you would have the option to pass your own CropState to ImageCropper::crop
.
In the meantime you can do something like this
val cropState = imageCropper.cropState
LaunchedEffect(key = cropState != null) {
cropState?.let { state ->
state.shape = TriangleCropShape
state.aspectLock = true
}
}
//.....
if (cropState != null) ImageCropperDialog(state = cropState)
Which would allow you change anything you want and would only be called once before the crop dialog is shown
Hope that helps !
Thanks for the suggestion. Currently, the CropState constuctor function is not part of the public api, also ImageCropper creates the instance internally. I guess in a future release you would have the option to pass your own CropState to
ImageCropper::crop
.In the meantime you can do something like this
val cropState = imageCropper.cropState LaunchedEffect(key = cropState != null) { cropState?.let { state -> state.shape = TriangleCropShape state.aspectLock = true } } //..... if (cropState != null) ImageCropperDialog(state = cropState)Which would allow you change anything you want and would only be called once before the crop dialog is shown Hope that helps !
Hope this coming soon. And give you a big thanks for the plugin
Hi! I'm using your library to implement a profile picture cropping feature. Ideally, I'd like to simplify the cropping experience for the user by limiting the options to a square crop with a fixed 1:1 aspect ratio.
I understand that the CropState constructor is not currently public, but I'm wondering if there could be a way to achieve this in a future release. Perhaps a parameter in the ImageCropper::crop function to set the initial aspect ratio and lock it, or a way to pass a custom CropState instance with the desired configuration.
This would greatly enhance the usability for profile picture cropping, as the only action required from the user would be to position and size the square cropping area.
Thanks again for your help and for developing this useful library!
Hi! I'm using your library to implement a profile picture cropping feature. Ideally, I'd like to simplify the cropping experience for the user by limiting the options to a square crop with a fixed 1:1 aspect ratio.
I understand that the CropState constructor is not currently public, but I'm wondering if there could be a way to achieve this in a future release. Perhaps a parameter in the ImageCropper::crop function to set the initial aspect ratio and lock it, or a way to pass a custom CropState instance with the desired configuration.
This would greatly enhance the usability for profile picture cropping, as the only action required from the user would be to position and size the square cropping area.
Thanks again for your help and for developing this useful library!
You can configure your cropState
variable such as:
LaunchedEffect(cropState) {
cropState?.let { state ->
state.shape = // Your impl. of a square shape
state.region = state.region.setAspect(1f)
}
}
// Prevent users from disabling aspect lock since we can't hide the aspect selection UI
LaunchedEffect(cropState?.aspectLock) {
cropState?.aspectLock = true
}
Thank you!
I get --> Unresolved reference: setAspect
on
state.region.setAspect(1f)
Thank you!
I get --> Unresolved reference: setAspect
on
state.region.setAspect(1f)
I copied from here and kept public for my usage.
Hey, thanks again for the code snippet and the link. I really appreciate your help!
Unfortunately, I'm still getting an "Unresolved reference: setAspect" error when I try to implement the function. I've tried defining the function in my file and importing it from an external library, but I'm still having trouble.
Could you take a look at my code and see if you can spot what I'm doing wrong?Here's the relevant part of my code:
LaunchedEffect(cropState) {
cropState?.let { state ->
state.shape = RectCropShape
state.region = state.region.setAspect(1f)
}
}