Reduces recomposition of the hash verification

This commit is contained in:
Vitor Pamplona
2024-04-02 16:08:38 -04:00
parent 793780f02c
commit fbf676bdb2
@@ -501,8 +501,6 @@ private fun AddedImageFeatures(
ImageUrlWithDownloadButton(content.url, showImage) ImageUrlWithDownloadButton(content.url, showImage)
} }
} else { } else {
var verifiedHash by remember(content.url) { mutableStateOf<Boolean?>(null) }
when (painter.value) { when (painter.value) {
null, null,
is AsyncImagePainter.State.Loading, is AsyncImagePainter.State.Loading,
@@ -528,24 +526,32 @@ private fun AddedImageFeatures(
} }
} }
is AsyncImagePainter.State.Success -> { is AsyncImagePainter.State.Success -> {
if (content.hash != null) { ShowHash(content, verifiedModifier)
LaunchedEffect(key1 = content.url) {
launch(Dispatchers.IO) {
val newVerifiedHash = verifyHash(content)
if (newVerifiedHash != verifiedHash) {
verifiedHash = newVerifiedHash
}
}
}
}
verifiedHash?.let { HashVerificationSymbol(it, verifiedModifier) }
} }
else -> {} else -> {}
} }
} }
} }
@Composable
fun ShowHash(
content: MediaUrlContent,
verifiedModifier: Modifier,
) {
var verifiedHash by remember(content.url) { mutableStateOf<Boolean?>(null) }
if (content.hash != null) {
LaunchedEffect(key1 = content.url) {
val newVerifiedHash = verifyHash(content)
if (newVerifiedHash != verifiedHash) {
verifiedHash = newVerifiedHash
}
}
}
verifiedHash?.let { HashVerificationSymbol(it, verifiedModifier) }
}
fun aspectRatio(dim: String?): Float? { fun aspectRatio(dim: String?): Float? {
if (dim == null) return null if (dim == null) return null
if (dim == "0x0") return null if (dim == "0x0") return null