React Native Chatty

website·Indexed 30 days ago

https://muhammedkpln.github.io/react-native-chatty/

A customizable chat UI library for React Native featuring support for message replies, typing animations, haptic feedback, and custom bubble components. It includes features such as URL previews, image upload support, and a 'load earlier messages' button, utilizing recyclerlistview for optimal performance.

Tokens
5.3K
Snippets
33
Records
36
Agent score
74%

What's inside React Native Chatty

  1. Enable message reply support in Chatty

    To enable reply support in the Chatty component, you must manage the state of the message being replied to. Use the onReply prop to capture the message the user wants to reply to and the replyingTo prop to pass that message object back into the component for display.
    import React, { useState } from 'react';
    import { Chatty } from 'react-native-chatty';
    
    export default function MyReactPage() {
      const [messages, setMessages] = useState([]);
      const [replyingTo, setReplyingTo] = useState(null);
    
      return (
        <Chatty
          messages={messages}
          // Handle onreply event and store the message in state
          onReply={(message) => setReplyingTo(message)}
          // Provide the message object currently being replied to
          replyingTo={replyingTo}
          headerProps={{
            id: 0,
            username: "Muhammed Kaplan",
            avatar: { uri: "https://blalala.com" }
          }}
          footerProps={{
            onChangeText: (text) => { /* handle text change */ },
            onPressSend: (data) => { /* handle send */ }
          }}
        />
      );
    }
  2. Create interactive blog posts using MDX in Docusaurus

    Blog posts support Docusaurus Markdown features and MDX, allowing the use of React components directly within the markdown content to create interactive elements.
    <button onClick={() => alert('button clicked!')}>
      Click me!
    </button>
  3. Truncate blog post previews in list view

    To limit the amount of content displayed for a blog post in the list view, insert the <!-- truncate --> HTML comment at the point where the preview should end.
    This text will appear in the list view preview.
    
    <!-- truncate -->
    
    This text will only appear on the full blog post page.
  4. Create and manage blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory. Post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md (e.g., 2019-05-30-welcome.md) or from an index.md file within a dated folder (e.g., 2019-05-30-welcome/index.md). Blog authors can be managed in the authors.yml file, and posts support the use of tags.
  5. Implement a custom message bubble in Chatty

    To customize the appearance of message bubbles in the Chatty component, provide a function to the renderBubble prop that returns JSX.

    Warning: Using a completely custom bubble component disables certain built-in features, such as reply support. If you need these features, it is recommended to customize the provided default bubble instead of replacing it entirely.

    import React, { useState, useRef } from 'react';
    import { View, Text } from 'react-native';
    import { Chatty } from 'react-native-chatty';
    
    export default function MyReactPage() {
      const [messages, setMessages] = useState([]);
      const text = useRef('');
    
      const onPressSend = (data) => {
        // Implement sending logic (e.g., socket.send(data))
      };
    
      return (
        <Chatty
          messages={messages}
          headerProps={{
            id: 0,
            username: "Muhammed Kaplan",
            avatar: { uri: "https://blalala.com" }
          }}
          footerProps={{
            onChangeText: (_text) => text.current = _text,
            onPressSend
          }}
          renderBubble={(props) => (
            <View>
              <Text> Custom Bubble! </Text>
            </View>
          )}
        />
      );
    }
  6. Create and organize blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory. To co-locate images with a specific post, use a folder structure with an index.md file. Blog post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md (e.g., 2019-05-30-welcome.md).
  7. Install dependencies for image upload support

    Depending on your project type, install the appropriate image picker library. For Expo projects, use expo-image-picker. For bare React Native projects, use react-native-image-picker. If you are using a bare React Native project, you must run pod install after installation.
    # For Expo users
    npm i expo-image-picker
    
    # For bare RN users
    npm i react-native-image-picker
    # Then run:
    pod install
  8. Install haptic feedback dependencies for react-native-chatty

    To enable haptic feedback when a user receives a new message in react-native-chatty, you must install the appropriate native module based on your project type. For bare React Native projects, remember to run pod install after the npm installation to link the native dependencies.
    # For Expo users
    npm i expo-haptics
    
    # For bare React Native users
    npm i react-native-haptic-feedback
    # Then run:
    ncd ios && pod install && cd ..
  9. Install optional dependencies for react-native-chatty features

    Depending on the specific features you wish to use, you may need to install the following optional dependencies. Only install these if the corresponding feature is required in your application.
    # Optional dependencies based on feature usage:
    react-native-parsed-text
    react-native-image-viewing
    react-native-context-menu-view
    lottie-ios
    lottie-react-native
    moti
    expo-linear-gradient
    expo-image-picker # OR react-native-image-picker
    expo-haptics # OR react-native-haptic-feedback
  10. Set up and manage blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory. Post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md (e.g., 2019-05-30-welcome.md) or from an index.md file within a folder named with the date. Using a folder for a post allows for easier co-location of images.
  11. Install native dependencies for Bubble actions

    To enable bubble actions in react-native-chatty, you must install the react-native-context-menu-view native module. After installing the package, ensure you run pod install for iOS development.
    npm i react-native-context-menu-view
    # Then run:
    cd ios && pod install