mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-03 07:47:32 +01:00
fix: unneeded space after post text
This commit is contained in:
parent
682f0c2ec0
commit
83160d5cff
@ -16,20 +16,25 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.Density
|
import androidx.compose.ui.unit.Density
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.toSize
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
|
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||||
|
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalPixel
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||||
@ -215,17 +220,22 @@ private fun ExtendedPost(
|
|||||||
onImageClick = onImageClick,
|
onImageClick = onImageClick,
|
||||||
)
|
)
|
||||||
Box {
|
Box {
|
||||||
|
val maxHeight = 200.dp
|
||||||
|
val maxHeightPx = maxHeight.toLocalPixel()
|
||||||
|
var textHeightPx by remember { mutableStateOf(0f) }
|
||||||
PostCardBody(
|
PostCardBody(
|
||||||
modifier = Modifier.let {
|
modifier = Modifier.let {
|
||||||
if (withOverflowBlurred) {
|
if (withOverflowBlurred) {
|
||||||
it.heightIn(max = 200.dp)
|
it.heightIn(max = maxHeight)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
}.padding(horizontal = Spacing.xs),
|
}.padding(horizontal = Spacing.xs).onGloballyPositioned {
|
||||||
|
textHeightPx = it.size.toSize().height
|
||||||
|
},
|
||||||
text = post.text,
|
text = post.text,
|
||||||
)
|
)
|
||||||
if (withOverflowBlurred) {
|
if (withOverflowBlurred && textHeightPx >= maxHeightPx) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.height(Spacing.xxl).fillMaxWidth()
|
modifier = Modifier.height(Spacing.xxl).fillMaxWidth()
|
||||||
.align(Alignment.BottomCenter).background(
|
.align(Alignment.BottomCenter).background(
|
||||||
@ -242,9 +252,7 @@ private fun ExtendedPost(
|
|||||||
if (post.url != post.imageUrl) {
|
if (post.url != post.imageUrl) {
|
||||||
PostLinkBanner(
|
PostLinkBanner(
|
||||||
modifier = Modifier.padding(vertical = Spacing.xs),
|
modifier = Modifier.padding(vertical = Spacing.xs),
|
||||||
url = post.url.takeIf {
|
url = post.url?.takeIf { !it.looksLikeAnImage }.orEmpty(),
|
||||||
it?.contains("pictrs/image") == false
|
|
||||||
}.orEmpty(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
PostCardFooter(
|
PostCardFooter(
|
||||||
@ -266,8 +274,11 @@ private fun ExtendedPost(
|
|||||||
|
|
||||||
private val PostModel.imageUrl: String
|
private val PostModel.imageUrl: String
|
||||||
get() = thumbnailUrl?.takeIf { it.isNotEmpty() } ?: run {
|
get() = thumbnailUrl?.takeIf { it.isNotEmpty() } ?: run {
|
||||||
url?.takeIf { u ->
|
url?.takeIf { it.looksLikeAnImage }
|
||||||
val imageExtensions = listOf(".jpeg", ".jpg", ".png")
|
|
||||||
imageExtensions.any { u.endsWith(it) }
|
|
||||||
}
|
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
|
|
||||||
|
private val String.looksLikeAnImage: Boolean
|
||||||
|
get() {
|
||||||
|
val imageExtensions = listOf(".jpeg", ".jpg", ".png")
|
||||||
|
return imageExtensions.any { this.endsWith(it) }
|
||||||
|
}
|
@ -59,7 +59,7 @@ fun PostCardFooter(
|
|||||||
|
|
||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(bottom = Spacing.xxxs),
|
modifier = Modifier.padding(vertical = Spacing.xxxs),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||||
) {
|
) {
|
||||||
|
@ -97,6 +97,7 @@ internal fun MarkdownText(
|
|||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
|
if (inlineImages || content.text != imageUrl) {
|
||||||
Text(
|
Text(
|
||||||
text = content,
|
text = content,
|
||||||
modifier = textModifier,
|
modifier = textModifier,
|
||||||
@ -163,6 +164,7 @@ internal fun MarkdownText(
|
|||||||
color = LocalMarkdownColors.current.text,
|
color = LocalMarkdownColors.current.text,
|
||||||
onTextLayout = { layoutResult.value = it },
|
onTextLayout = { layoutResult.value = it },
|
||||||
)
|
)
|
||||||
|
}
|
||||||
if (!inlineImages && imageUrl.isNotEmpty()) {
|
if (!inlineImages && imageUrl.isNotEmpty()) {
|
||||||
CustomImage(
|
CustomImage(
|
||||||
modifier = modifier.fillMaxWidth()
|
modifier = modifier.fillMaxWidth()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user