mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
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:
parent
0536c141b7
commit
91c19dc2a1
@ -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
|
||||
|
@ -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 -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user