Skip to content

Commit 72945a7

Browse files
authored
Update design of message dividers (#6176)
* Update design of message dividers * Update padding and string resolution
1 parent 930e090 commit 72945a7

11 files changed

Lines changed: 90 additions & 235 deletions

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 14 additions & 45 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.ui.messages.list
18+
19+
import androidx.compose.foundation.background
20+
import androidx.compose.foundation.layout.Arrangement
21+
import androidx.compose.foundation.layout.Box
22+
import androidx.compose.foundation.layout.Column
23+
import androidx.compose.foundation.layout.padding
24+
import androidx.compose.foundation.shape.CircleShape
25+
import androidx.compose.material3.Text
26+
import androidx.compose.runtime.Composable
27+
import androidx.compose.ui.Alignment
28+
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.tooling.preview.Preview
30+
import io.getstream.chat.android.compose.ui.theme.ChatTheme
31+
import io.getstream.chat.android.compose.ui.theme.StreamTokens
32+
33+
@Composable
34+
internal fun MessageDivider(text: String, modifier: Modifier = Modifier) {
35+
val colors = ChatTheme.colors
36+
37+
Box(modifier, contentAlignment = Alignment.Center) {
38+
Text(
39+
text = text,
40+
style = ChatTheme.typography.metadataEmphasis,
41+
color = colors.chatTextSystem,
42+
modifier = Modifier
43+
.background(colors.backgroundCoreSurfaceSubtle, CircleShape)
44+
.padding(vertical = StreamTokens.spacing2xs, horizontal = StreamTokens.spacingSm),
45+
)
46+
}
47+
}
48+
49+
@Preview
50+
@Composable
51+
private fun MessageDividerPreview() {
52+
ChatTheme {
53+
Column(
54+
horizontalAlignment = Alignment.CenterHorizontally,
55+
verticalArrangement = Arrangement.spacedBy(StreamTokens.spacingXs),
56+
) {
57+
MessageDivider("Unread messages")
58+
MessageDivider("Today")
59+
MessageDivider("Tue, 25 Dec")
60+
}
61+
}
62+
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/MessageItem.kt

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import androidx.compose.foundation.layout.Box
2121
import androidx.compose.foundation.layout.fillMaxWidth
2222
import androidx.compose.foundation.layout.padding
2323
import androidx.compose.foundation.lazy.LazyItemScope
24-
import androidx.compose.foundation.shape.RoundedCornerShape
25-
import androidx.compose.material3.Surface
2624
import androidx.compose.material3.Text
2725
import androidx.compose.runtime.Composable
2826
import androidx.compose.runtime.getValue
@@ -45,6 +43,7 @@ import androidx.compose.ui.unit.dp
4543
import io.getstream.chat.android.compose.R
4644
import io.getstream.chat.android.compose.state.mediagallerypreview.MediaGalleryPreviewResult
4745
import io.getstream.chat.android.compose.ui.theme.ChatTheme
46+
import io.getstream.chat.android.compose.ui.theme.StreamTokens
4847
import io.getstream.chat.android.models.Message
4948
import io.getstream.chat.android.models.Option
5049
import io.getstream.chat.android.models.Poll
@@ -162,27 +161,15 @@ public fun LazyItemScope.MessageItem(
162161
*/
163162
@Composable
164163
internal fun DefaultMessageDateSeparatorContent(dateSeparator: DateSeparatorItemState) {
165-
Box(
164+
MessageDivider(
165+
text = ChatTheme.dateFormatter.formatRelativeDate(dateSeparator.date),
166166
modifier = Modifier
167-
.semantics(mergeDescendants = true) {}
167+
.semantics(mergeDescendants = true) {
168+
testTag = "Stream_MessageDateSeparator"
169+
}
170+
.padding(vertical = StreamTokens.spacingXs)
168171
.fillMaxWidth(),
169-
contentAlignment = Alignment.Center,
170-
) {
171-
Surface(
172-
modifier = Modifier
173-
.padding(vertical = 8.dp),
174-
color = ChatTheme.messageDateSeparatorTheme.backgroundColor,
175-
shape = RoundedCornerShape(16.dp),
176-
) {
177-
Text(
178-
modifier = Modifier
179-
.padding(vertical = 2.dp, horizontal = 16.dp)
180-
.testTag("Stream_MessageDateSeparator"),
181-
text = ChatTheme.dateFormatter.formatRelativeDate(dateSeparator.date),
182-
style = ChatTheme.messageDateSeparatorTheme.textStyle,
183-
)
184-
}
185-
}
172+
)
186173
}
187174

188175
/**
@@ -192,24 +179,15 @@ internal fun DefaultMessageDateSeparatorContent(dateSeparator: DateSeparatorItem
192179
*/
193180
@Composable
194181
internal fun DefaultMessageUnreadSeparatorContent(unreadSeparatorItemState: UnreadSeparatorItemState) {
195-
Box(
182+
MessageDivider(
183+
text = stringResource(R.string.stream_compose_message_list_unread_separator),
196184
modifier = Modifier
197185
.semantics(mergeDescendants = true) {
198186
testTag = "Stream_UnreadMessagesBadge"
199187
}
200-
.fillMaxWidth()
201-
.padding(bottom = 8.dp)
202-
.background(ChatTheme.messageUnreadSeparatorTheme.backgroundColor),
203-
contentAlignment = Alignment.Center,
204-
) {
205-
Text(
206-
modifier = Modifier.padding(vertical = 2.dp, horizontal = 16.dp),
207-
text = LocalContext.current.resources.getString(
208-
R.string.stream_compose_message_list_unread_separator,
209-
),
210-
style = ChatTheme.messageUnreadSeparatorTheme.textStyle,
211-
)
212-
}
188+
.padding(vertical = StreamTokens.spacingXs)
189+
.fillMaxWidth(),
190+
)
213191
}
214192

215193
/**

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/ChatTheme.kt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ private val LocalReadCountEnabled = compositionLocalOf<Boolean> {
198198
"Make sure to wrap all usages of Stream components in a ChatTheme.",
199199
)
200200
}
201-
private val LocalMessageDateSeparatorTheme = compositionLocalOf<MessageDateSeparatorTheme> {
202-
error("No MessageDateSeparatorTheme provided! Make sure to wrap all usages of Stream components in a ChatTheme.")
203-
}
204-
private val LocalMessageUnreadSeparatorTheme = compositionLocalOf<MessageUnreadSeparatorTheme> {
205-
error("No MessageUnreadSeparatorTheme provided! Make sure to wrap all usages of Stream components in a ChatTheme.")
206-
}
207201
private val LocalMessageComposerTheme = compositionLocalOf<MessageComposerTheme> {
208202
error("No MessageComposerTheme provided! Make sure to wrap all usages of Stream components in a ChatTheme.")
209203
}
@@ -284,13 +278,10 @@ private val LocalChatConfig = compositionLocalOf<ChatConfig> {
284278
* @param messageAlignmentProvider [MessageAlignmentProvider] Used to provide message alignment for the given message.
285279
* @param messageOptionsTheme [MessageOptionsTheme] Theme for the message option list in the selected message menu.
286280
* For theming the reaction option list in the same menu, use [reactionOptionsTheme].
287-
* @param messageOptionsUserReactionAlignment Alignment of the user reaction inside the message options.
288281
* @param videoThumbnailsEnabled Dictates whether video thumbnails will be displayed inside video previews.
289282
* @param streamCdnImageResizing Sets the strategy for resizing images hosted on Stream's CDN. Disabled by default,
290283
* set [StreamCdnImageResizing.imageResizingEnabled] to true if you wish to enable resizing images. Note that resizing
291284
* applies only to images hosted on Stream's CDN which contain the original height (oh) and width (ow) query parameters.
292-
* @param messageDateSeparatorTheme Theme of the message date separator.
293-
* @param messageUnreadSeparatorTheme Theme of the message unread separator.
294285
* @param messageComposerTheme Theme of the message composer.
295286
* @param attachmentPickerTheme Theme of the attachment picker.
296287
* @param streamMediaRecorder Used for recording audio messages.
@@ -349,14 +340,6 @@ public fun ChatTheme(
349340
videoThumbnailsEnabled: Boolean = true,
350341
streamCdnImageResizing: StreamCdnImageResizing = StreamCdnImageResizing.defaultStreamCdnImageResizing(),
351342
readCountEnabled: Boolean = true,
352-
messageDateSeparatorTheme: MessageDateSeparatorTheme = MessageDateSeparatorTheme.defaultTheme(
353-
typography = typography,
354-
colors = colors,
355-
),
356-
messageUnreadSeparatorTheme: MessageUnreadSeparatorTheme = MessageUnreadSeparatorTheme.defaultTheme(
357-
typography = typography,
358-
colors = colors,
359-
),
360343
messageComposerTheme: MessageComposerTheme = MessageComposerTheme.defaultTheme(
361344
isInDarkMode = isInDarkMode,
362345
typography = typography,
@@ -404,8 +387,6 @@ public fun ChatTheme(
404387
LocalMessagePreviewFormatter provides messagePreviewFormatter,
405388
LocalMessageTextFormatter provides messageTextFormatter,
406389
LocalSearchResultNameFormatter provides searchResultNameFormatter,
407-
LocalMessageDateSeparatorTheme provides messageDateSeparatorTheme,
408-
LocalMessageUnreadSeparatorTheme provides messageUnreadSeparatorTheme,
409390
LocalMessageComposerTheme provides messageComposerTheme,
410391
LocalAttachmentPickerTheme provides attachmentPickerTheme,
411392
LocalStreamImageLoader provides imageLoaderFactory.imageLoader(LocalContext.current.applicationContext),
@@ -666,22 +647,6 @@ public object ChatTheme {
666647
@ReadOnlyComposable
667648
get() = LocalReadCountEnabled.current
668649

669-
/**
670-
* Retrieves the current [MessageDateSeparatorTheme] at the call site's position in the hierarchy.
671-
*/
672-
public val messageDateSeparatorTheme: MessageDateSeparatorTheme
673-
@Composable
674-
@ReadOnlyComposable
675-
get() = LocalMessageDateSeparatorTheme.current
676-
677-
/**
678-
* Retrieves the current [MessageUnreadSeparatorTheme] at the call site's position in the hierarchy.
679-
*/
680-
public val messageUnreadSeparatorTheme: MessageUnreadSeparatorTheme
681-
@Composable
682-
@ReadOnlyComposable
683-
get() = LocalMessageUnreadSeparatorTheme.current
684-
685650
/**
686651
* Retrieves the current [MessageComposerTheme] at the call site's position in the hierarchy.
687652
*/

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/MessageDateSeparatorTheme.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/MessageUnreadSeparatorTheme.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/StreamColors.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public data class StreamColors(
205205
public val chatTextOutgoing: Color = textPrimary,
206206
public val chatTextLink: Color = accentPrimary,
207207
public val chatTextMention: Color = chatTextLink,
208+
public val chatTextSystem: Color = textSecondary,
208209
public val chatTextTimestamp: Color = textTertiary,
209210
public val chatWaveformBar: Color = borderCoreOpacity25,
210211
public val chatWaveformBarPlaying: Color = accentPrimary,
-758 Bytes
Loading
Loading
Loading

0 commit comments

Comments
 (0)