Omkar Amberkar
09/01/2023, 4:23 PMBox
to it's child GlideImage
? if so, whats the best way to do that?Casey Brooks
09/01/2023, 4:28 PMBoxWithConstraints
can give you the box’s dimensions. Though it should be noted that it uses SubcomposeLayout
so has a bit of a performance penalty.Francesc
09/01/2023, 4:38 PMonPlaced
but this comes with a 1 frame delay, but doesn't have the penalty of BoxWithConstraints
. Alternatively, you can use Layout
which has neither the penalty nor the delay, but it's a bit more involvedZach Klippenstein (he/him) [MOD]
09/01/2023, 4:44 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 4:45 PMOmkar Amberkar
09/01/2023, 4:56 PMOmkar Amberkar
09/01/2023, 4:58 PMBox
through using onSizeChanged
and then uses that to pass down to GlideImage, but wondering if there is a better wayKonstantin Tskhovrebov
09/01/2023, 5:02 PMFrancesc
09/01/2023, 5:09 PM@Composable
fun RemoteImage(
url: String,
modifier: Modifier = Modifier,
) {
var updatedUrl by remember { mutableStateOf(Uri.EMPTY) }
Layout(
modifier = modifier,
content = {
AsyncImage(
model = updatedUrl,
contentDescription = null,
)
}
) { measurables, constraints ->
val placeable = measurables[0].measure(constraints)
layout(
width = constraints.maxWidth,
height = constraints.maxHeight,
) {
updatedUrl = Uri.parse(url).buildUpon()
.appendQueryParameter("w", constraints.maxWidth.toString())
.appendQueryParameter("h", constraints.maxHeight.toString())
.build()
placeable.place(0, 0)
}
}
}
Omkar Amberkar
09/01/2023, 5:14 PMFrancesc
09/01/2023, 5:15 PMonSizeChanged
Omkar Amberkar
09/01/2023, 5:20 PMOmkar Amberkar
09/01/2023, 5:44 PMonSizeChanged
have the same performance issue of 1 frame delay?Zach Klippenstein (he/him) [MOD]
09/01/2023, 5:51 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 5:52 PMonSizeChanged
, onPlaced
, onGloballyPositioned
, etc don’t inherently have a frame delay, the delay comes from data flowing “backwards”Omkar Amberkar
09/01/2023, 5:52 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 5:53 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 5:54 PMAsyncImage
would need some way for you to pass it an object that can retrieve the URL lazily, e.g. a () -> URL
.Zach Klippenstein (he/him) [MOD]
09/01/2023, 5:54 PMAsyncImage
does not internally need to actually know the URL at composition timeOmkar Amberkar
09/01/2023, 5:54 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 5:58 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 6:00 PMAsyncImagePainter
and set the request property from measurement? But i’m not sure if that would actually workOmkar Amberkar
09/01/2023, 6:00 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 6:05 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 6:05 PMOmkar Amberkar
09/01/2023, 6:15 PMZach Klippenstein (he/him) [MOD]
09/01/2023, 6:36 PMOmkar Amberkar
09/01/2023, 6:39 PMKonstantin Tskhovrebov
09/02/2023, 6:58 AMStylianos Gakis
09/02/2023, 1:38 PMandroidx.compose.ui.layout.onSizeChanged
instead of onGloballyPositioned
since you only care for the size.
Also not sure about the fillMaxSize
on that Image itself, would that sometimes make the image take more space than it needs to?