Timeline: fix unknown aspectRatio
This commit is contained in:
parent
e907d610c2
commit
dcb9bcd11e
5 changed files with 11 additions and 15 deletions
|
|
@ -24,22 +24,23 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemAspectRatioBox(
|
fun TimelineItemAspectRatioBox(
|
||||||
height: Int?,
|
height: Int?,
|
||||||
aspectRatio: Float,
|
aspectRatio: Float?,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentAlignment: Alignment = Alignment.TopStart,
|
contentAlignment: Alignment = Alignment.TopStart,
|
||||||
content: @Composable BoxScope.() -> Unit,
|
content: @Composable BoxScope.() -> Unit,
|
||||||
) {
|
) {
|
||||||
// TODO should probably be moved to an ElementTheme.dimensions
|
val maxHeight = minOf(300, maxOf(100, height ?: Int.MAX_VALUE))
|
||||||
val maxHeight = min(300, height ?: 0)
|
val aspectRatioModifier = aspectRatio?.let {
|
||||||
|
Modifier.aspectRatio(it)
|
||||||
|
} ?: Modifier
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.heightIn(max = maxHeight.dp)
|
.heightIn(max = maxHeight.dp)
|
||||||
.aspectRatio(aspectRatio, matchHeightConstraintsFirst = true),
|
.then(aspectRatioModifier),
|
||||||
contentAlignment = contentAlignment,
|
contentAlignment = contentAlignment,
|
||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package io.element.android.features.messages.impl.timeline.components.event
|
package io.element.android.features.messages.impl.timeline.components.event
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
|
@ -28,24 +27,20 @@ import io.element.android.libraries.designsystem.components.BlurHashAsyncImage
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||||
import io.element.android.libraries.matrix.ui.media.MediaRequestData
|
import io.element.android.libraries.matrix.ui.media.MediaRequestData
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemImageView(
|
fun TimelineItemImageView(
|
||||||
content: TimelineItemImageContent,
|
content: TimelineItemImageContent,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
// TODO place this value somewhere else?
|
|
||||||
val minHeight = max(100, content.height ?: 0)
|
|
||||||
TimelineItemAspectRatioBox(
|
TimelineItemAspectRatioBox(
|
||||||
height = minHeight,
|
height = content.height,
|
||||||
aspectRatio = content.aspectRatio,
|
aspectRatio = content.aspectRatio,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
) {
|
) {
|
||||||
BlurHashAsyncImage(
|
BlurHashAsyncImage(
|
||||||
model = MediaRequestData(content.preferredMediaSource, MediaRequestData.Kind.File(content.body, content.mimeType)),
|
model = MediaRequestData(content.preferredMediaSource, MediaRequestData.Kind.File(content.body, content.mimeType)),
|
||||||
blurHash = content.blurhash,
|
blurHash = content.blurhash,
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentScale = ContentScale.Fit,
|
contentScale = ContentScale.Fit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,11 @@ class TimelineItemContentMessageFactory @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun aspectRatioOf(width: Long?, height: Long?): Float {
|
private fun aspectRatioOf(width: Long?, height: Long?): Float? {
|
||||||
return if (height != null && width != null) {
|
return if (height != null && width != null) {
|
||||||
width.toFloat() / height.toFloat()
|
width.toFloat() / height.toFloat()
|
||||||
} else {
|
} else {
|
||||||
0.7f
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ data class TimelineItemImageContent(
|
||||||
val blurhash: String?,
|
val blurhash: String?,
|
||||||
val width: Int?,
|
val width: Int?,
|
||||||
val height: Int?,
|
val height: Int?,
|
||||||
val aspectRatio: Float
|
val aspectRatio: Float?
|
||||||
) : TimelineItemEventContent {
|
) : TimelineItemEventContent {
|
||||||
override val type: String = "TimelineItemImageContent"
|
override val type: String = "TimelineItemImageContent"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ data class TimelineItemVideoContent(
|
||||||
val duration: Long,
|
val duration: Long,
|
||||||
val videoSource: MediaSource,
|
val videoSource: MediaSource,
|
||||||
val thumbnailSource: MediaSource?,
|
val thumbnailSource: MediaSource?,
|
||||||
val aspectRatio: Float,
|
val aspectRatio: Float?,
|
||||||
val blurHash: String?,
|
val blurHash: String?,
|
||||||
val height: Int?,
|
val height: Int?,
|
||||||
val width: Int?,
|
val width: Int?,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue