GithubHelp home page GithubHelp logo

hama / react-native-gifted-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from faridsafi/react-native-gifted-chat

0.0 1.0 0.0 23.19 MB

๐Ÿ’ฌ The most complete chat UI for React Native

Home Page: http://gifted.chat

License: MIT License

JavaScript 90.22% Python 2.21% Java 1.66% Objective-C 5.91%

react-native-gifted-chat's Introduction

Gifted Chat

The most complete chat UI for React Native (formerly known as Gifted Messenger)

Dependency

Use 0.0.10 for RN < 0.40.0
Use 0.1.0 for RN >= 0.40.0

Installation

npm install react-native-gifted-chat --save

Android installation

  • Add android:windowSoftInputMode="adjustResize" to your Android Manifest android/app/src/main/AndroidManifest.xml
<!-- ... -->
<activity
  android:name=".MainActivity"
  android:label="@string/app_name"
  android:windowSoftInputMode="adjustResize"
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<!-- ... -->
  • If you plan to use GiftedChat inside a Modal, see #200

Example

import { GiftedChat } from 'react-native-gifted-chat';

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {messages: []};
    this.onSend = this.onSend.bind(this);
  }
  componentWillMount() {
    this.setState({
      messages: [
        {
          _id: 1,
          text: 'Hello developer',
          createdAt: new Date(Date.UTC(2016, 7, 30, 17, 20, 0)),
          user: {
            _id: 2,
            name: 'React Native',
            avatar: 'https://facebook.github.io/react/img/logo_og.png',
          },
        },
      ],
    });
  }
  onSend(messages = []) {
    this.setState((previousState) => {
      return {
        messages: GiftedChat.append(previousState.messages, messages),
      };
    });
  }
  render() {
    return (
      <GiftedChat
        messages={this.state.messages}
        onSend={this.onSend}
        user={{
          _id: 1,
        }}
      />
    );
  }
}

Advanced example

See example/App.js

Message object

{
  _id: 1,
  text: 'My message',
  createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
  user: {
    _id: 2,
    name: 'React Native',
    avatar: 'https://facebook.github.io/react/img/logo_og.png',
  },
  image: 'https://facebook.github.io/react/img/logo_og.png',
  // additional custom parameters
}

Props

  • messages (Array) - messages to display
  • messageIdGenerator (Function) - generate id for new message. By default is a UUID v4 generated by uuid.
  • user (Object) - user sending the messages {_id, name, avatar}
  • onSend (Function) - function to call when sending a message
  • locale (String) - localize the dates
  • isAnimated (Bool) - animates the view when the keyboard appears
  • loadEarlier (Bool) - enables the load earlier message button
  • onLoadEarlier (Function) - function to call when loading earlier messages
  • isLoadingEarlier (Bool) - display an ActivityIndicator when loading earlier messages
  • renderLoading (Function) - render a loading view when initializing
  • renderLoadEarlier (Function) - render the load earlier button
  • renderAvatar (Function) - renders the message avatar
  • renderAvatarOnTop (Bool) - render the message avatar, on top of consecutive messages. The default value is false.
  • renderBubble (Function) - render the message bubble
  • renderMessage (Function) - render the message container
  • renderMessageText (Function) - render the message text
  • renderMessageImage (Function) - render the message image
  • imageProps (Object) - extra props to be passed to the <Image> component created by the default renderMessageImage
  • lightboxProps (Object) - extra props to be passed to the MessageImage's Lightbox
  • renderCustomView (Function) - render a custom view inside the bubble
  • renderDay (Function) - render the day above a message
  • renderTime (Function) - render the message time
  • renderFooter (Function) - renders a fixed bottom view. Can be used for 'is typing message', see example/App.js
  • renderInputToolbar (Function) - render the composer container
  • renderActions (Function) - renders an action button on the left of the message composer
  • renderComposer (Function) - render the text input message composer
  • renderSend (Function) - render the send button
  • renderAccessory (Function) - renders a second line of actions below the message composer
  • onPressActionButton (Function) - callback to perform custom logic when the Action button is pressed (the default actionSheet will not be used)
  • bottomOffset (Integer) - distance of the chat from the bottom of the screen, useful if you display a tab bar
  • listViewProps (Object) - extra props to be passed to the <ListView>, some props can not be override, see the code in render method of MessageContainer for detail
  • keyboardShouldPersistTaps (Enum) - determines when the keyboard should stay visible after a tap <ScrollView>
  • onInputTextChanged (Function) - function that will be called when input text changes

Features

  • Custom components
  • InputToolbar avoiding keyboard
  • Multiline TextInput
  • Load earlier messages
  • Avatar as initials
  • Touchable links using react-native-parsed-text
  • Localized dates
  • Copy text messages to clipboard

License

Feel free to ask me questions on Twitter @FaridSafi !

react-native-gifted-chat's People

Contributors

alizbazar avatar austinkelleher avatar bpeters avatar brianinator avatar burgalon avatar charlle avatar cooperka avatar davidleonardi avatar faridsafi avatar fengliu222 avatar gnl avatar ianlin avatar jayshah123 avatar jeromegrosse avatar kesha-antonov avatar kfiroo avatar kirillpisarev avatar koppelaar avatar llgoer avatar luhui avatar niftylettuce avatar scarmuega avatar shauns avatar slavik0329 avatar swapkats avatar tafelito avatar tommoor avatar vgorte avatar wenkesj avatar zxcpoiu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.