import { useContext } from "react";
import { MessageInputContext } from "stream-chat-react-native";
const { sendMessage, toggleAttachmentPicker } = useContext(MessageInputContext);
MessageInputContext
MessageInputContext
is provided by Channel
component. If you are not familiar with React Context API, please read about it on React docs.
Basic Usage
MessageInputContext
can be consumed by any of the child component of Channel
component as following:
Alternatively, you can also use useMessageInputContext
hook provided by library to consume MessageInputContext.
import { useMessageInputContext } from "stream-chat-react-native";
const { sendMessage, toggleAttachmentPicker } = useMessageInputContext();
Value
additionalTextInputProps
Additional props provided to the underlying TextInput within MessageInput
.
Type |
---|
object |
autoCompleteSuggestionsLimit
Maximum number of suggestions to display as part of autocomplete feature within input box.
Type | Default |
---|---|
number | 10 |
autoCompleteTriggerSettings
Function that returns the trigger settings for the auto complete input.
Type | Default |
---|---|
function | ACITriggerSettings |
clearEditingState
Function to clear “Editing Message” state from MessageInput component.
Type |
---|
function |
clearQuotedMessageState
Function to clear “Add Quoted Reply” state from MessageInput component.
Type |
---|
function |
compressImageQuality
Image compression quality prior to uploading.
On iOS values of 0.8 and above don’t reduce the quality noticeably in most images. A value of 0.8 will reduce the file size in iOS by approximately half compared to a value of 1.
Type | Default |
---|---|
number 0 to 1 (1 is best quality) | iOS: 0.8 Android: 1 |
doDocUploadRequest
Override of the file upload request when a user selects a file from the file picker.
The function must return a Promise
that is resolved to an object with the key file
that is the URL of the uploaded file.
This can be used to store file attachments in your own custom CDN.
Type |
---|
function |
Parameter | Description |
---|---|
file | { name, size, type, uri } |
channel | current channel instance |
doImageUploadRequest
Override of the image upload request when a user selects an image from the image picker.
The function must return a Promise
that is resolved to an object with the key file
that is the URL of the uploaded image.
This can be used to store image attachments in your own custom CDN.
Type |
---|
function |
Parameter | Description |
---|---|
image | { name, uri } |
channel | current channel instance |
editing
True if the user is editing some message within MessageInput
component.
Type |
---|
boolean |
editMessage
Override of the Edit MessageMessageAction
shown when a user long presses a message.
The editMessage
function receives as a parameter the relevant message and must return a MessageAction
.
Please refer to the guide on customizing message actions for details.
Type |
---|
function | null |
Parameter | Description |
---|---|
message | message the action is called on |
hasCommands
Enable commands on the MessageInput
component.
Type | Default |
---|---|
boolean | true |
hasFilePicker
Enable the file picker on the MessageInput
component.
Type | Default |
---|---|
boolean | true |
hasImagePicker
Enable the image picker on the MessageInput
component.
Type | Default |
---|---|
boolean | true |
initialValue
The initial value for the MessageInput
component.
Type |
---|
string |
maxMessageLength
Maximum length of the message text. The default value is supplied by the channel config.
Type |
---|
number |
maxNumberOfFiles
Maximum number of files (documents & images), that can be attached per message.
Type | Default |
---|---|
number | 10 |
mentionAllAppUsersEnabled
Allows any of the app users to be mentioned in a message, as part of autocomplete feature within input box. By default only members of channel can be mentioned while composing a message.
Type | Default |
---|---|
boolean | false |
mentionAllAppUsersQuery
Query to be used for searching users as part of autocomplete mention feature within input box. Please check the Querying Users docs for more details on filters/sort/options.
mentionAllAppUsersQuery={{
filters: {
id: {
$in: ['vishal', 'lucas']
}
},
sort: {},
options: {}
}}
Type |
---|
object |
numberOfLines
Maximum number of lines that underlying TextInput
component within MessageInput
should expand to.
Type | Default |
---|---|
number | 5 |
onChangeText
Callback that is called when the text input’s text changes.
Type |
---|
function |
Parameter | Description |
---|---|
text | changed text |
quotedMessage
sendImageAsync
sendMessage
Sends a composed message within MessageInput
component to channel. This function is attached to onPress
handler of SendButton
. The message optimistically gets added to message list UI first, before actually making API call to server.
During this intermediate stage, MessageStatus component will display an indicator for “pending” state.
Type |
---|
function |
uploadsEnabled
Allow attachments on messages, including images. The default value is supplied by the channel config.
Type |
---|
boolean |
appendText
Appends text to existing text entered by user in MessageInput
component.
Type |
---|
(text) => void |
closeAttachmentPicker
Dismiss the attachment picker, if its already open.
Type |
---|
function |
fileUploads
List of file
type attachments currently attached to message, which is being composed in MessageInput
component.
[
{
file: {
name: 'test.pdf';
size: 2000;
type: 'application/pdf';
uri: 'file-uri';
};
id: 'asdas232bk3jb42k3';
state: 'uploaded'; // or 'finished'
url: 'https://cdn.getstream.io/kajsnkj2n3j4';
}
]
Type |
---|
array |
giphyActive
True if a user selects the giphy
command from commands list (which is shown when you type a /
in the input box).
This value is set back to false
when the user sends the message for searching Giphy.
Type |
---|
boolean |
imageUploads
List of image
type attachments currently attached to message, which is being composed in MessageInput
component.
[
{
file: { name: "fallback-name.jpeg" },
id: "2j3n4k23nj4k23n4k3",
state: "finished", // or 'uploading'
url: "https://cdn.getstream.io/kajsnkj2n3j4", // If the state is `uploading`, then this will be a local uri of image.
},
];
Type |
---|
array |
inputBoxRef
Ref for TextInput
component within MessageInput
Type |
---|
ref |
isValidMessage
False if text within input box is empty and no images or files have been attached to a message yet. You can use this value to add enabled/disabled UI state on SendMessage button.
Type |
---|
boolean |
mentionedUsers
Ids of users which are mentioned (for example Hey @Vishal Narkhede, how are you
) in a message, which is being composed in MessageInput component.
["vishal-user-id", "jaap-user-id"];
Type |
---|
array |
numberOfUploads
Number of image + files attached to message which is being composed in MessageInput
component.
Type |
---|
number |
openAttachmentPicker
Opens the attachment picker bottom sheet, if its not open.
Type |
---|
function |
openCommandsPicker
Opens the commands picker box. By default, this function is attached to onPress
handler for CommandsButton
.
Type |
---|
function |
openFilePicker
Opens the file picker. By default, this function is attached to onPress
handler for FileAttachmentIcon
.
Type |
---|
function |
openMentionsPicker
Opens the user mentions autocomplete popup. When user types @
in input box, internally this function gets called.
Type |
---|
function |
removeFile
Removes attached file in message, which is being composed in MessageInput
component. By default, this function is attached to onPress
handler for close button in FileUploadPreview.
It takes index of file (to be removed) in fileUploads
array as parameter.
Type |
---|
(index) => void |
removeImage
Removes attached image in message, which is being composed in MessageInput
component. By default, this function is attached to onPress
handler for close button in ImageUploadPreview.
It takes index of file (to be removed) in imageUploads
array as parameter.
Type |
---|
(index) => void |
resetInput
Resets the entire MessageInput
component to empty state by clearing the text, attachments etc.
Type |
---|
function |
selectedPicker
Value is images
(string), when image attachment picker is open. Value will be undefined
if file picker is active or file picker is open.
Type |
---|
’images’ | undefined |
sendThreadMessageInChannel
This value is only applicable to Thread
component. When value sendThreadMessageInChannel
is true, message gets sent from MessageInput
component with property show_in_channel: true
.
This value is attached to the checkbox (with label “Also Send To Channel”) in MessageInput
component within Thread
component.
Type |
---|
boolean |
setFileUploads
Setter function for fileUploads
.
Type |
---|
(files) => void |
setGiphyActive
Setter function for giphyActive
Type |
---|
(isActive) => void |
setImageUploads
Setter function for imageUploads
.
Type |
---|
(images) => void |
setInputBoxRef
Setter function for inputBoxRef
Type |
---|
(ref) => void |
setMentionedUsers
Setter function for mentionedUsers
Type |
---|
(mentionedUsers) => void |
setNumberOfUploads
Setter function for numberOfUploads
Type |
---|
(numberOfUploads) => void |
setSendThreadMessageInChannel
Setter function for setSendThreadMessageInChannel
.
Type |
---|
(sendThreadMessageInChannel) => void |
setShowMoreOptions
Setter function for showMoreOptions
.
Type |
---|
(showMoreOptions) => void |
setText
Setter function for text
.
Type |
---|
(text) => void |
showMoreOptions
Represents the expanded or collapsed state for attach and commands button, next to input box.
Type |
---|
boolean |
text
Text message entered by user in underlying TextInput
within MessageInput
component.
This value is attached to TextInput
’s value prop
Type |
---|
string |
thread
A message object that when set indicates a thread is open.
When used with the Thread
component this will display the thread.
When used with the standard MessageList
component this will prevent any singleton components in the OverlayProvider
form getting out of sync.
thread
should be set on all Channel
components when a thread is open.
Type |
---|
object |
toggleAttachmentPicker
Function to toggle attachment picker. By default, this function is attached to onPress
handler for AttachButton
.
Type |
---|
function |
triggerSettings
Trigger settings for the auto complete input.
Type | Default |
---|---|
object | TriggerSettings |
updateMessage
This function is a counterpart of sendMessage
, for the case of editing a message. This function is attached to SendButton
when some existing message is being updated.
Similar to sendMessage
function, the message will be updated in message list UI first, before making API call to update the message.
Type |
---|
function |
uploadFile
This function is used internally by uploadNewFile
function, and is used for purpose retry mechanism.
Type |
---|
function |
uploadImage
This function is used internally by uploadNewImage
function, and is used for purpose retry mechanism.
Type |
---|
function |
uploadNewFile
Function to upload an attached file in MessageInput
. This function adds a file to fileUploads
array and calls channel.sendFile
.
This function takes a file from react-native-document-picker as parameter.
Type |
---|
(file) => Promise |
uploadNewImage
Function to upload an attached image in MessageInput
. This function takes an image from imageUploads
array as a parameter.
Type |
---|
(image) => Promise |
AttachButton
Component to render the attach button next to input box.
Type | Default |
---|---|
component | AttachButton |
CommandsButton
Component to render button next to input box, which when pressed opens commands list.
Type | Default |
---|---|
component | CommandsButton |
FileUploadPreview
Component to render preview of attached file, within enclosed MessageInput
component.
Type | Default |
---|---|
component | FileUploadPreview |
ImageUploadPreview
Component to render preview of attached images, within enclosed MessageInput component
Type | Default |
---|---|
component | ImageUploadPreview |
Input
Component to render UI part of enclosed MessageInput component. Please read section in guides about Customizing Message Input.
Type |
---|
component |
InputButtons
Component to render action buttons (CommandsButton and AttachButton) on left side of input box, within enclosed MessageInput
component.
Type | Default |
---|---|
component | InputButtons |
MoreOptionsButton
Component to render a button within enclosed MessageInput, which when pressed shows more options such as AttachButton, CommandsButton.
Type | Default |
---|---|
component | MoreOptionsButton |
SendButton
Component to render a send message button, within enclosed MessageInput component.
Type | Default |
---|---|
component | SendButton |
ShowThreadMessageInChannelButton
Component to render a checkbox within enclosed Thread component, which when checked sets a show_in_channel
property to true on a message.
Type | Default |
---|---|
component | ShowThreadMessageInChannelButton |
UploadProgressIndicator
Component to render progress indicator on ImageUploadPreview
and FileUploadPreview
components, as overlay.
Type | Default |
---|---|
component | UploadProgressIndicator |
- Basic Usage
- Value
- additionalTextInputProps
- autoCompleteSuggestionsLimit
- autoCompleteTriggerSettings
- clearEditingState
- clearQuotedMessageState
- compressImageQuality
- doDocUploadRequest
- doImageUploadRequest
- editing
- editMessage
- hasCommands
- hasFilePicker
- hasImagePicker
- initialValue
- maxMessageLength
- maxNumberOfFiles
- mentionAllAppUsersEnabled
- mentionAllAppUsersQuery
- numberOfLines
- onChangeText
- quotedMessage
- sendImageAsync
- sendMessage
- uploadsEnabled
- appendText
- closeAttachmentPicker
- fileUploads
- giphyActive
- imageUploads
- inputBoxRef
- isValidMessage
- mentionedUsers
- numberOfUploads
- openAttachmentPicker
- openCommandsPicker
- openFilePicker
- openMentionsPicker
- removeFile
- removeImage
- resetInput
- selectedPicker
- sendThreadMessageInChannel
- setFileUploads
- setGiphyActive
- setImageUploads
- setInputBoxRef
- setMentionedUsers
- setNumberOfUploads
- setSendThreadMessageInChannel
- setShowMoreOptions
- setText
- showMoreOptions
- text
- thread
- toggleAttachmentPicker
- triggerSettings
- updateMessage
- uploadFile
- uploadImage
- uploadNewFile
- uploadNewImage
- AttachButton
- CommandsButton
- FileUploadPreview
- ImageUploadPreview
- Input
- InputButtons
- MoreOptionsButton
- SendButton
- ShowThreadMessageInChannelButton
- UploadProgressIndicator