Reduces recomposition of the hash verification
This commit is contained in:
@@ -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,23 +526,31 @@ private fun AddedImageFeatures(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is AsyncImagePainter.State.Success -> {
|
is AsyncImagePainter.State.Success -> {
|
||||||
|
ShowHash(content, verifiedModifier)
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ShowHash(
|
||||||
|
content: MediaUrlContent,
|
||||||
|
verifiedModifier: Modifier,
|
||||||
|
) {
|
||||||
|
var verifiedHash by remember(content.url) { mutableStateOf<Boolean?>(null) }
|
||||||
|
|
||||||
if (content.hash != null) {
|
if (content.hash != null) {
|
||||||
LaunchedEffect(key1 = content.url) {
|
LaunchedEffect(key1 = content.url) {
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
val newVerifiedHash = verifyHash(content)
|
val newVerifiedHash = verifyHash(content)
|
||||||
if (newVerifiedHash != verifiedHash) {
|
if (newVerifiedHash != verifiedHash) {
|
||||||
verifiedHash = newVerifiedHash
|
verifiedHash = newVerifiedHash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
verifiedHash?.let { HashVerificationSymbol(it, verifiedModifier) }
|
verifiedHash?.let { HashVerificationSymbol(it, verifiedModifier) }
|
||||||
}
|
}
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun aspectRatio(dim: String?): Float? {
|
fun aspectRatio(dim: String?): Float? {
|
||||||
if (dim == null) return null
|
if (dim == null) return null
|
||||||
|
|||||||
Reference in New Issue
Block a user