Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-gifted-messenger

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-gifted-messenger

The chat of your next React-Native Apps

  • 0.0.24
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Gifted Messenger

Ready-to-use chat interface for iOS and Android React-Native apps

Dependency: React-Native >= v0.20.0 (scrollTo is now using {x, y, animated})

Changelog

0.0.24
  • Fix textInputContainer issue #83
0.0.23
  • Scroll to bottom after onSend, Add enablesReturnKeyAutomatically setting to end on return key (PR @alizbazar)
  • New prop onMessageLongPress (PR @corymsmith)
  • displayNamesInsideBubble and keyboardShouldPersistTaps props (PR @koppelaar)
  • Expose full rowData to renderCustomText and add dynamic hide/show text input (PR @bpeters)

Example

var GiftedMessenger = require('react-native-gifted-messenger');
var {Dimensions} = React;

var GiftedMessengerExample = React.createClass({
  getMessages() {
    return [
      {text: 'Are you building a chat app?', name: 'React-Native', image: {uri: 'https://facebook.github.io/react/img/logo_og.png'}, position: 'left', date: new Date(2015, 0, 16, 19, 0)},
      {text: "Yes, and I use Gifted Messenger!", name: 'Developer', image: null, position: 'right', date: new Date(2015, 0, 17, 19, 0)},
    ];
  },
  handleSend(message = {}, rowID = null) {
    // Send message.text to your server
  },
  handleReceive() {
    this._GiftedMessenger.appendMessage({
      text: 'Received message',
      name: 'Friend',
      image: {uri: 'https://facebook.github.io/react/img/logo_og.png'},
      position: 'left',
      date: new Date(),
    });
  },
  render() {
    return (
      <GiftedMessenger
        ref={(c) => this._GiftedMessenger = c}

        messages={this.getMessages()}
        handleSend={this.handleSend}
        maxHeight={Dimensions.get('window').height - 64} // 64 for the navBar

        styles={{
          bubbleLeft: {
            backgroundColor: '#e6e6eb',
            marginRight: 70,
          },
          bubbleRight: {
            backgroundColor: '#007aff',
            marginLeft: 70,
          },
        }}
      />
    );
  },
});

Advanced example

See GiftedMessengerExample/GiftedMessengerExample.js

Installation

npm install react-native-gifted-messenger --save

Props

Props nameTypeDescriptionPlatformDefault
messagesArrayList of messages to displayBoth[]
displayNamesBooleanDisplay or not the name of the interlocutor(s)Bothtrue
displayNamesInsideBubbleBooleanDisplay the name of the interlocutor(s) inside the bubbleBothfalse
placeholderStringTextInput placeholderBoth'Type a message...'
stylesFunctionStyles of children components - See GiftedMessenger.js/componentWillMountBoth{}
autoFocusBooleanTextInput auto focusBothtrue
onErrorButtonPressFunctionCalled when the re-send button is pressedBoth(message, rowID) => {}
loadEarlierMessagesButtonBooleanDisplay or not the button to load earlier messageBothfalse
loadEarlierMessagesButtonTextStringLabel of the 'Load Earlier Messages' buttonBoth'Load earlier messages'
onLoadEarlierMessagesFunctionCalled when 'Load Earlier Message' button is pressedBoth(oldestMessage, callback) => {}
handleSendFunctionCalled when a message is SentBoth(message, rowID) => {}
maxHeightIntegerMax height of the componentBothDimensions.get('window').height
senderNameStringName of the sender of the messagesBoth'Sender'
senderImageObjectImage of the senderBothnull
sendButtonTextString'Send' button labelBoth'Send'
onImagePressFunctionCalled when the image of a message is pressedBoth(rowData, rowID) => {}
parseTextBooleanIf the text has to be parsed with taskrabbit/react-native-parsed-textiOStrue
handleUrlPressFunctionCalled when a parsed url is pressediOS(url) => {}
handlePhonePressFunctionCalled when a parsed phone number is pressediOS(phone) => {}
handleEmailPressFunctionCalled when a parsed email is pressediOS(email) => {}
hideTextInputBooleanHide or not the text inputBothfalse
keyboardShouldPersistTapsBooleanWhen false, tapping the scrollview dismisses the keyboard.Bothtrue
keyboardDismissModeStringMethod to dismiss the keyboard when dragging (none, interactive, on-drag)Bothinteractive
returnKeyTypeBooleanDetermine if pressing 'send' will trigger handleSendiOSfalse
submitOnReturnBooleanSend message when clicking on submitBothfalse
forceRenderImageBooleanAlways render the users images (avatar)Bothfalse
onCustomSendFunctionIf you want to implement a progress bar. See PR #16Both(message) => {}
renderCustomTextFunctionImplement your own text renderingBoth(rowData) => {}
onChangeTextFunctionCalled on every keypress in the TextInputBoth(text) => {}

Props update

The UI is updated when receiving new messages prop.

API

  • appendMessages(messages = []) // Add messages at the end of the list view

  • appendMessage(message = {}) // Add 1 message at the end of the list view

  • prependMessages(messages = []) // Add messages at the begining of the list view

  • prependMessage(message = {}) // Add 1 message at the begining of the list view

  • setMessageStatus(status = '', rowID) // Set the status of a message ('ErrorButton', 'Sent', 'Seen', 'Anything you want')

  • getMessage(rowID) // Get message object by rowID

  • getPreviousMessage(rowID) // Get previous message object of a rowID

  • getNextMessage(rowID) // Get next message object of a rowID

Message object

var message = {
  text: 'Message content',
  name: "Sender's name",
  image: {uri: 'https://facebook.github.io/react/img/logo_og.png'},
  position: 'left', // left if received, right if sent
  date: new Date(),
  view: null, // A custom Bubble view
  // ...any attributes you want
};

License

MIT

Feel free to ask me questions on Twitter @FaridSafi !

Keywords

FAQs

Package last updated on 16 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc