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.1
  • Source
  • npm
  • Socket score

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

react-native-gifted-messenger

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

Simple example

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

var GiftedMessengerExample = React.createClass({
  getInitialMessages() {
    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.refs.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='GiftedMessenger'
        initialMessages={this.getInitialMessages()}
        handleSend={this.handleSend}
        maxHeight={Dimensions.get('window').height - navBarHeight} // 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
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) => {}
initialMessagesArrayList of initial messagesBoth[]
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
  • In Android React-Native 0.14.2, I recommend to use inverted={false} until issue #3557 is fixed

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

Follow @FaridSafi on Twitter for updates about React-Native !

Keywords

FAQs

Package last updated on 19 Nov 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