Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AND-160] Make mentions color customisable (Compose) #5528

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
- Add `MessageOptionItemVisibility.isBlockUserVisible` property to show/hide the block user option. [#5512](https://github.com/GetStream/stream-chat-android/pull/5512)
- Add `ChatTheme.channelOptionsTheme` property to customize the channel options. [#5513](https://github.com/GetStream/stream-chat-android/pull/5513)
- Add `SearchResultItemState.channel` property containing the cached info of the channel where the message was sent. [#5500](https://github.com/GetStream/stream-chat-android/pull/5500)
- Add `MessageTheme.mentionColor` property for customizing the mentions color in messages. [#5528](https://github.com/GetStream/stream-chat-android/pull/5528)

### ⚠️ Changed
- 🚨 Breaking change: The `SearchResultNameFormatter.formatMessageTitle` method receives a `SearchResultItemState` instead of a `Message`. [#5500](https://github.com/GetStream/stream-chat-android/pull/5500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2386,10 +2386,11 @@ public final class io/getstream/chat/android/compose/ui/theme/MessageOptionsThem
public final class io/getstream/chat/android/compose/ui/theme/MessageTheme {
public static final field $stable I
public static final field Companion Lio/getstream/chat/android/compose/ui/theme/MessageTheme$Companion;
public synthetic fun <init> (Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;JLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Landroidx/compose/ui/text/TextStyle;
public final fun component10 ()Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;
public final fun component11 ()Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;
public final fun component12-0d7_KjU ()J
public final fun component2 ()Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;
public final fun component3-0d7_KjU ()J
public final fun component4 ()Landroidx/compose/foundation/BorderStroke;
Expand All @@ -2398,15 +2399,16 @@ public final class io/getstream/chat/android/compose/ui/theme/MessageTheme {
public final fun component7-0d7_KjU ()J
public final fun component8-0d7_KjU ()J
public final fun component9 ()Lio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;
public final fun copy-pk3EwZ4 (Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;)Lio/getstream/chat/android/compose/ui/theme/MessageTheme;
public static synthetic fun copy-pk3EwZ4$default (Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;ILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/theme/MessageTheme;
public final fun copy-D31MQNc (Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;J)Lio/getstream/chat/android/compose/ui/theme/MessageTheme;
public static synthetic fun copy-D31MQNc$default (Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Landroidx/compose/ui/text/TextStyle;Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;JLandroidx/compose/foundation/BorderStroke;Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;Landroidx/compose/ui/text/TextStyle;JJLio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;JILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/theme/MessageTheme;
public fun equals (Ljava/lang/Object;)Z
public final fun getAudioRecording ()Lio/getstream/chat/android/compose/ui/theme/messages/attachments/AudioRecordingAttachmentTheme;
public final fun getBackgroundBorder ()Landroidx/compose/foundation/BorderStroke;
public final fun getBackgroundColor-0d7_KjU ()J
public final fun getBackgroundShapes ()Lio/getstream/chat/android/compose/ui/theme/MessageBackgroundShapes;
public final fun getContentPadding ()Lio/getstream/chat/android/compose/ui/theme/ComponentPadding;
public final fun getDeletedBackgroundColor-0d7_KjU ()J
public final fun getMentionColor-0d7_KjU ()J
public final fun getPoll ()Lio/getstream/chat/android/compose/ui/theme/messages/list/PollMessageStyle;
public final fun getQuoted ()Lio/getstream/chat/android/compose/ui/theme/messages/list/QuotedMessageStyle;
public final fun getQuotedBackgroundColor-0d7_KjU ()J
Expand Down Expand Up @@ -3363,7 +3365,7 @@ public abstract interface class io/getstream/chat/android/compose/ui/util/Messag

public final class io/getstream/chat/android/compose/ui/util/MessageTextFormatter$Companion {
public final fun composite ([Lio/getstream/chat/android/compose/ui/util/MessageTextFormatter;)Lio/getstream/chat/android/compose/ui/util/MessageTextFormatter;
public final fun defaultFormatter (ZZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/MessageTextFormatter;
public final fun defaultFormatter (ZZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/MessageTextFormatter;
public final fun defaultFormatter (ZZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamShapes;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/MessageTextFormatter;
}

Expand All @@ -3384,7 +3386,7 @@ public abstract interface class io/getstream/chat/android/compose/ui/util/Quoted
public final class io/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter$Companion {
public final fun composite ([Lio/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter;)Lio/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter;
public final fun defaultFormatter (ZLandroid/content/Context;ZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lio/getstream/chat/android/compose/ui/theme/StreamShapes;Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Lio/getstream/chat/android/compose/ui/theme/MessageTheme;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter;
public final fun defaultFormatter (ZLandroid/content/Context;ZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lio/getstream/chat/android/compose/ui/theme/StreamShapes;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter;
public final fun defaultFormatter (ZLandroid/content/Context;ZLio/getstream/chat/android/compose/ui/theme/StreamTypography;Lio/getstream/chat/android/compose/ui/theme/StreamColors;Lio/getstream/chat/android/compose/ui/theme/StreamShapes;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)Lio/getstream/chat/android/compose/ui/util/QuotedMessageTextFormatter;
}

public final class io/getstream/chat/android/compose/ui/util/ReactionDrawable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public open class MessageContentFactory {
currentUser = currentUser,
onLongItemClick = onLongItemClick,
onLinkClick = onLinkClick,
onUserMentionClick = onUserMentionClick,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import io.getstream.chat.android.compose.ui.theme.messages.list.QuotedMessageSty
* @param quotedBackgroundColor The background color for the quoted messages.
* @param deletedBackgroundColor The background color for the deleted messages.
* @param audioRecording The theming for the audio recording attachment.
* @param mentionColor The color for the mentions in the messages.
*/
@Immutable
public data class MessageTheme(
Expand Down Expand Up @@ -71,6 +72,7 @@ public data class MessageTheme(
val audioRecording: AudioRecordingAttachmentTheme,
val quoted: QuotedMessageStyle,
val poll: PollMessageStyle,
val mentionColor: Color,
) {
public companion object {

Expand Down Expand Up @@ -188,6 +190,7 @@ public data class MessageTheme(
colors = colors,
shapes = shapes,
),
mentionColor = colors.primaryAccent,
).let { theme ->
theme.copy(
quoted = theme.quoted.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.getstream.chat.android.compose.ui.util

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import io.getstream.chat.android.compose.ui.theme.ChatTheme
Expand Down Expand Up @@ -68,9 +69,17 @@ public fun interface MessageTextFormatter {
else -> StreamColors.defaultColors()
},
textStyle: (isMine: Boolean) -> TextStyle = defaultTextStyle(isInDarkMode, typography, colors),
mentionColor: (isMine: Boolean) -> Color = defaultMentionColor(isInDarkMode, typography, colors),
builder: AnnotatedMessageTextBuilder? = null,
): MessageTextFormatter {
return DefaultMessageTextFormatter(autoTranslationEnabled, typography, colors, textStyle, builder)
return DefaultMessageTextFormatter(
autoTranslationEnabled = autoTranslationEnabled,
typography = typography,
colors = colors,
textStyle = textStyle,
mentionColor = mentionColor,
builder = builder,
)
}

/**
Expand Down Expand Up @@ -111,7 +120,16 @@ public fun interface MessageTextFormatter {
builder: AnnotatedMessageTextBuilder? = null,
): MessageTextFormatter {
val textStyle = defaultTextStyle(ownMessageTheme, otherMessageTheme)
return defaultFormatter(autoTranslationEnabled, isInDarkMode, typography, colors, textStyle, builder)
val mentionColor = defaultMentionColor(ownMessageTheme, otherMessageTheme)
return defaultFormatter(
autoTranslationEnabled = autoTranslationEnabled,
isInDarkMode = isInDarkMode,
typography = typography,
colors = colors,
textStyle = textStyle,
mentionColor = mentionColor,
builder = builder,
)
}

@Composable
Expand Down Expand Up @@ -186,6 +204,7 @@ private class DefaultMessageTextFormatter(
private val typography: StreamTypography,
private val colors: StreamColors,
private val textStyle: (isMine: Boolean) -> TextStyle,
private val mentionColor: (isMine: Boolean) -> Color,
private val builder: AnnotatedMessageTextBuilder? = null,
) : MessageTextFormatter {

Expand All @@ -198,12 +217,13 @@ private class DefaultMessageTextFormatter(
}
val mentionedUserNames = message.mentionedUsers.map { it.name.ifEmpty { it.id } }
val textColor = textStyle(message.isMine(currentUser)).color
val mentionColor = mentionColor(message.isMine(currentUser))
return buildAnnotatedMessageText(
text = displayedText,
textColor = textColor,
textFontStyle = typography.body.fontStyle,
linkColor = colors.primaryAccent,
mentionsColor = colors.primaryAccent,
mentionsColor = mentionColor,
mentionedUserNames = mentionedUserNames,
builder = {
builder?.invoke(this, message, currentUser)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.compose.ui.util

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import io.getstream.chat.android.compose.ui.theme.MessageTheme
import io.getstream.chat.android.compose.ui.theme.StreamColors
import io.getstream.chat.android.compose.ui.theme.StreamShapes
import io.getstream.chat.android.compose.ui.theme.StreamTypography

/**
* Function that returns the color of the mentions text, depending on whether the message is mine or not.
*
* @param ownTheme The theme for messages from the current user.
* @param otherTheme The theme for messages from the other user.
*
* @return A function that returns the color of the mention text, based on whether the message is from the current user
* or from another user.
*/
@Composable
internal fun defaultMentionColor(
ownTheme: MessageTheme,
otherTheme: MessageTheme,
): (Boolean) -> Color {
return { isMine ->
if (isMine) ownTheme.mentionColor else otherTheme.mentionColor
}
}

/**
* Function that returns the color of the mentions text, depending on whether the message is mine or not.
*
* @param isInDarkMode Indicator if the app is in dark mode.
* @param typography The typography to use for styling.
* @param colors The colors to use for styling.
* @param shapes The shapes to use for styling.
*
* @return A function that returns the color of the mention text, based on whether the message is from the current user
* or from another user.
*/
@Composable
internal fun defaultMentionColor(
isInDarkMode: Boolean,
typography: StreamTypography,
colors: StreamColors,
shapes: StreamShapes = StreamShapes.defaultShapes(),
): (Boolean) -> Color {
val ownTheme = MessageTheme.defaultOwnTheme(isInDarkMode, typography, shapes, colors)
val otherTheme = MessageTheme.defaultOtherTheme(isInDarkMode, typography, shapes, colors)
return defaultMentionColor(ownTheme, otherTheme)
}
Loading
Loading