diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAspectRatioBox.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAspectRatioBox.kt index 7b2e2099d4..48072ce5bf 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAspectRatioBox.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAspectRatioBox.kt @@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp const val MIN_HEIGHT_IN_DP = 100 const val MAX_HEIGHT_IN_DP = 360 -private const val DEFAULT_ASPECT_RATIO = 1.33f +const val DEFAULT_ASPECT_RATIO = 1.33f @Composable fun TimelineItemAspectRatioBox( diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt index b876fc3a3f..af401dc56a 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemImageView.kt @@ -100,9 +100,10 @@ fun TimelineItemImageView( LocalContentColor provides ElementTheme.colors.textPrimary, LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular ) { + val aspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO EditorStyledText( modifier = Modifier - .widthIn(min = MIN_HEIGHT_IN_DP.dp * content.aspectRatio!!, max = MAX_HEIGHT_IN_DP.dp * content.aspectRatio), + .widthIn(min = MIN_HEIGHT_IN_DP.dp * aspectRatio, max = MAX_HEIGHT_IN_DP.dp * aspectRatio), text = caption, style = ElementRichTextEditorStyle.textStyle(), releaseOnDetach = false, @@ -136,5 +137,16 @@ internal fun TimelineImageWithCaptionRowPreview() = ElementPreview { ), ) } + ATimelineItemEventRow( + event = aTimelineItemEvent( + isMine = false, + content = aTimelineItemImageContent().copy( + filename = "image.jpg", + body = "Image with null aspectRatio", + aspectRatio = null, + ), + groupPosition = TimelineItemGroupPosition.Last, + ), + ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemStickerView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemStickerView.kt index 684e3ea54a..f895eddc85 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemStickerView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemStickerView.kt @@ -23,18 +23,17 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.matrix.ui.media.MediaRequestData private const val STICKER_SIZE_IN_DP = 128 -private const val DEFAULT_ASPECT_RATIO = 1.33f @Composable fun TimelineItemStickerView( content: TimelineItemStickerContent, modifier: Modifier = Modifier, ) { - val safeAspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO + val aspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO Box( modifier = modifier .heightIn(min = STICKER_SIZE_IN_DP.dp, max = STICKER_SIZE_IN_DP.dp) - .aspectRatio(safeAspectRatio, false), + .aspectRatio(aspectRatio, false), contentAlignment = Alignment.TopStart, ) { BlurHashAsyncImage( diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt index a571403e40..31cb5f1607 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemVideoView.kt @@ -72,7 +72,9 @@ fun TimelineItemVideoView( modifier = modifier.semantics { contentDescription = description } ) { val containerModifier = if (content.showCaption) { - Modifier.padding(top = 6.dp).clip(RoundedCornerShape(6.dp)) + Modifier + .padding(top = 6.dp) + .clip(RoundedCornerShape(6.dp)) } else { Modifier } @@ -116,9 +118,10 @@ fun TimelineItemVideoView( LocalContentColor provides ElementTheme.colors.textPrimary, LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular, ) { + val aspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO EditorStyledText( modifier = Modifier - .widthIn(min = MIN_HEIGHT_IN_DP.dp * content.aspectRatio!!, max = MAX_HEIGHT_IN_DP.dp * content.aspectRatio), + .widthIn(min = MIN_HEIGHT_IN_DP.dp * aspectRatio, max = MAX_HEIGHT_IN_DP.dp * aspectRatio), text = caption, style = ElementRichTextEditorStyle.textStyle(), releaseOnDetach = false, @@ -152,5 +155,16 @@ internal fun TimelineVideoWithCaptionRowPreview() = ElementPreview { ), ) } + ATimelineItemEventRow( + event = aTimelineItemEvent( + isMine = false, + content = aTimelineItemVideoContent().copy( + filename = "video.mp4", + body = "Video with null aspect ratio", + aspectRatio = null, + ), + groupPosition = TimelineItemGroupPosition.Last, + ), + ) } } diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Day_0_en.png index f5a62dcc36..399d942e18 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Day_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Day_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1f515c9e3fe7f24c0db3b6daff7d583a4accc71e34deab665aa1977e93132fd2 -size 136015 +oid sha256:926904f8e96ed206835166d6a6d206a8ed2c0ea6895f2e48951b43a5b92aeee7 +size 225862 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Night_0_en.png index 4c0ef97965..aa161e4266 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Night_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineImageWithCaptionRow_Night_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:29e4c9cf040e4227c653f022b3116eb313c011a3d4df8adceb3cfc826b773b64 -size 135849 +oid sha256:727a7e925722c7addc8b8021259ad15f3cb0e664803bbd4c67959ec1e9ca036a +size 226638 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Day_0_en.png index eb45df9180..847ae35de9 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Day_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Day_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4b47bf80fce1bdd567644769a14123f4969a808bee08058067bf8e4947cd1174 -size 135073 +oid sha256:0db8b0043cc020fc8f7c7f5b44059486e022dd13080b02368723e253b1c616d7 +size 225018 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Night_0_en.png index d4f164148c..81247e3e07 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Night_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.event_TimelineVideoWithCaptionRow_Night_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:530130c2f5de6bbced25a1b04e7bcb16ebc630dfdfa7f522c055a5b38a851a81 -size 134615 +oid sha256:feaf14edc0d7a8ff1349e9fb051ce883b0de75a2528f9a6650df398b81e82b68 +size 225300