Skip to content

Commit

Permalink
fix: message padding [WPB-5059] (#2384)
Browse files Browse the repository at this point in the history
Co-authored-by: Oussama Hassine <[email protected]>
  • Loading branch information
Garzas and ohassine authored Nov 1, 2023
1 parent e6aef5d commit ca803a7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ fun MessageList(
reverseLayout = true,
// calculating bottom padding to have space for [UsersTypingIndicator]
contentPadding = PaddingValues(
bottom = dimensions().typingIndicatorHeight - (dimensions().messageItemBottomPadding / 2)
bottom = dimensions().typingIndicatorHeight - dimensions().messageItemVerticalPadding
),
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -42,12 +43,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.ui.graphics.Color
import com.wire.android.R
import com.wire.android.media.audiomessage.AudioState
import com.wire.android.model.Clickable
Expand Down Expand Up @@ -82,7 +81,6 @@ import com.wire.android.ui.home.conversations.model.messagetypes.asset.Restricte
import com.wire.android.ui.home.conversations.model.messagetypes.audio.AudioMessage
import com.wire.android.ui.home.conversations.model.messagetypes.image.ImageMessageParams
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.user.UserId
Expand Down Expand Up @@ -141,12 +139,8 @@ fun MessageItem(
}

Box(backgroundColorModifier) {
val fullAvatarOuterPadding = if (showAuthor) {
dimensions().avatarClickablePadding + dimensions().avatarStatusBorderSize
} else {
0.dp
}
val halfItemBottomPadding = dimensions().messageItemBottomPadding / 2
// padding needed to have same top padding for avatar and rest composables in message item
val fullAvatarOuterPadding = dimensions().avatarClickablePadding + dimensions().avatarStatusBorderSize
Row(
Modifier
.fillMaxWidth()
Expand All @@ -156,31 +150,42 @@ fun MessageItem(
onLongClick = remember(message) { { onLongClicked(message) } }
)
.padding(
end = dimensions().spacing12x,
top = halfItemBottomPadding - fullAvatarOuterPadding,
bottom = halfItemBottomPadding
end = dimensions().messageItemHorizontalPadding,
top = dimensions().messageItemVerticalPadding - fullAvatarOuterPadding,
bottom = dimensions().messageItemVerticalPadding
)
) {
Spacer(Modifier.padding(start = dimensions().spacing8x - fullAvatarOuterPadding))

val isProfileRedirectEnabled =
header.userId != null &&
!(header.isSenderDeleted || header.isSenderUnavailable)

if (showAuthor) {
val avatarClickable = remember {
Clickable(enabled = isProfileRedirectEnabled) {
onOpenProfile(header.userId!!.toString())
Box(
modifier = Modifier.width(dimensions().spacing56x),
contentAlignment = Alignment.TopStart
) {
if (showAuthor) {
val avatarClickable = remember {
Clickable(enabled = isProfileRedirectEnabled) {
onOpenProfile(header.userId!!.toString())
}
}
// because avatar takes start padding we don't need to add padding to message item
UserProfileAvatar(
avatarData = message.userAvatarData,
clickable = avatarClickable
)
} else {
// imitating width of space that avatar takes
Spacer(
Modifier.width(
dimensions().avatarDefaultSize
+ (dimensions().avatarStatusBorderSize * 2)
+ (dimensions().avatarClickablePadding * 2)
)
)
}
UserProfileAvatar(
avatarData = message.userAvatarData,
clickable = avatarClickable
)
} else {
Spacer(Modifier.width(MaterialTheme.wireDimensions.avatarDefaultSize))
}
Spacer(Modifier.padding(start = dimensions().spacing16x - fullAvatarOuterPadding))
Spacer(Modifier.width(dimensions().messageItemHorizontalPadding - fullAvatarOuterPadding))
Column {
Spacer(modifier = Modifier.height(fullAvatarOuterPadding))
if (showAuthor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ fun SystemMessageItem(
.customizeMessageBackground(message.sendingFailed, message.decryptionFailed)
.padding(
end = dimensions().spacing16x,
start = dimensions().spacing8x,
top = fullAvatarOuterPadding,
bottom = dimensions().messageItemBottomPadding - fullAvatarOuterPadding
bottom = dimensions().messageItemVerticalPadding
)
.fillMaxWidth()
) {
Box(
modifier = Modifier
.width(dimensions().avatarDefaultSize),
.width(dimensions().spacing56x)
.padding(end = fullAvatarOuterPadding),
contentAlignment = Alignment.TopEnd
) {
if (message.messageContent.iconResId != null) {
Expand All @@ -140,7 +140,7 @@ fun SystemMessageItem(
}
}
}
Spacer(Modifier.padding(start = dimensions().spacing16x))
Spacer(Modifier.padding(start = dimensions().messageItemHorizontalPadding - fullAvatarOuterPadding))
Column(
Modifier
.defaultMinSize(minHeight = dimensions().spacing20x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ data class WireDimensions(
val initiatingCallHangUpButtonSize: Dp,
val ongoingCallLabelHeight: Dp,
// Message item
val messageItemBottomPadding: Dp,
val messageItemVerticalPadding: Dp,
val messageItemHorizontalPadding: Dp,
// audio message
val audioMessageHeight: Dp,
// Conversation options
Expand Down Expand Up @@ -329,7 +330,8 @@ private val DefaultPhonePortraitWireDimensions: WireDimensions = WireDimensions(
defaultIncomingCallSheetPeekHeight = 280.dp,
callingIncomingUserAvatarSize = 128.dp,
initiatingCallHangUpButtonSize = 72.dp,
messageItemBottomPadding = 16.dp,
messageItemVerticalPadding = 8.dp,
messageItemHorizontalPadding = 12.dp,
conversationOptionsItemMinHeight = 57.dp,
ongoingCallLabelHeight = 28.dp,
audioMessageHeight = 48.dp,
Expand Down

0 comments on commit ca803a7

Please sign in to comment.