1.0.6 • Published 2 years ago

rn-custom-chat v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

rn-custom-chat

Easy custom messages with rn-custom-chat

Installation

Install rn-custom-chat with npm

  npm install rn-custom-chat

#or Install rn-custom-chat with yarn

  yarn add rn-custom-chat

More setting

 npm install / yarn add react-native-tab-view
 npm install / yarn add react-native-vector-icons

Screenshots

Usage/Examples

import React, { useEffect, useRef, useState } from "react";
import { View, Image } from "react-native";

import ChatBox from "rn-custom-chat";

const App = () => {
  const user = {
    id: "u1",
    name: "Vadim",
    imageUri:
      "https://notjustdev-dummy.s3.us-east-2.amazonaws.com/avatars/vadim.jpg",
  };
  const customer = {
    id: "u2",
    name: "Elon Musk",
    imageUri:
      "https://static-images.vnncdn.net/files/publish/ty-phu-elon-musk-vua-chi-44-ty-usd-de-mua-lai-twitter-9ff465ee3a124118b8fc9b8e8c9bcb4a.jpg",
  };
  const [messages, setMessages] = useState([
    {
      id: "m1",
      type: "text",
      content: "How are you, Elon!",
      createdAt: "2020-10-02T12:48:00.000Z",
      user: {
        id: "u1",
        name: "Vadim",
      },
    },
    {
      id: "m2",
      type: "text",
      content: "I am good, good",
      createdAt: "2020-10-03T14:49:00.000Z",
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m3",
      type: "text",
      content: "What about you?",
      createdAt: "2020-10-04T14:49:40.000Z",
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m4",
      type: "text",
      content: "Good as well, preparing for the stream now.",
      createdAt: "2020-10-07T14:47:00.000Z",
      user: {
        id: "u1",
        name: "Vadim",
      },
    },
    {
      id: "m5",
      type: "text",
      content: "How is SpaceX doing?",
      createdAt: "2020-10-07T14:48:00.000Z",
      user: {
        id: "u1",
        name: "Vadim",
      },
    },
    {
      id: "m6",
      type: "text",
      content: "going to the Moooooon",
      createdAt: "2020-10-07T14:49:00.000Z",
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m6",
      type: "text",
      content: "going to the Moooooon",
      createdAt: "2020-10-07T14:49:00.000Z",
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m6",
      type: "text",
      content: "going to the Moooooon",
      createdAt: "2020-10-07T14:49:00.000Z",
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m7",
      type: "text",
      content: "btw, SpaceX is interested in buying notJust.dev!",
      createdAt: 1656497877769,
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m7",
      type: "text",
      content: "btw, SpaceX is interested in buying notJust.dev!",
      createdAt: 1656497877769,
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
    {
      id: "m7",
      type: "image",
      content: "btw, SpaceX is interested in buying notJust.dev!",
      createdAt: 1656497877769,
      user: {
        id: "u2",
        name: "Elon Musk",
      },
    },
  ]);

  const onPressSend = (value) => {
    let item = {
      id: "m1",
      type: "text",
      content: value,
      createdAt: new Date().getTime(),
      user: {
        ...user,
      },
    };
    let data = [];
    data.push(...messages, item);
    // console.log(JSON.stringify(data));
    setMessages(data);
  };

  const backgroundContainer = () => {
    return (
      <Image
        style={{ width: "100%", height: "100%" }}
        source={{
          uri: "https://1.bp.blogspot.com/-Re1cd2wUahw/Xp3BVxbXN0I/AAAAAAAAh2w/jGx30lNaoIUkmtkj4GQR8VY0iE1qeLlBACLcBGAsYHQ/s1600/Hinh-nen-hoa-cuc-dep%2B%25282%2529.jpg",
        }}
      />
    );
  };

  return (
    <ChatBox
      messages={messages}
      user={user}
      customer={customer}
      styleUser={{ color: "red", backgroundColor: "blue" }}
      styleCustomer={{ color: "blue", backgroundColor: "black" }}
      styleTextDate={{ color: "white", fontSize: 16 }}
      backgroundContainer={() => backgroundContainer()}
      onPressSend={onPressSend}
      onPressCamera={() => {}}
      onLongPressItem={() => {}}
      txtSendEmoji={"👍"}
      colorBottomInput={"white"}
      colorInput={"#e0e0d1"}
      iconColor={"blue"}
      onPressLibrary={() => {}}
    />
  );
};

export default App;

Properties

ParameterTypeDescription
messages @requiredArrayMessages to display
user @requiredObjectInfomation user { id: Any, name: string,imageUri: string }
customer @requiredObjectcustomer user { id: Any, name: string,imageUri: string }
styleUserObjectUser display messages {color:text color,backgroundColor:text crossword color}
styleTextDateObjectCustom style for textDate <Text>
backgroundContainerFunctionPicture for the message
onPressSend @requiredFunctionCallback when the Action button is pressed (The function to return the content of the text message)
onPressCameraFunctionCallback when the Action button is pressed (Note:no camera just empty function) if onPressCamera not available
onPressLibraryFunctionCallback when the Action button is pressed (Note:no library just empty function) if onPressLibrary not available
onLongPressItem @requiredFunctionCall on Hold and return message information
txtSendEmoji @requiredstringSend text Emoji { avoid text } 👍
colorBottomInputstringColor for bottom chat
colorInputstringColor for input chat
iconColor @requiredstringColor icon camera and library

🔗 Links

github

🚀 About Me

I'm a Mobile developer...

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago