Just wanted to share.
I was finding it difficult to customize the default UI for this package. The official documentation wasn't that helpful.
Luckily, I was able to solve it.
See answer
Make your imports
import {GiftedChat, InputToolbar,...} from 'react-native-gifted-chat'
Note: InputToolbar
must be imported since we want to customize it
Create a function called customInputToolbar
that will return the custom UI
const customtInputToolbar = props => {
return (
<InputToolbar
{...props}
containerStyle={{
backgroundColor: "white",
borderTopColor: "#E8E8E8",
borderTopWidth: 1,
padding: 8
}}
/>
);
};
Note: props
must be an argument.
Tip: Since all props for the InputToolbar
were not listed in the official github page (https://github.com/FaridSafi/react-native-gifted-chat), you can Cmd + Left Click
on the InputToolbar
tag while in your editor. This will navigate you to the source file within which all props are listed. Be careful not to edit anything !!
Include the renderInputToolbar
as a prop in the GiftedChat
component
<GiftedChat
messages={chatMessages.messages}
onSend={messages => sendMessage(messages)}
renderInputToolbar={props => customtInputToolbar(props)}
...
/>
Note: Remember to pass props
as an argument to the function. Without this, the UI will not display
You're done !!
Include SystemMessage
in your import
Create a function called customSystemMessage
const customSystemMessage = props => {
return (
<View style={styles.ChatMessageSytemMessageContainer}>
<Icon name="lock" color="#9d9d9d" size={16} />
<Text style={styles.ChatMessageSystemMessageText}>
Your chat is secured. Remember to be cautious about what you share
with others.
</Text>
</View>
);
};
Include renderSystemMessage
as a prop in your GiftedChat
component
You're done
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With