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

RequestListener.onResourceReady was called twice in Compose. #5032

Closed
lyh8577 opened this issue Feb 25, 2023 · 1 comment · Fixed by #5062
Closed

RequestListener.onResourceReady was called twice in Compose. #5032

lyh8577 opened this issue Feb 25, 2023 · 1 comment · Fixed by #5062

Comments

@lyh8577
Copy link

lyh8577 commented Feb 25, 2023

Glide Version:
implementation 'com.github.bumptech.glide:glide:4.15.0'
kapt 'com.github.bumptech.glide:compiler:4.15.0'
implementation "com.github.bumptech.glide:okhttp3-integration:4.15.0"
implementation "com.github.bumptech.glide:compose:1.0.0-alpha.2"

Device/Android Version:
Android Emulator - Resizable - Android 13 Goolge APIs | x86_64

Issue details / Repro steps / Use case background:
I added a RequestListener because I wanted to get the loading status, and as a result onResourceReady was called twice, each time with a different target object

Glide load line / GlideModule (if any) / list Adapter code (if any):

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            GlideDemoTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    debug("Surface")
                    Greeting()
                }
            }
        }
    }
}

fun debug(message: String) {
    Log.d("MainActivity", message)
}

@OptIn(ExperimentalGlideComposeApi::class)
@Composable
fun Greeting() {
    debug("Greeting")
    GlideImage(model = "https://picsum.photos/300/300", contentDescription = null) {
        debug("addListener")
        it.addListener(object : RequestListener<Drawable> {
            override fun onLoadFailed(
                e: GlideException?,
                model: Any?,
                target: Target<Drawable>?,
                isFirstResource: Boolean
            ): Boolean {
                debug("onLoadFailed")
                return false
            }

            override fun onResourceReady(
                resource: Drawable?,
                model: Any?,
                target: Target<Drawable>?,
                dataSource: DataSource?,
                isFirstResource: Boolean
            ): Boolean {
                debug("onResourceReady $resource $model $target")
                return false
            }
        })
    }
}

Stack trace / LogCat:

2023-02-25 17:22:23.757 27202-27202 MainActivity            com.example.glidedemo                  D  Surface
2023-02-25 17:22:23.757 27202-27202 MainActivity            com.example.glidedemo                  D  Greeting
2023-02-25 17:22:23.787 27202-27202 MainActivity            com.example.glidedemo                  D  addListener
2023-02-25 17:22:23.846 27202-27230 MainActivity            com.example.glidedemo                  D  onResourceReady android.graphics.drawable.BitmapDrawable@9d43df7 https://picsum.photos/300/300 com.bumptech.glide.integration.ktx.FlowTarget@a670a3f
2023-02-25 17:22:23.847 27202-27230 MainActivity            com.example.glidedemo                  D  onResourceReady android.graphics.drawable.BitmapDrawable@e49d464 https://picsum.photos/300/300 com.bumptech.glide.integration.ktx.FlowTarget@e27aa6a

Finally

Easier access to loading status. eg: when use Placeholder

GlideDemo.zip

@sjudd
Copy link
Collaborator

sjudd commented Mar 10, 2023

Thanks for the report and sample app! I'll send a fix soon.

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

Successfully merging a pull request may close this issue.

2 participants