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

[BUG] - Image disappears in CropImageActivity after configuration change #296

Closed
samiuelson opened this issue Jan 2, 2022 · 6 comments · Fixed by #335
Closed

[BUG] - Image disappears in CropImageActivity after configuration change #296

samiuelson opened this issue Jan 2, 2022 · 6 comments · Fixed by #335

Comments

@samiuelson
Copy link

  • Lib Version 4.0.0
  • Reproducible in the sample app

Describe the bug
The cropped image disappears in CropImageActivity on any configuration change (e.g. screen rotation, device theme switch).

To Reproduce
Steps to reproduce the behavior in the sample app:

  1. Go to 'Sample of custom activity'
  2. Pick an image from storage or from the camera
  3. Image is displayed correctly
  4. Rotate the screen to landscape (or invoke any other configuration change, e.g. switch device's theme from light to dark)
  5. Image disappears (it's not visible also when going back to portrait)

Expected behavior
The state (image uri, crop, rotation, etc) should be preserved across configuration changes.

Media

rotation_issue.mp4

Smartphone (please complete the following information):

  • Device: Pixel 4a 5G
  • OS: Android API 31

Additional context
Happens both in the sample app, and in my own app using CropImageActivity launched in the following way:

options(uri = imageUri) {
    setGuidelines(CropImageView.Guidelines.ON)
    setAllowFlipping(false)
    setActivityTitle("Adjust Image")
    setCropMenuCropButtonTitle("Save")
}
@samiuelson samiuelson added the bug label Jan 2, 2022
@Canato
Copy link
Member

Canato commented Jan 5, 2022

Hey, sorry for the lack of answers here.

I'm on vacation and traveling until 18/01. Just after this I will have the attention of this repository.

Do not need to wait for me, just letting people know as I'm the main maintenance

@Canato
Copy link
Member

Canato commented Jan 18, 2022

Indeed, an issue. Happy to someone drop a PR fixing it ^^

@yoijoe4
Copy link

yoijoe4 commented Jan 19, 2022

Hi, guys :) . This issue is indeed unfitting of this great image-cropper library.
I have tested some different versions and it seems this issue started in release '3.3.4'.
Release '3.2.2.' works fine when the screen rotates.

For now, if you want to make the issue less noticable (THIS IS NOT A FIX):
For now you can set screenOrientation to portrait in the Manifest File (sacrifice of User-Experience). Device theme switch or locale switch will still break the behavior, but it's safe to say these use-cases are less likely to happen.

<application
	
        <activity android:name="com.canhub.cropper.CropImageActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Base.Theme.AppCompat"/> <!-- default theme has no action bar -->

</application>

@Canato
Copy link
Member

Canato commented Jan 19, 2022

@yoijoe4 thanks for searching this!

@samiuelson this work for you?

Please any of you feel free to drop a PR fixing it ^^

@samiuelson
Copy link
Author

samiuelson commented Jan 19, 2022

This is not a solution. Configuration change happens not only during screen rotation but also on theme switch, locale change, etc. Events like those also break the behavior.

My preferred solution would be to implement ViewModel for CropImageActivity which would survive configuration changes. The ViewModel would intercept user/UI events from CropImageActivity and compute and expose the current UI state. The activity would collect the state from view model and render it.

@yoijoe4
Copy link

yoijoe4 commented Jan 19, 2022

@samiuelson You are totally right. I forgot to mention that and I have changed my comment accordingly.

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

Successfully merging a pull request may close this issue.

3 participants