Adds a wait and display function to make sure the image url doesn't appear while the image is loading from disk
This commit is contained in:
+28
-2
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.components
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.AnimatedVisibilityScope
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@@ -264,7 +265,9 @@ fun LocalImageView(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DisplayUrlWithLoadingSymbol(content)
|
WaitAndDisplay {
|
||||||
|
DisplayUrlWithLoadingSymbol(content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is AsyncImagePainter.State.Error -> {
|
is AsyncImagePainter.State.Error -> {
|
||||||
@@ -370,7 +373,9 @@ fun UrlImageView(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DisplayUrlWithLoadingSymbol(content)
|
WaitAndDisplay {
|
||||||
|
DisplayUrlWithLoadingSymbol(content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is AsyncImagePainter.State.Error -> {
|
is AsyncImagePainter.State.Error -> {
|
||||||
@@ -520,6 +525,27 @@ fun aspectRatio(dim: DimensionTag?): Float? {
|
|||||||
return dim.width.toFloat() / dim.height.toFloat()
|
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
|
@Composable
|
||||||
fun DisplayUrlWithLoadingSymbol(content: BaseMediaContent) {
|
fun DisplayUrlWithLoadingSymbol(content: BaseMediaContent) {
|
||||||
val uri = LocalUriHandler.current
|
val uri = LocalUriHandler.current
|
||||||
|
|||||||
+4
-1
@@ -61,6 +61,7 @@ import com.vitorpamplona.amethyst.ui.components.GetMediaItem
|
|||||||
import com.vitorpamplona.amethyst.ui.components.GetVideoController
|
import com.vitorpamplona.amethyst.ui.components.GetVideoController
|
||||||
import com.vitorpamplona.amethyst.ui.components.ImageUrlWithDownloadButton
|
import com.vitorpamplona.amethyst.ui.components.ImageUrlWithDownloadButton
|
||||||
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
|
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.navigation.INav
|
||||||
import com.vitorpamplona.amethyst.ui.note.DownloadForOfflineIcon
|
import com.vitorpamplona.amethyst.ui.note.DownloadForOfflineIcon
|
||||||
import com.vitorpamplona.amethyst.ui.note.WatchAuthor
|
import com.vitorpamplona.amethyst.ui.note.WatchAuthor
|
||||||
@@ -216,7 +217,9 @@ fun UrlImageView(
|
|||||||
defaultModifier,
|
defaultModifier,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
DisplayUrlWithLoadingSymbol(content)
|
WaitAndDisplay {
|
||||||
|
DisplayUrlWithLoadingSymbol(content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is AsyncImagePainter.State.Error -> {
|
is AsyncImagePainter.State.Error -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user