diff --git a/app/src/main/java/com/rosetta/messenger/ui/chats/components/AttachmentComponents.kt b/app/src/main/java/com/rosetta/messenger/ui/chats/components/AttachmentComponents.kt index cf73c00..e01a2e7 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/chats/components/AttachmentComponents.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/chats/components/AttachmentComponents.kt @@ -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 {