Skip to main content

Message Input Box Screen

Overview

The MessageInput component is designed to facilitate message sending within our chat app. It internally utilizes the LMChatTextInput component, offering full customization capabilities. Additionally, it supports features like tagging and media, enhancing user interaction by enabling users to mention others or share multimedia content within the chat.

LMFeedMediaPreviewScreen

UI Components

Callbacks

  • joinSecretChatroomProp: Callback method to handle joining a secret chatroom.
  • showJoinAlertProp: Callback method to display an alert for joining a chatroom.
  • showRejectAlertProp: Callback method to display an alert for rejecting a chatroom invitation.

Customisations

PropertyTypeDescription
placeHolderTextColorstringThe color of the placeholder text
selectionColorstringThe color used for text selection
partsTextStylePartstextstyleCustom style for the text parts
plainTextStylePlaintextstyleCustom style for plain text
placeHolderTextstringThe text to display as placeholder
inputTextStyleInputtextstyleCustom style for the input text
sendIconStylesSendiconstylesCustom style for the send icon
attachmentIconStylesAttachmenticonstylesCustom style for the attachment icon
micIconStylesMiciconstylesCustom style for the mic icon
cameraIconStylesCameraiconstylesCustom style for the camera icon
galleryIconStylesGalleryiconstylesCustom style for the gallery icon
documentIconStylesDocumenticonstylesCustom style for the document icon
pollIconStylesPolliconstylesCustom style for the poll icon
messageInputMarginBottomnumberThe margin at the bottom of the message input

PartsTextstyle

PropertyTypeDescription
colorstringThe color of the text

PlainTextstyle

PropertyTypeDescription
colorstringThe color of the text

InputTextstyle

PropertyTypeDescription
flexgrownumberDefines the grow factor for the input text
fontsizestringThe size of the input text font
fontfamilystringThe font family for the input text
maxheightnumberThe maximum height of the input text
paddingnumberPadding inside the input text
marginbottomnumberThe margin at the bottom of the input text
overflowstringHow to handle overflow for the input text

SendIconstyles

PropertyTypeDescription
widthnumberThe width of the send icon
heightnumberThe height of the send icon
resizemodestringDefines how to resize the send icon
marginleftnumberThe left margin of the send icon
tintcolorstringThe color tint for the send icon

AttachmentIconstyles

PropertyTypeDescription
widthnumberThe width of the attachment icon
heightnumberThe height of the attachment icon
resizemodestringDefines how to resize the attachment icon

MicIconstyles

PropertyTypeDescription
widthnumberThe width of the mic icon
heightnumberThe height of the mic icon
resizemodestringDefines how to resize the mic icon
tintcolorstringThe color tint for the mic icon

CameraIconstyles

PropertyTypeDescription
widthnumberThe width of the camera icon
heightnumberThe height of the camera icon
resizemodestringDefines how to resize the camera icon

GalleryIconstyles

PropertyTypeDescription
widthnumberThe width of the gallery icon
heightnumberThe height of the gallery icon
resizemodestringDefines how to resize the gallery icon

DocumentIconstyles

PropertyTypeDescription
widthnumberThe width of the document icon
heightnumberThe height of the document icon
resizemodestringDefines how to resize the document icon

PollIconstyles

PropertyTypeDescription
widthnumberThe width of the poll icon
heightnumberThe height of the poll icon
resizemodestringDefines how to resize the poll icon

Props

PropertyTypeDescriptionRequired
joinSecretChatroomPropFunctionFunction to handle joining a secret chatroom.✔️
showJoinAlertPropFunctionFunction to display an alert for joining a chatroom.✔️
showRejectAlertPropFunctionFunction to display an alert for rejecting a chatroom invitation.✔️
hintMessagesHintMessagesObject containing various hint messages.

HintMessages

PropertyTypeDescription
messageForRightsDisabledstringMessage shown when rights are disabled.
messageForMemberCanMessagestringMessage shown to members who can send messages.
messageForAnnouncementRoomstringMessage shown for announcement rooms.
respondingDisabledstringMessage shown when responding is disabled.

Usage Example

info

The MessageInput screen can be used by wrapping it inside the ChatRoom screen, and the callbacks are passed as props to MessageInput.

Step 1: Create Custom Screen and Wrapper

  • In your app, create a ChatroomScreenWrapper file which will wrap the ChatroomScreen within the Chat so that the callbacks becomes accessible inside of the ChatroomScreen.
  • Create inputBoxStyles for customisation and call the setInputBoxStyle to set the customisation.
import {
STYLES,
MessageInput,
useChatroomContext,
ChatRoom,
} from "@likeminds.community/chat-rn-core";

const ChatroomScreen = () => {
const { joinSecretChatroom, showJoinAlert, showRejectAlert } =
useChatroomContext();

const customJoinSecretChatroom = async () => {
console.log("before custom join secret chatroom");
const response = await joinSecretChatroom();
console.log("response after custom join secret chatroom", response);
};

const customShowJoinAlert = async () => {
console.log("before custom show join alert");
await showJoinAlert();
console.log("after custom show join alert");
};
const customShowRejectAlert = async () => {
console.log("before custom show reject alert");
await showRejectAlert();
console.log("after custom show reject alert");
};

const inputBoxStyles = {
placeholderTextColor: "#aaa",
selectionColor: "#3CA874",
partsTextStyle: {
color: "#3CA874",
},
sendIconStyles: {
tintColor: "black",
},
micIconStyles: {
tintColor: "black",
},
};

// custom styling for input box
if (inputBoxStyles) {
STYLES.setInputBoxStyle(inputBoxStyles);
}

return (
<ChatRoom>
<MessageInput
joinSecretChatroomProp={customJoinSecretChatroom}
showJoinAlertProp={customShowJoinAlert}
showRejectAlertProp={customShowRejectAlert}
/>
</ChatRoom>
);
};

export default ChatroomScreen;

Step 2: Add the Custom Screen in App.tsx

  • In your App.tsx, create a Stack.Navigator in the NavigationContainer wrapped by LMOverlayProvider.
  • Add ChatroomScreenWrapper as a Stack screen in your NavigationContainer.
App.tsx
import { CHATROOM, LMOverlayProvider } from "@likeminds.community/feed-rn-core";
import { CreatePostScreenWrapper } from "<<path_to_CreatePostScreenWrapper.tsx>>";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";

export const App = () => {
const Stack = createNativeStackNavigator();
return (
<LMOverlayProvider
myClient={myClient} // pass in the LMChatClient created
apiKey={apiKey} // pass in the API Key generated
userName={userName} // pass in the logged-in user's name
userUniqueId={userUniqueID} // pass in the logged-in user's uuid
>
<NavigationContainer ref={navigationRef} independent={true}>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen
name={CHATROOM}
component={ChatroomScreenWrapper}
initialParams={{
chatroomID: chatroomId,
announcementRoomId: announcementRoomId,
}}
/>
</Stack.Navigator>
</NavigationContainer>
</LMOverlayProvider>
);
};