Fix reloading

Signed-off-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
2026-03-26 15:13:36 +03:00
Unverified
parent ecffdb9048
commit c3529408c1
@@ -140,7 +140,9 @@ fun AttachmentPreview(
) )
} }
isImageWithThumb || isPendingImage -> { isImageWithThumb || isPendingImage -> {
var isFullyLoaded by remember { mutableStateOf(false) } var isFullyLoaded by remember(messageId, fileIndex, file?.path, pendingFileUri) {
mutableStateOf(false)
}
Box( Box(
modifier = modifier modifier = modifier
.then( .then(
@@ -158,7 +160,6 @@ fun AttachmentPreview(
Modifier.size(IMAGE_SIZE) Modifier.size(IMAGE_SIZE)
} }
) )
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
.clip(RoundedCornerShape(IMAGE_RADIUS)) .clip(RoundedCornerShape(IMAGE_RADIUS))
.then( .then(
if (onImageBounds != null && (isImageWithThumb || !isPendingImage)) { if (onImageBounds != null && (isImageWithThumb || !isPendingImage)) {
@@ -180,7 +181,11 @@ fun AttachmentPreview(
), ),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
if (!isExpanded) { Box(
modifier = Modifier
.fillMaxSize()
.graphicsLayer { alpha = if (isExpanded) 0f else 1f }
) {
when { when {
isPendingImage -> UnifiedImageContent( isPendingImage -> UnifiedImageContent(
localUri = pendingFileUri, localUri = pendingFileUri,
@@ -191,7 +196,7 @@ fun AttachmentPreview(
currentUserId = currentUserId, currentUserId = currentUserId,
isUploading = isUploading, isUploading = isUploading,
uploadProgress = uploadProgress, uploadProgress = uploadProgress,
onFullyLoaded = { isFullyLoaded = it } onFullyLoaded = { if (it) isFullyLoaded = true }
) )
else -> DecryptedImageContent( else -> DecryptedImageContent(
messageId = messageId ?: -1, messageId = messageId ?: -1,
@@ -201,11 +206,9 @@ fun AttachmentPreview(
currentUserId = currentUserId, currentUserId = currentUserId,
thumbnailBase64 = fileThumbnail!!, thumbnailBase64 = fileThumbnail!!,
aspectRatio = fileAspectRatio, aspectRatio = fileAspectRatio,
onFullyLoaded = { isFullyLoaded = it } onFullyLoaded = { if (it) isFullyLoaded = true }
) )
} }
} else {
Box(modifier = Modifier.fillMaxSize())
} }
} }
} }
@@ -242,16 +245,25 @@ private fun UnifiedImageContent(
null null
} }
} }
LaunchedEffect(Unit) { onFullyLoaded(true) }
val localPainter = rememberAsyncImagePainter(
model = localUri,
contentScale = ContentScale.Crop
)
val localState by localPainter.state.collectAsState()
LaunchedEffect(localState) {
if (localState is coil3.compose.AsyncImagePainter.State.Success) {
onFullyLoaded(true)
}
}
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.clip(RoundedCornerShape(IMAGE_RADIUS)) .clip(RoundedCornerShape(IMAGE_RADIUS))
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
) { ) {
AsyncImage( Image(
model = localUri, painter = localPainter,
contentDescription = null, contentDescription = null,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop contentScale = ContentScale.Crop
@@ -300,9 +312,7 @@ private fun UnifiedImageContent(
contentScale = ContentScale.FillWidth contentScale = ContentScale.FillWidth
) )
} }
else -> { else -> Unit
LaunchedEffect(Unit) { onFullyLoaded(false) }
}
} }
} }
} }
@@ -406,11 +416,6 @@ private fun PendingImageContent(
.fillMaxSize() .fillMaxSize()
.clip(RoundedCornerShape(IMAGE_RADIUS)) .clip(RoundedCornerShape(IMAGE_RADIUS))
) { ) {
Box(
modifier = Modifier
.matchParentSize()
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
)
AsyncImage( AsyncImage(
model = uri, model = uri,
contentDescription = null, contentDescription = null,
@@ -516,15 +521,11 @@ private fun DecryptedImageContent(
LaunchedEffect(messageId, fileIndex, file.path, envelope) { LaunchedEffect(messageId, fileIndex, file.path, envelope) {
cachedPath = DecryptedImageCache.getOrDecrypt(messageId, fileIndex, file, envelope, currentUserId) cachedPath = DecryptedImageCache.getOrDecrypt(messageId, fileIndex, file, envelope, currentUserId)
} }
LaunchedEffect(cachedPath) {
onFullyLoaded(cachedPath != null)
}
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.clip(RoundedCornerShape(IMAGE_RADIUS)) .clip(RoundedCornerShape(IMAGE_RADIUS))
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
) { ) {
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
when { when {
@@ -536,6 +537,7 @@ private fun DecryptedImageContent(
val fullState by fullPainter.state.collectAsState() val fullState by fullPainter.state.collectAsState()
when (fullState) { when (fullState) {
is coil3.compose.AsyncImagePainter.State.Success -> { is coil3.compose.AsyncImagePainter.State.Success -> {
LaunchedEffect(Unit) { onFullyLoaded(true) }
Image( Image(
painter = fullPainter, painter = fullPainter,
contentDescription = file.name, contentDescription = file.name,
@@ -585,6 +587,7 @@ private fun DecryptedImageContent(
} }
} }
is coil3.compose.AsyncImagePainter.State.Success -> { is coil3.compose.AsyncImagePainter.State.Success -> {
LaunchedEffect(Unit) { onFullyLoaded(true) }
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@@ -606,6 +609,7 @@ private fun DecryptedImageContent(
val fullState by fullPainter.state.collectAsState() val fullState by fullPainter.state.collectAsState()
when (fullState) { when (fullState) {
is coil3.compose.AsyncImagePainter.State.Success -> { is coil3.compose.AsyncImagePainter.State.Success -> {
LaunchedEffect(Unit) { onFullyLoaded(true) }
val alpha = remember { Animatable(0f) } val alpha = remember { Animatable(0f) }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
alpha.animateTo(1f, animationSpec = tween(300)) alpha.animateTo(1f, animationSpec = tween(300))