Skip to content

Commit

Permalink
Center images in the message bubble.
Browse files Browse the repository at this point in the history
Always display a white background for them.
  • Loading branch information
jmartinesp committed Dec 15, 2023
1 parent b4ce316 commit 2b76aeb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -99,10 +100,10 @@ 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.displayBackground -> Color.White
state.isMine -> ElementTheme.colors.messageFromMeBackground
else -> ElementTheme.colors.messageFromOtherBackground
}
val bubbleShape = bubbleShape()
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemVideoContent
import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemImageContent
import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent
import io.element.android.features.messages.impl.timeline.model.event.hasMediaThumbnail
import io.element.android.features.messages.impl.timeline.model.metadata
import io.element.android.libraries.androidutils.system.openUrlInExternalApp
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
Expand Down Expand Up @@ -301,12 +302,15 @@ private fun TimelineItemEventRowContent(
)
}

val displayBubbleBackground = !event.content.hasMediaThumbnail() || event.inReplyTo != null

// Message bubble
val bubbleState = BubbleState(
groupPosition = event.groupPosition,
isMine = event.isMine,
isHighlighted = isHighlighted,
timelineRoomInfo = timelineRoomInfo,
displayBackground = displayBubbleBackground,
)
MessageEventBubble(
modifier = Modifier
Expand Down Expand Up @@ -439,7 +443,7 @@ private fun MessageEventBubbleContent(
) {
when (timestampPosition) {
TimestampPosition.Overlay ->
Box(modifier) {
Box(modifier, contentAlignment = Alignment.Center) {
content()
TimelineEventTimestampView(
event = event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun TimelineItemImageView(
) {
TimelineItemAspectRatioBox(
aspectRatio = content.aspectRatio,
modifier = modifier
modifier = modifier,
) {
BlurHashAsyncImage(
model = MediaRequestData(content.preferredMediaSource, MediaRequestData.Kind.File(content.body, content.mimeType)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ data class BubbleState(
val isMine: Boolean,
val isHighlighted: Boolean,
val timelineRoomInfo: TimelineRoomInfo,
val displayBackground: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ internal fun aBubbleState(
isMine: Boolean = false,
isHighlighted: Boolean = false,
timelineRoomInfo: TimelineRoomInfo = aTimelineRoomInfo(),
displayBackground: Boolean = true,
) = BubbleState(
groupPosition = groupPosition,
isMine = isMine,
isHighlighted = isHighlighted,
timelineRoomInfo = timelineRoomInfo,
displayBackground = displayBackground,
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ fun TimelineItemEventContent.isEdited(): Boolean =
is TimelineItemPollContent -> isEdited
else -> false
}

fun TimelineItemEventContent.hasMediaThumbnail(): Boolean =
when (this) {
is TimelineItemImageContent -> true
is TimelineItemVideoContent -> true
else -> false
}

0 comments on commit 2b76aeb

Please sign in to comment.