Fix scaling of timeline images (#1941)
Co-authored-by: ElementBot <benoitm+elementbot@element.io> Co-authored-by: Benoit Marty <benoit@matrix.org> Co-authored-by: Benoit Marty <benoitm@matrix.org>
This commit is contained in:
parent
9130ecbd7d
commit
7ed460b282
40 changed files with 82 additions and 85 deletions
|
|
@ -99,10 +99,9 @@ fun MessageEventBubble(
|
|||
}
|
||||
|
||||
// Ignore state.isHighlighted for now, we need a design decision on it.
|
||||
val backgroundBubbleColor = if (state.isMine) {
|
||||
ElementTheme.colors.messageFromMeBackground
|
||||
} else {
|
||||
ElementTheme.colors.messageFromOtherBackground
|
||||
val backgroundBubbleColor = when {
|
||||
state.isMine -> ElementTheme.colors.messageFromMeBackground
|
||||
else -> ElementTheme.colors.messageFromOtherBackground
|
||||
}
|
||||
val bubbleShape = bubbleShape()
|
||||
Box(
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ private fun MessageEventBubbleContent(
|
|||
) {
|
||||
when (timestampPosition) {
|
||||
TimestampPosition.Overlay ->
|
||||
Box(modifier) {
|
||||
Box(modifier, contentAlignment = Alignment.Center) {
|
||||
content()
|
||||
TimelineEventTimestampView(
|
||||
event = event,
|
||||
|
|
@ -650,7 +650,7 @@ internal fun TimelineItemEventRowPreview() = ElementPreview {
|
|||
event = aTimelineItemEvent(
|
||||
isMine = it,
|
||||
content = aTimelineItemImageContent().copy(
|
||||
aspectRatio = 5f
|
||||
aspectRatio = 2.5f
|
||||
),
|
||||
groupPosition = TimelineItemGroupPosition.Last,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ internal fun TimelineItemEventRowWithReplyPreview(
|
|||
isMine = it,
|
||||
timelineItemReactions = aTimelineItemReactions(count = 0),
|
||||
content = aTimelineItemImageContent().copy(
|
||||
aspectRatio = 5f
|
||||
aspectRatio = 2.5f
|
||||
),
|
||||
inReplyTo = inReplyToDetails,
|
||||
isThreaded = true,
|
||||
|
|
|
|||
|
|
@ -25,9 +25,8 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
private const val MAX_HEIGHT_IN_DP = 360f
|
||||
private const val MIN_ASPECT_RATIO = 0.6f
|
||||
private const val MAX_ASPECT_RATIO = 4f
|
||||
private const val MIN_HEIGHT_IN_DP = 100
|
||||
private const val MAX_HEIGHT_IN_DP = 360
|
||||
private const val DEFAULT_ASPECT_RATIO = 1.33f
|
||||
|
||||
@Composable
|
||||
|
|
@ -37,11 +36,11 @@ fun TimelineItemAspectRatioBox(
|
|||
contentAlignment: Alignment = Alignment.TopStart,
|
||||
content: @Composable (BoxScope.() -> Unit),
|
||||
) {
|
||||
val safeAspectRatio = (aspectRatio ?: DEFAULT_ASPECT_RATIO).coerceIn(MIN_ASPECT_RATIO, MAX_ASPECT_RATIO)
|
||||
val safeAspectRatio = aspectRatio ?: DEFAULT_ASPECT_RATIO
|
||||
Box(
|
||||
modifier = modifier
|
||||
.heightIn(max = MAX_HEIGHT_IN_DP.dp)
|
||||
.aspectRatio(safeAspectRatio, true),
|
||||
.heightIn(min = MIN_HEIGHT_IN_DP.dp, max = MAX_HEIGHT_IN_DP.dp)
|
||||
.aspectRatio(safeAspectRatio, false),
|
||||
contentAlignment = contentAlignment,
|
||||
content = content
|
||||
)
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@ package io.element.android.features.messages.impl.timeline.components.event
|
|||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent
|
||||
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContentProvider
|
||||
import io.element.android.libraries.designsystem.components.BlurHashAsyncImage
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.matrix.ui.media.MediaRequestData
|
||||
|
||||
@Composable
|
||||
|
|
@ -34,12 +33,11 @@ fun TimelineItemImageView(
|
|||
) {
|
||||
TimelineItemAspectRatioBox(
|
||||
aspectRatio = content.aspectRatio,
|
||||
modifier = modifier
|
||||
modifier = modifier,
|
||||
) {
|
||||
BlurHashAsyncImage(
|
||||
model = MediaRequestData(content.preferredMediaSource, MediaRequestData.Kind.File(content.body, content.mimeType)),
|
||||
blurHash = content.blurhash,
|
||||
contentScale = ContentScale.Crop,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue