Change input states
Update user typing state focus within a conversation using the OpenIM React Native SDK.
Update the current user's typing activity in a conversation. Pass focus: true when the user starts typing into the input field, and false when sending a message, losing input focus, or closing the conversation screen.
await OpenIMSDK.changeInputStates({
conversationID,
focus: true,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Target conversation ID. |
focus | boolean | Yes | true indicates active typing; false indicates typing has stopped. |
To prevent excessive network traffic, debounce repeated keystrokes rather than reporting on every individual character change.
Return value
A resolved Promise confirms that the typing status update was submitted to the server.
Typing state transitions trigger the OnInputStatusChanged event on the recipient client. Reconcile the UI by matching conversationID and using userID to show or hide the "User is typing..." indicator.
interface InputStatusChangedPayload {
conversationID: string;
userID: string;
platformIDs: number[];
}
const handleInputStatusChanged = (inputStatus: InputStatusChangedPayload) => {
// Update typing indicator for the matching conversationID and userID
};
// Register listener
OpenIMSDK.on(OpenIMEvent.OnInputStatusChanged, handleInputStatusChanged);
// Unregister listener on cleanup
OpenIMSDK.off(OpenIMEvent.OnInputStatusChanged, handleInputStatusChanged);Always unregister listeners using identical function references when unmounting components or signing out.
Was this page helpful?