From 91c19dc2a1a3cf61c5c1c56f1a4ef9ea6aa4568a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 5 Mar 2025 15:26:52 -0500 Subject: [PATCH] Adds a wait and display function to make sure the image url doesn't appear while the image is loading from disk --- .../ui/components/ZoomableContentView.kt | 30 +++++++++++++++++-- .../loggedIn/profile/gallery/GalleryThumb.kt | 5 +++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index 2e991ee7a..378a2dddc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.components import android.util.Log import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.AnimatedVisibilityScope import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.clickable @@ -264,7 +265,9 @@ fun LocalImageView( ) } } else { - DisplayUrlWithLoadingSymbol(content) + WaitAndDisplay { + DisplayUrlWithLoadingSymbol(content) + } } } is AsyncImagePainter.State.Error -> { @@ -370,7 +373,9 @@ fun UrlImageView( ) } } else { - DisplayUrlWithLoadingSymbol(content) + WaitAndDisplay { + DisplayUrlWithLoadingSymbol(content) + } } } is AsyncImagePainter.State.Error -> { @@ -520,6 +525,27 @@ fun aspectRatio(dim: DimensionTag?): Float? { return dim.width.toFloat() / dim.height.toFloat() } +@Composable +fun WaitAndDisplay( + content: + @Composable() + (AnimatedVisibilityScope.() -> Unit), +) { + val visible = remember { mutableStateOf(false) } + + LaunchedEffect(Unit) { + delay(200) + visible.value = true + } + + AnimatedVisibility( + visible = visible.value, + enter = fadeIn(), + exit = fadeOut(), + content = content, + ) +} + @Composable fun DisplayUrlWithLoadingSymbol(content: BaseMediaContent) { val uri = LocalUriHandler.current diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt index 5e27dec94..71d3b9651 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt @@ -61,6 +61,7 @@ import com.vitorpamplona.amethyst.ui.components.GetMediaItem import com.vitorpamplona.amethyst.ui.components.GetVideoController import com.vitorpamplona.amethyst.ui.components.ImageUrlWithDownloadButton import com.vitorpamplona.amethyst.ui.components.SensitivityWarning +import com.vitorpamplona.amethyst.ui.components.WaitAndDisplay import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.note.DownloadForOfflineIcon import com.vitorpamplona.amethyst.ui.note.WatchAuthor @@ -216,7 +217,9 @@ fun UrlImageView( defaultModifier, ) } else { - DisplayUrlWithLoadingSymbol(content) + WaitAndDisplay { + DisplayUrlWithLoadingSymbol(content) + } } } is AsyncImagePainter.State.Error -> {