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

Loading images into "gone" Views cause downsampling to 1x1 BitmapDrawable #387

Closed
littledot opened this issue May 3, 2020 · 1 comment · Fixed by #397
Closed

Loading images into "gone" Views cause downsampling to 1x1 BitmapDrawable #387

littledot opened this issue May 3, 2020 · 1 comment · Fixed by #397
Labels
bug Something isn't working

Comments

@littledot
Copy link

littledot commented May 3, 2020

Describe the bug

Consider the following layout:

<FrameLayout xmlns:android="https://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/img1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:visibility="gone" />
</FrameLayout>

When Coil loads an image into a View whose visibility is "gone", it will downsample the image into a 1x1 BitmapDrawable.

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main)

        val src =
            "https://pbs.twimg.com/profile_images/378800000666093975/cbe970ce9a19d2c6bec0d06c6004ccf0_400x400.png"

        Coil.loadAny(this, src) {
            target(img1)
            listener { request, source ->
                img1.visibility = View.VISIBLE
            }
        }
    }
}

Expected behavior

I think other libraries won't even start loading the image until the target View has valid dimensions.

I think it has something to do with this size resolver.

To Reproduce

Run the project: https://gitlab.com/littledot/android-bug-report

Logs/Screenshots

Version
Coil 0.10.1

@littledot littledot added the bug Something isn't working label May 3, 2020
@colinrtwhite
Copy link
Member

Thanks for the repro project! I think this is due to ViewSizeResolver waiting at most one layout pass for valid dimensions when instead we should wait as many as needed. Will have a fix up soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants