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

Introduce ChatComponentFactory #5565

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

andremion
Copy link
Collaborator

@andremion andremion commented Jan 17, 2025

🎯 Goal

Make it easier to customize UI elements used by stateless components.

🛠 Implementation details

ChatComponentFactory is introduced to create stateless components used by default throughout the Chat UI.

Example of a custom ChatComponentFactory implementation that changes the default UI of the trailing content of the channel list header element:

ChatTheme(
    componentFactory = ComponentFactory(
        channelListHeader = object : ChannelListHeader() {
            @Composable
            override fun RowScope.TrailingContent(
                onHeaderActionClick: () -> Unit,
            ) {
                IconButton(onClick = onHeaderActionClick) {
                    Icon(
                        imageVector = Icons.Default.Add,
                        contentDescription = "Add",
                    )
                }
            }
        }
    )
) {
    // Your Chat screens
}

ChatComponentFactory can also be extended in a separate class and passed to the ChatTheme as shown:

class MyComponentFactory : ComponentFactory(
    channelListHeader = object : ChannelListHeader() {
        @Composable
        override fun RowScope.TrailingContent(
            onHeaderActionClick: () -> Unit,
        ) {
            IconButton(onClick = onHeaderActionClick) {
                Icon(
                    imageVector = Icons.Default.Add,
                    contentDescription = "Add",
                )
            }
        }
    }
)
ChatTheme(
    componentFactory = MyComponentFactory()
) {
    // Your Chat screens
}

🧪 Testing

Update the ChannelsActivity of the Compose sample app, and set a new ChatComponentFactory to the ChatTheme with some customizations.

☑️Contributor Checklist

Code & documentation

  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (KDocs, docusaurus, tutorial)

☑️Reviewer Checklist

  • UI Components sample runs & works
  • Compose sample runs & works
  • UI Changes correct (before & after images)
  • Bugs validated (bugfixes)
  • New feature tested and works
  • Release notes and docs clearly describe changes
  • All code we touched has new or updated KDocs

🎉 GIF

gif

Copy link
Contributor

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.14 MB 9.15 MB 0.00 MB 🟢

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2.4% Coverage on New Code (required ≥ 80%)
6.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

1 participant