feat: Calculate bubble size based on image aspect ratio in ImageAttachment component
This commit is contained in:
@@ -244,10 +244,45 @@ fun ImageAttachment(
|
||||
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(
|
||||
modifier = Modifier
|
||||
.widthIn(min = 180.dp, max = 260.dp)
|
||||
.heightIn(min = 140.dp, max = 300.dp)
|
||||
.width(imageWidth)
|
||||
.height(imageHeight)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color.Transparent)
|
||||
.clickable {
|
||||
|
||||
Reference in New Issue
Block a user