Skip to content

How to use it inside Compose? #672

@Franky4242

Description

@Franky4242

I have tried :
@composable
fun ComposableCropImageView(position: Int, setCropImageView: (CropImageView) -> Unit, force16_9: Boolean){
// Image Cropper fill the remaining available height
AndroidView(
factory = { context ->
Log.d(TAG, "in factory")
val uri = getPhotoUri(position)
var anaBitmap = getAnaBitmap(uri)
if (isHalfWidth){
anaBitmap = anaBitmap.scale(anaBitmap.width * 2, anaBitmap.height, false)
}
Log.d(TAG, "HERE")
CropImageView(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
setImageBitmap(anaBitmap)
setOnCropWindowChangedListener { onCropWindowChangedCallback(cropRect) }
setCropImageView(this) // Store the instance
Log.d(TAG, "end factory")
}

        },
        modifier = Modifier
            .fillMaxSize(),
        update = {cropImageView ->
            Log.d(TAG, "start update")
            if (force16_9) {
                cropImageView.setAspectRatio(16, 9)
                cropImageView.setFixedAspectRatio(true)
                sharedViewModel.setCropAspectRatio16x9(true)
            }
            else {
                cropImageView.setFixedAspectRatio(false)
                sharedViewModel.setCropAspectRatio16x9(false)
            }
            Log.d(TAG, "end update")
        }
    )
}

but adding this Composable to my screen makes a timeout while composition. and then a crash and a tombstone file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions