Message Input for PubNub Chat Components for React Native
USED BY THE OLD IA, PLEASE DISREGARD
Allows users to compose messages using text and emojis and automatically publish them on PubNub channels upon sending.
Component
Check the source code of the Message Input component and its preview on the right.
USED BY THE OLD IA, PLEASE DISREGARD
Try it out
Test the component as Sue Flores (default user):
-
Choose one of the Preview tabs and click
Tap to Playfor the Android and iOS emulators to have the sample component up and running. -
Type in a message in the input field and send it.
-
Modify the source code of the component to your liking and see the changes live on the preview. For example, you can change the
themetodarkor uncomment one of the configurable parameters to see how you can modify the component's default behavior.
Parameters
You can configure the component using these parameters:
placeholder?#- Option to set a placeholder message to display in the text window.
- Default value
"Send message"
draftMessage?#- Option to set a draft message to display in the text window.
- Default value
- n/a
senderInfo?#- Option to attach sender data directly to each message. Enable it for high-throughput environments. This is an alternative to providing a full list of users directly into the Chat provider.
- Default value
false
typingIndicator?#- Option to enable/disable firing the typing events when a user is typing a message.
- Default value
false
fileUpload?#- Option to enable/disable the internal file upload capability. It lets you send both text and file in one message.
- Default value
- n/a
fileModalRenderer?#- Option to override the default modal allowing to upload images and files.
- Default value
- n/a
filePreviewRenderer?#- Callback to render the preview of the attached file.
- Default value
- n/a
disabled?#- Option to disable the input from composing and sending messages.
- Default value
false
actionsAfterInput?#- Option to move action buttons (eg. file upload icon) to the right of the text input.
- Default value
false
onChange?#- Callback to handle an event when the text value changes.
- Default value
- n/a
onBeforeSend?#- Callback to modify message content before sending it. This only works for text messages, not files.
- Default value
- n/a
onSend?#- Callback for extra actions after sending a message.
- Default value
- n/a
extraActionsRenderer?#- Option to provide an extra actions renderer to add custom action buttons to the input.
- Default value
- n/a
style?#- Option to provide a custom StyleSheet for the component. It will be merged with the default styles.
- Default value
- n/a
sendMessageOnSubmitEditing?#- If you set the
sendMessageOnSubmitEditingparameter totrue, a message is sent whenever users hit the Return or Enter key on a keyboard.- Default value
- n/a
- Selected
TextInputprops# - Chat Components for React Native let you configure all the default
TextInputprops from React Native except fortestID,autoComplete,multiline,onChangeText,placeholder,style,placeholderTextColor,editable, andvalue. For example, you can set a limit to the maximum number of characters that can be entered in the input field using themaxLengthparameter, like<MessageInput maxLength={120} />.- Default value
- n/a
Offline message behavior
When you send a message and the network connection is lost, the message will still be visible in the message input upon tapping the Send button, and other chat users won’t see it on the message list.
The message won't reach the server (the publish method from the JavaScript SDK will fail), returning the PubNub call failed, check status for details error.
You can handle these incoming errors using the onError property of the Chat Provider component and pass it to a custom callback function.
1import PubNub from "pubnub";
2import { PubNubProvider } from "pubnub-react";
3import { Chat, MessageList, MessageInput } from "@pubnub/react-native-chat-components";
4
5const pubnub = new PubNub({
6publishKey: "demo",
7subscribeKey: "demo",
8userId: "test-user"
9});
10
11export default function App() {
12function handleError(e) {
13 console.log("Error handler: ", e);
14}
15
show all 24 lines