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

Android 13 (SDK 33): CropImageView white on some Samsung devices #599

Closed
manuel-tud opened this issue Nov 7, 2023 · 10 comments
Closed

Android 13 (SDK 33): CropImageView white on some Samsung devices #599

manuel-tud opened this issue Nov 7, 2023 · 10 comments

Comments

@manuel-tud
Copy link

Hi,
I've an app with 100k+ installs out there. Recently I've updated the target SDK version to 33 without changing anything on the image cropping code. Since that update I receive lots of complaints from users with various (not all) Samsung devices running Android 13 saying that the CIV doesn't load the chosen image and just stays white.
I load the image using the setImageUriAsync() method. Unfortunately I was not able to reproduce that bug on my test devices (which are not made by Samsung). I was also not able to reproduce it using Samsung's Test Lab devices.
But by the amount of bug report messages (including screenshots showing the behavior) I get, I can say for sure, that there is a bug.

(This could by the same bug mentioned here: #593)

@vanniktech
Copy link
Contributor

Can you reproduce and try to submit a PR which fixes this?

@anmol14dev
Copy link

Facing same issue on my samsung device. I can see the image with crop square but white screen all around.

@Devenom1
Copy link
Contributor

Same issue here. But not just Samsung Phones. Motorola phones too. I don't have direct access to the devices facing the issue.

@HamzaAkram-shyk
Copy link

Facing the same issue on my Vivo device. I can see the image with a crop square but a white screen all around. there is no option to go back and get the cropped image's Uri.

@kevschweitzer
Copy link

kevschweitzer commented Dec 29, 2023

Same issue here. I Could handle it by implementing a CustomCropImageActivity as stated in documentation and in sample app.

Custom activity code

import android.net.Uri
import android.os.Bundle
import com.canhub.cropper.CropImageActivity
import dac.corp.dactive.databinding.ActivityCustomCropImageBinding

class CustomCropImageActivity : CropImageActivity() {

    private lateinit var binding: ActivityCustomCropImageBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        binding = ActivityCustomCropImageBinding.inflate(layoutInflater)
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        setListener()
        setCropImageView(binding.cropImageView)
    }

    private fun setListener() {
        binding.button.setOnClickListener { cropImage() }
    }

    override fun onPickImageResult(resultUri: Uri?) {
        super.onPickImageResult(resultUri)

        if (resultUri != null) {
            binding.cropImageView.setImageUriAsync(resultUri)
        }
    }
}

Custom Activity Layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".utilities.CustomCropImage.CustomCropImageActivity">

    <com.canhub.cropper.CropImageView
        android:id="@+id/cropImageView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Accept"
        app:layout_constraintTop_toBottomOf="@id/cropImageView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

And this is the code to start the activity.

  1. You register the activity for result with a new Contract I created to change the Activity that will start (to put my own). I left it below
  2. You launch the activity in some button with the options you want (in my case I only wanted gallery and a square aspect ratio).
private val cropImage = registerForActivityResult(CustomCropImageContract()) { result ->
        if (result.isSuccessful) {
            result.uriContent?.let {
                val bitmap = mapUriToBitmap(it)
                viewModel.setNewPhoto(bitmap)
            }
        }
    }

//In some button you launch the activity
cropImage.launch(
                CropImageContractOptions(null, CropImageOptions(
                    imageSourceIncludeGallery = true,
                    imageSourceIncludeCamera= false,
                    fixAspectRatio = true
                ))
            )

The custom contract here

class CustomCropImageContract : ActivityResultContract<CropImageContractOptions, CropImageView.CropResult>() {
    override fun createIntent(context: Context, input: CropImageContractOptions) = Intent(context, CustomCropImageActivity::class.java).apply {
        putExtra(
            CropImage.CROP_IMAGE_EXTRA_BUNDLE,
            Bundle(2).apply {
                putParcelable(CropImage.CROP_IMAGE_EXTRA_SOURCE, input.uri)
                putParcelable(CropImage.CROP_IMAGE_EXTRA_OPTIONS, input.cropImageOptions)
            },
        )
    }

    override fun parseResult(
        resultCode: Int,
        intent: Intent?,
    ): CropImageView.CropResult {
        val result = intent?.parcelable<CropImage.ActivityResult>(CropImage.CROP_IMAGE_EXTRA_RESULT)

        return if (result == null || resultCode == Activity.RESULT_CANCELED) {
            CropImage.CancelledResult
        } else {
            result
        }
    }
}

@Alex-Dobrynin
Copy link

@vanniktech
Same here. Will this be fixed?

@SourabhSuman007
Copy link

@vanniktech Is this issue fixed in the latest release?

@vanniktech
Copy link
Contributor

Has something changed since my last comment? #599 (comment)

@omiwrench
Copy link

Same issue here, using a Pixel 6 emulator with API 34.

@vanniktech
Copy link
Contributor

Roll your own activity and just use the CropImageView. Or alternatively use the workaround: #599 (comment)

Long term, I want to get rid of all the contracts & CropImageActivity.

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

No branches or pull requests

9 participants