MessageComposer

fun MessageComposer(viewModel: MessageComposerViewModel, modifier: Modifier = Modifier, isAttachmentPickerVisible: Boolean = false, onSendMessage: (Message) -> Unit = { viewModel.sendMessage(it) }, onAttachmentsClick: () -> Unit = {}, onValueChange: (String) -> Unit = { viewModel.setMessageInput(it) }, onAttachmentRemoved: (Attachment) -> Unit = { viewModel.removeAttachment(it) }, onCancelAction: () -> Unit = { viewModel.dismissMessageActions() }, onLinkPreviewClick: (LinkPreview) -> Unit? = null, onCancelLinkPreviewClick: () -> Unit? = { viewModel.cancelLinkPreview() }, onUserSelected: (User) -> Unit = { viewModel.selectMention(it) }, onCommandSelected: (Command) -> Unit = { viewModel.selectCommand(it) }, onAlsoSendToChannelChange: (Boolean) -> Unit = viewModel::setAlsoSendToChannel, onActiveCommandDismiss: () -> Unit = viewModel::clearActiveCommand, recordingActions: AudioRecordingActions = AudioRecordingActions.defaultActions( viewModel = viewModel, sendOnComplete = ChatTheme.config.composer.audioRecordingSendOnComplete, ), input: @Composable RowScope.(MessageComposerState) -> Unit = { state -> val inputFocusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { viewModel.inputFocusEvents.collect { inputFocusRequester.requestFocus() } } ChatTheme.componentFactory.MessageComposerInput( params = MessageComposerInputParams( modifier = Modifier .weight(1f) .focusRequester(inputFocusRequester), state = state, onInputChanged = onValueChange, onAttachmentRemoved = onAttachmentRemoved, onLinkPreviewClick = onLinkPreviewClick, onCancelLinkPreviewClick = onCancelLinkPreviewClick, onCancel = onCancelAction, onSendClick = { input, attachments -> val message = viewModel.buildNewMessage(input, attachments) onSendMessage(message) }, onAlsoSendToChannelChange = onAlsoSendToChannelChange, recordingActions = recordingActions, onActiveCommandDismiss = onActiveCommandDismiss, ), ) })

Default MessageComposer component that relies on MessageComposerViewModel to handle data and communicate various events.

Parameters

viewModel

The ViewModel that provides pieces of data to show in the composer, like the currently selected integration data or the user input. It also handles sending messages.

modifier

Modifier for styling.

isAttachmentPickerVisible

If the attachment picker is visible or not.

onSendMessage

Handler when the user sends a message. By default it delegates this to the ViewModel, but the user can override if they want more custom behavior.

onAttachmentsClick

Handler for the default Attachments integration.

onValueChange

Handler when the input field value changes.

onAttachmentRemoved

Handler when the user taps on the cancel/delete attachment action.

onCancelAction

Handler for the cancel button on Message actions, such as Edit and Reply.

onLinkPreviewClick

Handler when the user taps on a link preview.

onCancelLinkPreviewClick

Handler when the user taps on the cancel link preview.

onUserSelected

Handler when the user taps on a user suggestion item.

onCommandSelected

Handler when the user taps on a command suggestion item.

onAlsoSendToChannelChange

Handler when the "Also send to channel" checkbox is changed.

onActiveCommandDismiss

Called when the user taps the dismiss button on the active command chip.

recordingActions

The actions that can be performed on an audio recording.

input

Customizable composable that represents the input field for the composer, MessageInput by default.


fun MessageComposer(messageComposerState: MessageComposerState, onSendMessage: (String, List<Attachment>) -> Unit, modifier: Modifier = Modifier, isAttachmentPickerVisible: Boolean = false, onAttachmentsClick: () -> Unit = {}, onValueChange: (String) -> Unit = {}, onAttachmentRemoved: (Attachment) -> Unit = {}, onCancelAction: () -> Unit = {}, onLinkPreviewClick: (LinkPreview) -> Unit? = null, onCancelLinkPreviewClick: () -> Unit? = null, onUserSelected: (User) -> Unit = {}, onCommandSelected: (Command) -> Unit = {}, onAlsoSendToChannelChange: (Boolean) -> Unit = {}, onActiveCommandDismiss: () -> Unit = {}, recordingActions: AudioRecordingActions = AudioRecordingActions.None, input: @Composable RowScope.(MessageComposerState) -> Unit = { state -> ChatTheme.componentFactory.MessageComposerInput( params = MessageComposerInputParams( modifier = Modifier.weight(1f), state = state, onInputChanged = onValueChange, onAttachmentRemoved = onAttachmentRemoved, onCancel = onCancelAction, onLinkPreviewClick = onLinkPreviewClick, onCancelLinkPreviewClick = onCancelLinkPreviewClick, onSendClick = onSendMessage, onAlsoSendToChannelChange = onAlsoSendToChannelChange, recordingActions = recordingActions, onActiveCommandDismiss = onActiveCommandDismiss, ), ) })

Clean version of the MessageComposer that doesn't rely on ViewModels, so the user can provide a manual way to handle and represent data and various operations.

Parameters

messageComposerState

The state of the message input.

onSendMessage

Handler when the user wants to send a message.

modifier

Modifier for styling.

isAttachmentPickerVisible

If the attachment picker is visible or not.

onAttachmentsClick

Handler for the default Attachments integration.

onValueChange

Handler when the input field value changes.

onAttachmentRemoved

Handler when the user taps on the cancel/delete attachment action.

onCancelAction

Handler for the cancel button on Message actions, such as Edit and Reply.

onLinkPreviewClick

Handler when the user taps on a link preview.

onCancelLinkPreviewClick

Handler when the user taps on the cancel link preview.

onUserSelected

Handler when the user taps on a user suggestion item.

onCommandSelected

Handler when the user taps on a command suggestion item.

onAlsoSendToChannelChange

Handler when the "Also send to channel" checkbox is changed.

onActiveCommandDismiss

Called when the user taps the dismiss button on the active command chip.

recordingActions

The actions that can be performed on an audio recording.

input

Customizable composable that represents the input field for the composer, MessageInput by default.