Hammad Akram
07/27/2023, 12:28 PM@Composable
fun Image(
imageUrl: String,
placeholder: Painter,
contentDescription: String,
modifier: Modifier = Modifier,
) {
var size: IntSize by remember { mutableStateOf(IntSize.Zero) }
val url by remember(size) {
derivedStateOf {
if (size == IntSize.Zero) {
imageUrl
} else {
addOrUpdateQueryParameter(
url = imageUrl,
queryParam = WidthParam to size.width
)
}
}
}
AsyncImage(
model = url,
placeholder = placeholder,
contentDescription = contentDescription,
modifier = modifier.onGloballyPositioned {
if (it.size != IntSize.Zero) {
size = it.size
}
}
)
}
Ivan Cagle (IvanEOD)
07/27/2023, 1:30 PMHammad Akram
07/27/2023, 3:11 PM@Composable
fun ImageItem(
imageUrl: String,
onImageClick: () -> Unit = {}
) {
Image(
imageUrl = imageUrl,
placeholder = painterResource(R.drawable.placeholder_2_3),
contentDescription = "Product Image",
modifier = Modifier
.aspectRatio(2 / 3f)
.testTag(imageUrl)
.clickable { onImageClick() }
.fillMaxSize())
}
Ivan Cagle (IvanEOD)
07/27/2023, 3:17 PMHammad Akram
07/27/2023, 3:36 PMurl
instead just use the imageUrl
directly. Means if I just update the remembered state, it recomposes.Ivan Cagle (IvanEOD)
07/27/2023, 4:20 PMonSizeChanged
modifier instead of globally positioned... i tested this with a label and image and it does not recompose.. i do not have a url handy to test with the url thoughAlexander Zhirkevich
07/27/2023, 6:00 PMBoxWithConstraints
StavFX
11/14/2023, 12:33 AMBen Trengrove [G]
11/14/2023, 12:43 AMStavFX
11/14/2023, 12:44 AM