1.0.0 • Published 12 months ago

expo-easy-chat v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

easy-chat

A chat UI library for Expo projects built with React Native and TypeScript.

Installation

npm install easy-chat

Usage

import { ChatWindow } from "easy-chat";
import React, { useState } from "react";
import { View, StyleSheet } from "react-native";

const App = () => {
  const [messages, setMessages] = useState<any[]>([]);

  const handleSend = (newMessages: any[]) => {
    setMessages((previousMessages) => newMessages.concat(previousMessages));
  };

  return (
    <View style={styles.container}>
      <ChatWindow
        messages={messages}
        onSend={handleSend}
        user={{ _id: 1 }}
        chatTitle="Chat"
      />
    </View>
  );
};

Components

Components and Props

ComponentPropDescription
ChatWindowmessagesArray of messages.
ChatWindowonSendFunction to handle sending messages.
ChatWindowuserCurrent user object.
ChatBubblemessageMessage object.
ChatBubbleisCurrentUserBoolean indicating if the message is from the current user.
ChatInputonSendFunction to handle sending a message.

All Possible Props

PropTypeDescription
messagesMessage[]Array of messages.
onSend(messages: Message[]) => voidFunction to handle sending messages.
userChatUserCurrent user object.
keyboardShouldPersistTaps"always" \| "never" \| "handled"Determines if the keyboard should persist taps. Default is "handled".
minInputToolbarHeightnumberMinimum height for the input toolbar. Default is 44.
listViewPropsFlatListProps<Message>Additional props to pass to the FlatList component.
renderBubble(props: { message: Message; isCurrentUser: boolean }) => JSX.ElementCustom render function for the message bubble.
renderInputToolbar(props: { onSend: (text: string) => void }) => JSX.ElementCustom render function for the input toolbar.
chatTitlestringTitle of the chat window.
showTimestampbooleanWhether to show the timestamp in the message bubble. Default is true.

Hooks

useChat() initialMessages: Array of initial messages. Returns messages and onSend function. vbnet Copy code

6. LICENSE

Include the license for your package, such as the MIT License:

MIT License

Copyright (c) 2024 Hamza Saleem

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

[...]
1.0.0

12 months ago