Colton Idle
03/03/2021, 2:57 AMfun ImageView.loadImageToSize(url: String) {
this.doOnLayout { <--- ktx method that replaced OnGlobalLayoutListener
// it.width and it.height are accessible here
...
}
Albert Chang
03/03/2021, 3:01 AMrequestBuilder
parameter of GlideImage
is giving you an IntSize
which is the size.
https://github.com/chrisbanes/accompanist/blob/main/glide/src/main/java/dev/chrisbanes/accompanist/glide/GlideImage.kt#L106Albert Chang
03/03/2021, 3:03 AMBoxWithConstraints
.Colton Idle
03/03/2021, 3:07 AMColton Idle
03/03/2021, 3:08 AMGlideImage(
data = imageUrl,
contentDescription = null,
requestBuilder = {
size: IntSize -> //set imageUrl to have size.height and size.width?
}
)
eygraber
03/03/2021, 3:10 AMColton Idle
03/03/2021, 3:12 AMAlbert Chang
03/03/2021, 3:15 AMRequestBuilder.load(newUri)
?Colton Idle
03/03/2021, 3:20 AMrequestBuilder
but I think I have something that'll work
GlideImage(
data = imageUrl,
contentDescription = null,
requestBuilder = { size: IntSize ->
data(imageUrl + "?width=" + size.width)
}
)
Running now... 🤞eygraber
03/03/2021, 3:24 AMColton Idle
03/03/2021, 3:24 AMColton Idle
03/03/2021, 3:34 AMAlbert Chang
03/03/2021, 3:44 AMBoxWithConstraints
, which is what accompanist is using internally, you'll get the size before the request is made, so you don't need a thumbnail anyway.Colton Idle
03/03/2021, 3:44 AMGlideImage(
data = imageUrl,
contentDescription = null,
requestBuilder = { size: IntSize ->
data(imageUrl + "?width=" + size.width +"&height=" + size.height)
}
)
Really easy! The only thing if Chris Banes is maybe listening in is do you think it's worth filing a bug report to be able to omit the initial data = ...
if I load data()
in the requestBuilder
? Or is it such a minor thing that it's not worth it?