fix: zoomable image (#659)

closes #656
This commit is contained in:
Diego Beraldin 2024-04-07 09:07:25 +02:00 committed by GitHub
parent 5e39a7a9a6
commit c1064665e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -22,8 +22,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextAlign
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
@ -47,7 +49,7 @@ fun ZoomableImage(
) {
val transformableState =
rememberTransformableState { zoomChange, panChange, _ ->
scale = (scale * zoomChange).coerceIn(1f, 5f)
scale = (scale * zoomChange).coerceIn(1f, 16f)
val extraWidth = (scale - 1) * constraints.maxWidth
val extraHeight = (scale - 1) * constraints.maxHeight
@ -74,6 +76,8 @@ fun ZoomableImage(
)
.transformable(transformableState),
url = url,
contentScale = ContentScale.FillWidth,
quality = FilterQuality.High,
autoload = autoLoadImages,
onFailure = {
Text(

View File

@ -33,9 +33,7 @@ data class PostModel(
)
val PostModel.imageUrl: String
get() = url?.takeIf { it.looksLikeAnImage }?.takeIf { it.isNotEmpty() } ?: run {
thumbnailUrl
}.orEmpty()
get() = (thumbnailUrl?.takeIf { it.isNotEmpty() } ?: url?.takeIf { it.looksLikeAnImage }).orEmpty()
val PostModel.videoUrl: String
get() = url?.takeIf { it.looksLikeAVideo }?.takeIf { it.isNotEmpty() }.orEmpty()