0.5.0 • Published 4 days ago

react-native-customizable-chat v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

react-native-customizable-chat

Lightweight and easy chat view for your react native chat apps

the package is still in development, it's possible that breaking changes appear often

Features

  • 🖌 FULLY customizable. Each component is customizable and replaceable
  • ⚡ PERFORMANCES ⚡️ well optimized, only new messages will render
  • 🔗 Link in messages can be opened
  • 👆 Clicked messages or long pressed messages events that return the selected message
  • 📳 Automatic scale for images in bubble
  • 😃 User avatar

Installation

npm install react-native-customizable-chat

⚠️FOR NON EXPO USER⚠️ ⚠️If you want to support gif and webp for image preview then check this link ⚠️

Basic usage

import CustomizableChat from 'react-native-customizable-chat'
import { CustomizableChatMessage } from 'react-native-customizable-chat/lib/typescript/src/types/Message';

export default function App() {
  
  const messages : Array<CustomizableChatMessage> = [
    {id: 0, content: "Hey!", isUser: false, date: new Date()},
    {id: 1, content: "Hey how are you?", isUser: true, date: new Date()},
    {id: 2, content: "Fine and you?", isUser: false, date: new Date()},
    {id: 3, content: "I'm having great time!", isUser: false, date: new Date(), uri: "IMAGE_URL"}
  ]

  return (
      <CustomizableChat 
        messages={messages}
        onSend={(e) => console.log(e)}
        debug={false}
      />
  );
}

This will give you :

Advanced usage

  const bgColor = '#17120E'
  const textColor = "#FFE0C2"
  const otherUserBubbleColor = '#331E0B'
  const userBubbleColor = '#562800'
  const borderColor = '#66350C'
  const sendButtonColor = '#F76B15'

  return (
      <CustomizableChat 
        messages={messages}
        onSend={(e) => addMessage(e)}
        noDivider
        keepKeyboardOnSend
        hideBubbleDate
        containerStyle={{backgroundColor: bgColor}}
        backgroundColor={bgColor}
        userBubbleColor={userBubbleColor}
        inputStyle={{color: textColor, 
                    borderRadius: 20, 
                    borderWidth: 1.5,
                    borderColor: borderColor, 
                    padding: 10 }}
        bottomContainerStyle={{marginTop: 10}}
        otherUserBubbleColor={otherUserBubbleColor}
        bubbleTextStyle={{color: textColor}}
        inputPlaceholderColor={textColor}
        customSendButton={<Icon name='send' 
                                size={15} 
                                type='material-community' 
                                color={sendButtonColor} 
                                reverse
                          />}
        debug={false}
      />
  )

Messages type

interface CustomizableChatMessage 
{
    id: number,//It's recommended to implement it correctly. Ex: if you want to delete the message on long press. You can easily remove it thanks to his id returned in the event
    content: string,
    date?: Date,
    isUser: boolean,//If true the message will be aligned to the right and considered as user message
    uri?: string,//uri of your image, video, gif, file... (the library will auto detect the type of the uri and show the correct badge associated to his type. For example if it's a video it will show the badge video, gif => gif badge, file => specific view)
    seen?: boolean//the message is seen or not
    userAvatar?: string//uri of user avatar
}

File type

if a uri is specified, it will get the following metadata (you can retrieve it through filePreview prop)

interface BubbleFileMetada
{
    size: number//in MB
    lastModified: string | Date
    contentType: string
}

Required props

NameTypeDescription
messagesArrayYour array of message formatted with the CustomizableChatMessage type
onSendfunctionTriggered when user clicks on send, returns a CustomizableChatMessage

Customization props

NameTypeDescription
onMsgPressfunctionIf user presses a bubble this function is triggered. Returns a CustomizableChatMessage
onLongMsgPressfunctionIf user long presses a bubble this function is triggered. Returns a CustomizableChatMessage
keepKeyboardOnSendbooleanIf true then the keyboard will not dimiss when the user presses sends
disableBubblePressOpacitybooleanIf true the opacity animation when a user touches a bubble is disabled
backgroundColorstringColor of the chat background
containerStyleViewStyleCustomize the style of the whole chat container
bottomContainerStyleViewStyleCustomize the container of the input and send button
hideAvatarbooleanDefault : false, if false the avatar of the bubble won't display
hideSendButtonbooleanIf true the send button won't display
alwaysShowSendbooleanBy default the send button will display only if input is not empty. Setting this to true will always display the send button
sendButtonContainerStyleViewStyleCustomize the container of the send button
dateFormatstringdayjs format of the date, for example "DD/MM/YYYY"
hideBubbleDatebooleanIf true, the date of messages won't display
dateTextStyleTextStyleText style of the date of user bubble
otherUserDateTextStyleTextStyleText style of the date of other user bubble
bubbleTextStyleTextStyleCustomize text in user chat bubble
otherUserBubbleTextStyleTextStyleCustomize text in other user chat bubble
imageStyleImageStyleCustomize the style of an image in bubble
customSendButtonReactNodeReplace the default button by your own button. The onSend event is still triggered
sendButtonPropsButtonPropsAdd props of the default send button
inputTopElementReactNodeAdd any fragment between the chat and the input
hideTopElementbooleanIf true your fragment between the chat and the input won't display
rightInputElementReactNodeAdd any fragment on the right of the input
leftInputElementReactNodeAdd any fragment on the left of the input
hideRightInputElementbooleanDefault: false, If true display your fragment on the right of the input
hideLeftInputElementbooleanDefault: false, If true display your fragment on the left of the input
otherUserBubbleColorstringChange the background color of the other user's bubble
userBubbleColorstringChange the background color of the user's bubble
bubbleContainerStyleViewStyleCustomize chat bubble container
sentMarkReactNodeCustom node to display when the message is not seen
seenMarkReactNodeCustom node to display when the message is seen
inputMaxLengthnumberMax length of the input
inputStyleTextStyleCustomize the style of the input
inputPlaceholderColorstringColor of the placeholder of the input
inputPlaceholderValuestringValue of the placeholder of the input
customVideoBadgeReactNodeAdd your own fragment to the video badge (video badge appears when the CustomizableChatMessage isVideo = true)
filePreviewfunction(msg: CustomizableChatMessage) => ReactNodeCustomize the node of file preview
defaultInputValuestringdefault value of the input, default : ''
debugbooleandefault value : true. If false no log and warning will be thrown by the package

Supports me

You want to support me ? Buy me a coffee

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


0.5.0

4 days ago

0.4.2

27 days ago

0.4.1

1 month ago

0.4.0

1 month ago

0.3.9

2 months ago

0.3.62

2 months ago

0.3.8

2 months ago

0.3.7

2 months ago

0.3.41

2 months ago

0.3.61

2 months ago

0.3.6

2 months ago

0.3.5

2 months ago

0.3.4

4 months ago

0.3.3

4 months ago

0.3.22

4 months ago

0.3.21

4 months ago

0.3.2

4 months ago

0.3.0

5 months ago

0.2.1

5 months ago

0.1.2

5 months ago

0.2.0

5 months ago

0.3.1

5 months ago

0.1.3

5 months ago

0.3.11

4 months ago

0.1.1

5 months ago

0.1.0

5 months ago