A simple chat interface built using React Native, with real-time messaging via Socket.IO, image sharing, and more.
- Features
- Prerequisites
- Installation
- Usage
- Props
- Passing Data
- Folder Structure
- Publishing Your Own Package
- Real-time messaging with Socket.IO
- Text and image messages
- Clean, user-friendly UI
- Support for custom styles and easy navigation
Before you begin, make sure you have the following installed:
- Node.js (>= 14.0.0)
- React Native CLI
- Xcode (for iOS development)
- Android Studio (for Android development)
-
Install the package using npm:
npm install react-native-chat-ui
Or using yarn:
yarn add react-native-chat-ui
-
Install peer dependencies:
npm install socket.io-client react-native-image-picker
-
Link dependencies (if required):
npx react-native link
//Note:- upload image and open camera button disable due to permission configuration
import { StyleSheet, View } from 'react-native';
import React, { useState } from 'react';
import ChatUI from 'akleem-react-native-chat';
const initialMessages = [
{ id: '1', text: 'Hello!', fromMe: false, timestamp: Date.now(), image: null },
{ id: '2', text: 'Hi there!', fromMe: true, timestamp: Date.now(), image: null },
];
const ChatScreen = () => {
const [messages, setMessages] = useState(initialMessages);
const onSendMessage = (message) => {
setMessages([...messages, message]);
};
return (
<View style={styles.container}>
<ChatUI
messageData={messages} // Render all messages
onSendMessage={onSendMessage} // Send new messages
profileData={{ name: 'John' }} // Profile data
themesColor={'blue'} // Default is WhatsApp theme
/>
</View>
);
};
export default ChatScreen;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});
Prop Name | Type | Description |
---|---|---|
messageData |
Array |
List of initial chat messages |
onSendMessage |
Function |
Callback function when a message is sent |
profileData |
Object |
User profile data (e.g., { name: 'John' } ) |
themesColor |
color code |
Theme customization (e.g., {'#6200ea'} ) |
Ensure you pass messages in the following format:
[
{
"id": "1",
"text": "Hello!",
"fromMe": false,
"timestamp": 1711025520000,
"image": null
},
{
"id": "2",
"text": "Hi there!",
"fromMe": true,
"timestamp": 1711025580000,
"image": "https://example.com/sample.jpg"
}
]
react-native-chat-ui/
├── src/
│ ├── components/
│ │ ├── ChatBubble.js
│ │ ├── ChatInput.js
│ ├── screens/
│ │ ├── ChatScreen.js
│ ├── assets/
│ │ ├── chat-preview.png
├── package.json
├── README.md
├── index.js
If you want to publish your own version of this package to npm, follow these steps:
npm init
Ensure the name
field in package.json
is unique and not already taken on npm.
npm login
For a private package:
npm publish
For a public package:
npm publish --access public
To update the package, increment the version number in package.json
and run:
npm publish
If you need to remove a package from npm:
npm unpublish package-name --force
This README.md
provides complete instructions on installing, using, and publishing your package. 🚀 Let me know if you need further modifications!