Fix crash when aspectRatio is null.
This commit is contained in:
parent
b43b0d3ecb
commit
49ec7d736a
4 changed files with 32 additions and 7 deletions
|
|
@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
const val MIN_HEIGHT_IN_DP = 100
|
const val MIN_HEIGHT_IN_DP = 100
|
||||||
const val MAX_HEIGHT_IN_DP = 360
|
const val MAX_HEIGHT_IN_DP = 360
|
||||||
private const val DEFAULT_ASPECT_RATIO = 1.33f
|
const val DEFAULT_ASPECT_RATIO = 1.33f
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemAspectRatioBox(
|
fun TimelineItemAspectRatioBox(
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,10 @@ 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
|
||||||
EditorStyledText(
|
EditorStyledText(
|
||||||
modifier = Modifier
|
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,
|
text = caption,
|
||||||
style = ElementRichTextEditorStyle.textStyle(),
|
style = ElementRichTextEditorStyle.textStyle(),
|
||||||
releaseOnDetach = false,
|
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,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,18 +23,17 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.matrix.ui.media.MediaRequestData
|
import io.element.android.libraries.matrix.ui.media.MediaRequestData
|
||||||
|
|
||||||
private const val STICKER_SIZE_IN_DP = 128
|
private const val STICKER_SIZE_IN_DP = 128
|
||||||
private const val DEFAULT_ASPECT_RATIO = 1.33f
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemStickerView(
|
fun TimelineItemStickerView(
|
||||||
content: TimelineItemStickerContent,
|
content: TimelineItemStickerContent,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val safeAspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO
|
val aspectRatio = content.aspectRatio ?: DEFAULT_ASPECT_RATIO
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.heightIn(min = STICKER_SIZE_IN_DP.dp, max = STICKER_SIZE_IN_DP.dp)
|
.heightIn(min = STICKER_SIZE_IN_DP.dp, max = STICKER_SIZE_IN_DP.dp)
|
||||||
.aspectRatio(safeAspectRatio, false),
|
.aspectRatio(aspectRatio, false),
|
||||||
contentAlignment = Alignment.TopStart,
|
contentAlignment = Alignment.TopStart,
|
||||||
) {
|
) {
|
||||||
BlurHashAsyncImage(
|
BlurHashAsyncImage(
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ fun TimelineItemVideoView(
|
||||||
modifier = modifier.semantics { contentDescription = description }
|
modifier = modifier.semantics { contentDescription = description }
|
||||||
) {
|
) {
|
||||||
val containerModifier = if (content.showCaption) {
|
val containerModifier = if (content.showCaption) {
|
||||||
Modifier.padding(top = 6.dp).clip(RoundedCornerShape(6.dp))
|
Modifier
|
||||||
|
.padding(top = 6.dp)
|
||||||
|
.clip(RoundedCornerShape(6.dp))
|
||||||
} else {
|
} else {
|
||||||
Modifier
|
Modifier
|
||||||
}
|
}
|
||||||
|
|
@ -116,9 +118,10 @@ fun TimelineItemVideoView(
|
||||||
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
|
||||||
EditorStyledText(
|
EditorStyledText(
|
||||||
modifier = Modifier
|
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,
|
text = caption,
|
||||||
style = ElementRichTextEditorStyle.textStyle(),
|
style = ElementRichTextEditorStyle.textStyle(),
|
||||||
releaseOnDetach = false,
|
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,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue