React-native-gifted-chat: Question: How to use local images?

Created on 26 Mar 2017  路  6Comments  路  Source: FaridSafi/react-native-gifted-chat

sorry, it's probably a stupid question, but is there any example or description how to use avatars or images in messages with local images? All the examples always use a web url and e.g.

require("./imgs/1.png")

as param doesn't seem to do anything :)

All 6 comments

has been answered at other places already.

@sagax85 How did you do ? I can not integrate the local images for the photos and the avatar 馃槶

So if you could help me, I would be grateful 馃榾

@sagax85 in the componentWillMount of the demo code provided on the main page, try adding a relative path:

  componentWillMount() {
    this.setState({
      messages: [
        {
          _id: 1,
          text: 'Hello User',
          createdAt: new Date(),
          user: {
            _id: 2,
            name: 'User',
            avatar: require('./my_picture.png'),
          },
        },
      ],
    });
  }           

@wrightmk it is not working with me

This isn't working for me either.

It works if I add the relative path to the user prop of GiftedChat, but if i try adding a local picture with relative path to a message in onSend it will get the wrong image number. It is seemingly picking a random number.

requiring an image from a local folder and adding as an avatar is working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

redwind picture redwind  路  3Comments

luisar picture luisar  路  3Comments

inceptivetech picture inceptivetech  路  3Comments

radvc picture radvc  路  3Comments

luisfuertes picture luisfuertes  路  3Comments