mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-30 00:40:49 +00:00
Only showing the loading url after 200 ms to avoid blinking the text.
This commit is contained in:
parent
c8f1e13448
commit
8641e0fec5
@ -64,15 +64,19 @@ import coil.annotation.ExperimentalCoilApi
|
|||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import coil.compose.AsyncImagePainter
|
import coil.compose.AsyncImagePainter
|
||||||
import coil.imageLoader
|
import coil.imageLoader
|
||||||
|
import com.google.accompanist.flowlayout.FlowRow
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.BlurHashRequester
|
import com.vitorpamplona.amethyst.service.BlurHashRequester
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
||||||
import com.vitorpamplona.amethyst.ui.actions.LoadingAnimation
|
import com.vitorpamplona.amethyst.ui.actions.LoadingAnimation
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SaveToGallery
|
import com.vitorpamplona.amethyst.ui.actions.SaveToGallery
|
||||||
|
import com.vitorpamplona.amethyst.ui.note.BlankNote
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import net.engawapg.lib.zoomable.rememberZoomState
|
import net.engawapg.lib.zoomable.rememberZoomState
|
||||||
import net.engawapg.lib.zoomable.zoomable
|
import net.engawapg.lib.zoomable.zoomable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -232,17 +236,21 @@ private fun LocalImageView(
|
|||||||
HashVerificationSymbol(content.isVerified, Modifier.align(Alignment.TopEnd))
|
HashVerificationSymbol(content.isVerified, Modifier.align(Alignment.TopEnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.blurhash != null) {
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = imageState !is AsyncImagePainter.State.Success,
|
visible = imageState !is AsyncImagePainter.State.Success,
|
||||||
exit = fadeOut(animationSpec = tween(200))
|
exit = fadeOut(animationSpec = tween(200))
|
||||||
) {
|
) {
|
||||||
|
if (content.blurhash != null) {
|
||||||
DisplayBlurHash(content.blurhash, content.description, mainImageModifier)
|
DisplayBlurHash(content.blurhash, content.description, mainImageModifier)
|
||||||
|
} else {
|
||||||
|
FlowRow() {
|
||||||
|
DisplayUrlWithLoadingSymbol(content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageState is AsyncImagePainter.State.Error) {
|
if (imageState is AsyncImagePainter.State.Error) {
|
||||||
DisplayUrlWithLoadingSymbol(content)
|
BlankNote()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,17 +298,21 @@ private fun UrlImageView(
|
|||||||
HashVerificationSymbol(verifiedHash, Modifier.align(Alignment.TopEnd))
|
HashVerificationSymbol(verifiedHash, Modifier.align(Alignment.TopEnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.blurhash != null) {
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = imageState !is AsyncImagePainter.State.Success,
|
visible = imageState !is AsyncImagePainter.State.Success,
|
||||||
exit = fadeOut(animationSpec = tween(200))
|
exit = fadeOut(animationSpec = tween(200))
|
||||||
) {
|
) {
|
||||||
|
if (content.blurhash != null) {
|
||||||
DisplayBlurHash(content.blurhash, content.description, mainImageModifier)
|
DisplayBlurHash(content.blurhash, content.description, mainImageModifier)
|
||||||
|
} else {
|
||||||
|
FlowRow() {
|
||||||
|
DisplayUrlWithLoadingSymbol(content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageState is AsyncImagePainter.State.Error) {
|
if (imageState is AsyncImagePainter.State.Error) {
|
||||||
DisplayUrlWithLoadingSymbol(content)
|
ClickableUrl(urlText = "${content.url} ", url = content.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,6 +334,20 @@ private fun aspectRatio(dim: String?): Float? {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplayUrlWithLoadingSymbol(content: ZoomableContent) {
|
private fun DisplayUrlWithLoadingSymbol(content: ZoomableContent) {
|
||||||
|
var cnt by remember { mutableStateOf<ZoomableContent?>(null) }
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
delay(200)
|
||||||
|
cnt = content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt?.let { DisplayUrlWithLoadingSymbolWait(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DisplayUrlWithLoadingSymbolWait(content: ZoomableContent) {
|
||||||
if (content is ZoomableUrlContent) {
|
if (content is ZoomableUrlContent) {
|
||||||
ClickableUrl(urlText = "${content.url} ", url = content.url)
|
ClickableUrl(urlText = "${content.url} ", url = content.url)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user