feat: Calculate bubble size based on image aspect ratio in ImageAttachment component

This commit is contained in:
k1ngsterr1
2026-01-25 17:55:43 +05:00
parent f58b941a5e
commit 1d36b51d06

View File

@@ -244,10 +244,45 @@ fun ImageAttachment(
if (isDarkTheme) Color.White.copy(alpha = 0.1f) else Color.Black.copy(alpha = 0.08f) if (isDarkTheme) Color.White.copy(alpha = 0.1f) else Color.Black.copy(alpha = 0.08f)
} }
// 📐 Вычисляем размер пузырька на основе соотношения сторон изображения (как в Telegram)
val (imageWidth, imageHeight) = remember(attachment.width, attachment.height) {
val maxWidth = 260.dp
val maxHeight = 340.dp
val minWidth = 180.dp
val minHeight = 140.dp
if (attachment.width > 0 && attachment.height > 0) {
val aspectRatio = attachment.width.toFloat() / attachment.height.toFloat()
when {
// Широкое изображение (landscape)
aspectRatio > 1.2f -> {
val width = maxWidth
val height = (maxWidth.value / aspectRatio).dp.coerceIn(minHeight, maxHeight)
width to height
}
// Высокое изображение (portrait)
aspectRatio < 0.8f -> {
val height = maxHeight
val width = (maxHeight.value * aspectRatio).dp.coerceIn(minWidth, maxWidth)
width to height
}
// Квадратное или близкое к квадрату
else -> {
val size = 220.dp
size to size
}
}
} else {
// Fallback если размеры не указаны
220.dp to 220.dp
}
}
Box( Box(
modifier = Modifier modifier = Modifier
.widthIn(min = 180.dp, max = 260.dp) .width(imageWidth)
.heightIn(min = 140.dp, max = 300.dp) .height(imageHeight)
.clip(RoundedCornerShape(12.dp)) .clip(RoundedCornerShape(12.dp))
.background(Color.Transparent) .background(Color.Transparent)
.clickable { .clickable {