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
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.
isAttachmentPickerVisible
If the attachment picker is visible or not.
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.
Handler for the default Attachments integration.
Handler when the input field value changes.
Handler when the user taps on the cancel/delete attachment action.
Handler for the cancel button on Message actions, such as Edit and Reply.
Handler when the user taps on a link preview.
Handler when the user taps on the cancel link preview.
Handler when the user taps on a user suggestion item.
Handler when the user taps on a command suggestion item.
onAlsoSendToChannelChange
Handler when the "Also send to channel" checkbox is changed.
Called when the user taps the dismiss button on the active command chip.
The actions that can be performed on an audio recording.
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
The state of the message input.
Handler when the user wants to send a message.
isAttachmentPickerVisible
If the attachment picker is visible or not.
Handler for the default Attachments integration.
Handler when the input field value changes.
Handler when the user taps on the cancel/delete attachment action.
Handler for the cancel button on Message actions, such as Edit and Reply.
Handler when the user taps on a link preview.
Handler when the user taps on the cancel link preview.
Handler when the user taps on a user suggestion item.
Handler when the user taps on a command suggestion item.
onAlsoSendToChannelChange
Handler when the "Also send to channel" checkbox is changed.
Called when the user taps the dismiss button on the active command chip.
The actions that can be performed on an audio recording.
Customizable composable that represents the input field for the composer, MessageInput by default.