mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Fix low width image message (#6692)
* fix low width image message * added previews for narrow images * Update screenshots --------- Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
+45
-2
@@ -58,6 +58,7 @@ import io.element.android.libraries.ui.utils.a11y.isTalkbackActive
|
|||||||
import io.element.android.wysiwyg.compose.EditorStyledText
|
import io.element.android.wysiwyg.compose.EditorStyledText
|
||||||
import io.element.android.wysiwyg.link.Link
|
import io.element.android.wysiwyg.link.Link
|
||||||
|
|
||||||
|
private const val TALL_IMAGE_RATIO_DIVISOR = 3
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemImageView(
|
fun TimelineItemImageView(
|
||||||
content: TimelineItemImageContent,
|
content: TimelineItemImageContent,
|
||||||
@@ -79,7 +80,7 @@ fun TimelineItemImageView(
|
|||||||
Modifier
|
Modifier
|
||||||
}
|
}
|
||||||
TimelineItemAspectRatioBox(
|
TimelineItemAspectRatioBox(
|
||||||
modifier = containerModifier.blurHashBackground(content.blurhash, alpha = 0.9f),
|
modifier = containerModifier.blurHashBackground(content.blurhash, alpha = 0.9f).align(Alignment.CenterHorizontally),
|
||||||
aspectRatio = coerceRatioWhenHidingContent(content.aspectRatio, hideMediaContent),
|
aspectRatio = coerceRatioWhenHidingContent(content.aspectRatio, hideMediaContent),
|
||||||
) {
|
) {
|
||||||
ProtectedView(
|
ProtectedView(
|
||||||
@@ -123,7 +124,14 @@ fun TimelineItemImageView(
|
|||||||
LocalContentColor provides ElementTheme.colors.textPrimary,
|
LocalContentColor provides ElementTheme.colors.textPrimary,
|
||||||
LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular
|
LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular
|
||||||
) {
|
) {
|
||||||
val aspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO
|
val width = content.width ?: 0
|
||||||
|
val height = content.height ?: 0
|
||||||
|
// if image is narrow and tall use DEFAULT_ASPECT_RATIO
|
||||||
|
val aspectRatio = if (width < height / TALL_IMAGE_RATIO_DIVISOR) {
|
||||||
|
DEFAULT_ASPECT_RATIO
|
||||||
|
} else {
|
||||||
|
content.aspectRatio ?: DEFAULT_ASPECT_RATIO
|
||||||
|
}
|
||||||
EditorStyledText(
|
EditorStyledText(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(horizontal = 4.dp) // This is (12.dp - 8.dp) contentPadding from CommonLayout
|
.padding(horizontal = 4.dp) // This is (12.dp - 8.dp) contentPadding from CommonLayout
|
||||||
@@ -200,3 +208,38 @@ internal fun TimelineImageWithCaptionRowPreview() = ElementPreview {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreviewsDayNight
|
||||||
|
@Composable
|
||||||
|
internal fun ATimelineItemEventRowPreview() = ElementPreview {
|
||||||
|
Column {
|
||||||
|
sequenceOf(false, true).forEach { isMine ->
|
||||||
|
ATimelineItemEventRow(
|
||||||
|
event = aTimelineItemEvent(
|
||||||
|
isMine = isMine,
|
||||||
|
content = aTimelineItemImageContent(
|
||||||
|
filename = "image.jpg",
|
||||||
|
caption = "A long caption that may wrap into several lines",
|
||||||
|
width = 80,
|
||||||
|
height = 300,
|
||||||
|
aspectRatio = 80f / 300f,
|
||||||
|
),
|
||||||
|
groupPosition = TimelineItemGroupPosition.Last,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ATimelineItemEventRow(
|
||||||
|
event = aTimelineItemEvent(
|
||||||
|
isMine = false,
|
||||||
|
content = aTimelineItemImageContent(
|
||||||
|
filename = "image.jpg",
|
||||||
|
caption = "Narrow image with null aspectRatio",
|
||||||
|
width = 80,
|
||||||
|
height = 300,
|
||||||
|
aspectRatio = null,
|
||||||
|
),
|
||||||
|
groupPosition = TimelineItemGroupPosition.Last,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+4
-2
@@ -28,6 +28,8 @@ fun aTimelineItemImageContent(
|
|||||||
blurhash: String? = A_BLUR_HASH,
|
blurhash: String? = A_BLUR_HASH,
|
||||||
filename: String = "A picture.jpg",
|
filename: String = "A picture.jpg",
|
||||||
caption: String? = null,
|
caption: String? = null,
|
||||||
|
width: Int? = null,
|
||||||
|
height: Int? = 300,
|
||||||
) = TimelineItemImageContent(
|
) = TimelineItemImageContent(
|
||||||
filename = filename,
|
filename = filename,
|
||||||
fileSize = 4 * 1024 * 1024L,
|
fileSize = 4 * 1024 * 1024L,
|
||||||
@@ -38,8 +40,8 @@ fun aTimelineItemImageContent(
|
|||||||
thumbnailSource = null,
|
thumbnailSource = null,
|
||||||
mimeType = MimeTypes.IMAGE_JPEG,
|
mimeType = MimeTypes.IMAGE_JPEG,
|
||||||
blurhash = blurhash,
|
blurhash = blurhash,
|
||||||
width = null,
|
width = width,
|
||||||
height = 300,
|
height = height,
|
||||||
thumbnailWidth = null,
|
thumbnailWidth = null,
|
||||||
thumbnailHeight = 150,
|
thumbnailHeight = 150,
|
||||||
aspectRatio = aspectRatio,
|
aspectRatio = aspectRatio,
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in New Issue
Block a user