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

ImageView.load no longer calls ImageRequest.Builder methods #1257

Closed
dafi opened this issue May 4, 2022 · 1 comment · Fixed by #1260
Closed

ImageView.load no longer calls ImageRequest.Builder methods #1257

dafi opened this issue May 4, 2022 · 1 comment · Fixed by #1260

Comments

@dafi
Copy link

dafi commented May 4, 2022

Describe the bug
I updated my project from 1.4.0 to 2.0.0-rc03 and the following code stopped to work

        thumbImage.load("https://myurl.com") {
            placeholder(R.drawable.stub)
            target(object : ImageViewTarget(thumbImage) {
                override fun onStart(placeholder: Drawable?) {
                    System.err.println("dafi: PhotoGridViewHolder.onStart ")
                }
                override fun onSuccess(result: Drawable) {
                    System.err.println("dafi: PhotoGridViewHolder.onSuccess ")
                }
            })
        }

The methods onStart and onSuccess are correctly called under 1.4.0 but no longer called after the library update

After some investigation I copied the ImageView.load code discovering the call to target bypasses the calls to the ImageRequest.Builder passed to it, indeed the code below works fine but the lambda inside the apply is never called

        val viewContext = itemView.context
        val request = ImageRequest.Builder(viewContext)
            .apply {
                target { System.err.println("dafi: PhotoGridViewHolder.displayImage target from apply is not called") }
            }
            .data("https://myurl.com")
            .target(object : ImageViewTarget(thumbImage) {
                override fun onStart(placeholder: Drawable?) {
                    System.err.println("dafi: PhotoGridViewHolder.onStart " + placeholder)
                }
                override fun onSuccess(result: Drawable) {
                    System.err.println("dafi: PhotoGridViewHolder.onSuccess ")
                }
            })
            .build()
        viewContext.imageLoader.enqueue(request)

Is this a regression? I searched the documentation for some new behaviour but without success.

I repeat the first code snippet correctly works on 1.4.0.
To make the code working on 2.0.0-rc03 I need to patch it and pass ImageViewTarget directly to the request to enqueue,

This makes ImageView.load useless if not worse harmful

@colinrtwhite
Copy link
Member

colinrtwhite commented May 6, 2022

I think you're right that this change is unexpected in 2.x; fixed here. That said, I wouldn't recommend using load if you want to set a custom target. It's expected that your second code snippet won't have the first target called since you're overwriting it. It looks like your use case would be better suited by a listener.

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.

2 participants