From c1064665e6e41b2f2d9360a5b07b76417acb2b87 Mon Sep 17 00:00:00 2001 From: Diego Beraldin Date: Sun, 7 Apr 2024 09:07:25 +0200 Subject: [PATCH] fix: zoomable image (#659) closes #656 --- .../core/commonui/components/ZoomableImage.kt | 6 +++++- .../raccoonforlemmy/domain/lemmy/data/PostModel.kt | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/commonui/components/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/components/ZoomableImage.kt b/core/commonui/components/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/components/ZoomableImage.kt index 38a998a52..52835b30c 100644 --- a/core/commonui/components/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/components/ZoomableImage.kt +++ b/core/commonui/components/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/components/ZoomableImage.kt @@ -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( diff --git a/domain/lemmy/data/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/domain/lemmy/data/PostModel.kt b/domain/lemmy/data/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/domain/lemmy/data/PostModel.kt index 2b20d635f..94742efe2 100644 --- a/domain/lemmy/data/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/domain/lemmy/data/PostModel.kt +++ b/domain/lemmy/data/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/domain/lemmy/data/PostModel.kt @@ -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()