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-199] Implement ComposerActionsTheme for customizing the message composer action icons. #5535

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

VelikovPetar
Copy link
Contributor

🎯 Goal

Linear: https://linear.app/stream/issue/AND-199/implement-icon-customisation-options-for-messagecomposer-in-compose
Exposes a way to customise the default message composer icons (attachments / commands / send) without overriding each component separately.

🛠 Implementation details

  • Define new ComposerActionsTheme which holds an IconContainerStyle for each default action in the composer (attachments / commands / send)
  • Expose the actionsTheme : ComposerActionsTheme via the MessageComposerTheme
  • The composer action icons styling is now taken from ChatTheme.messageComposerTheme.actionsTheme

Example (overriding the default attachments button):

val actionsTheme = ComposerActionsTheme.defaultTheme(colors)
val messageComposerTheme = MessageComposerTheme
      .defaultTheme(isInDarkMode, typography, shapes, colors)
      .copy(
          actionsTheme = actionsTheme.copy(
              attachmentsButton = IconContainerStyle(
                  size = ComponentSize.square(48.dp),
                  padding = ComponentPadding.all(8.dp),
                  icon = IconStyle(
                     painter = painterResource(id = R.drawable.stream_compose_ic_image_picker),
                     tint = colors.textLowEmphasis,
                     size = ComponentSize.square(32.dp),
                  )
              ),
            )
        )
ChatTheme(
  // ...
  messageComposerTheme = messageComposerTheme
) { }

Will produce the following message composer (sample app):

Example
example

🧪 Testing

  1. Apply the provided patch
  2. Open the compose sample app
  3. Open a channel
  4. The message composer should have an updated "Attachments" icon
Provide the patch summary here
Index: stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
--- a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(revision 803974da8bc950749488d85adfade6ccdb394d6b)
+++ b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(date 1735059477925)
@@ -80,6 +80,11 @@
 import io.getstream.chat.android.compose.ui.messages.list.MessageList
 import io.getstream.chat.android.compose.ui.theme.AttachmentPickerTheme
 import io.getstream.chat.android.compose.ui.theme.ChatTheme
+import io.getstream.chat.android.compose.ui.theme.ComponentPadding
+import io.getstream.chat.android.compose.ui.theme.ComponentSize
+import io.getstream.chat.android.compose.ui.theme.ComposerActionsTheme
+import io.getstream.chat.android.compose.ui.theme.IconContainerStyle
+import io.getstream.chat.android.compose.ui.theme.IconStyle
 import io.getstream.chat.android.compose.ui.theme.MessageComposerTheme
 import io.getstream.chat.android.compose.ui.theme.MessageOptionsTheme
 import io.getstream.chat.android.compose.ui.theme.MessageTheme
@@ -151,7 +156,22 @@
         val colors = if (isInDarkMode) StreamColors.defaultDarkColors() else StreamColors.defaultColors()
         val typography = StreamTypography.defaultTypography()
         val shapes = StreamShapes.defaultShapes()
-        val messageComposerTheme = MessageComposerTheme.defaultTheme(isInDarkMode, typography, shapes, colors)
+        val actionsTheme = ComposerActionsTheme.defaultTheme(colors)
+        val messageComposerTheme = MessageComposerTheme
+            .defaultTheme(isInDarkMode, typography, shapes, colors)
+            .copy(
+                actionsTheme = actionsTheme.copy(
+                    attachmentsButton = IconContainerStyle(
+                        size = ComponentSize.square(48.dp),
+                        padding = ComponentPadding.all(8.dp),
+                        icon = IconStyle(
+                            painter = painterResource(id = R.drawable.stream_compose_ic_image_picker),
+                            tint = colors.textLowEmphasis,
+                            size = ComponentSize.square(32.dp),
+                        )
+                    ),
+                )
+            )
         val ownMessageTheme = MessageTheme.defaultOwnTheme(isInDarkMode, typography, shapes, colors)
         ChatTheme(
             isInDarkMode = isInDarkMode,
@@ -162,19 +182,7 @@
             autoTranslationEnabled = ChatApp.autoTranslationEnabled,
             isComposerLinkPreviewEnabled = ChatApp.isComposerLinkPreviewEnabled,
             allowUIAutomationTest = true,
-            messageComposerTheme = messageComposerTheme.let {
-                it.copy(
-                    attachmentCancelIcon = it.attachmentCancelIcon.copy(
-                        painter = painterResource(id = R.drawable.stream_compose_ic_clear),
-                        tint = colors.overlayDark,
-                        backgroundColor = colors.appBackground,
-                    ),
-                    audioRecording = it.audioRecording.copy(
-                        enabled = true,
-                        showRecordButtonOverSend = false,
-                    ),
-                )
-            },
+            messageComposerTheme = messageComposerTheme,
             attachmentPickerTheme = AttachmentPickerTheme.defaultTheme(colors).copy(
                 backgroundOverlay = colors.overlayDark,
                 backgroundSecondary = colors.inputBackground,

@VelikovPetar VelikovPetar marked this pull request as ready for review December 25, 2024 08:06
@VelikovPetar VelikovPetar requested a review from a team as a code owner December 25, 2024 08:06
Copy link
Member

@skydoves skydoves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

* @param commandsButton The style for the commands button.
* @param sendButton The style for the send button.
*/
public data class ComposerActionsTheme(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can attach @Immuable annotation here to make sure the properties of this theme style wouldn't be changed after the initial creation.

Copy link
Contributor

github-actions bot commented Jan 6, 2025

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 3.04 MB 3.04 MB 0.00 MB 🟢
stream-chat-android-offline 3.25 MB 3.25 MB 0.00 MB 🟢
stream-chat-android-ui-components 7.91 MB 7.91 MB 0.00 MB 🟢
stream-chat-android-compose 9.03 MB 9.04 MB 0.00 MB 🟢

PetarVelikov added 2 commits January 6, 2025 09:22
# Conflicts:
#	stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/MessageComposer.kt
CHANGELOG.md Outdated
@@ -12,7 +12,7 @@

## stream-chat-android-client
### 🐞 Fixed
- Fix `ChatClient::queryBlockedMembers` not working. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532)
- Fix `ChatClient::queryBlockedUsers` not working. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised that I previously made a typo in the changelog (the correct name is queryBlockedUsers), so I updated it here. I can revert this change and fix it separately, so that it is not confusing why is it in this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed here: c229890 (I will fix the changeling in a separate PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants