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.6
  • 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

Changelog

  • 0.0.6 Fix renderImage() exception
  • 0.0.5 The UI is now updated when receiving new messages prop. Thanks @burgalon for PR
  • 0.0.4 Update doc and example
  • 0.0.3 Fix image position, Add hideTextInput prop

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
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) => {}
invertedBooleanInvert vertically the orientation of the chatBothtrue
hideTextInputBooleanHide or not the text inputBothfalse
keyboardDismissModeStringMethod to dismiss the keyboard when dragging (none, interactive, on-drag)Bothon-drag
returnKeyTypeBooleanDetermine if pressing 'send' will trigger handleSendiOSfalse

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(),
  // ...any attributes you want
};

License

MIT

Feel free to ask me questions on Twitter @FaridSafi !

Keywords

FAQs

Package last updated on 07 Dec 2015

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