【问题标题】:How can I send files ( pdf, text, jpg) through react-native-gifted-chat?如何通过 react-native-gifted-chat 发送文件(pdf、文本、jpg)?
【发布时间】:2020-04-20 10:47:56
【问题描述】:

任何人都可以通过反应原生天才聊天来帮助我吗?我想分享(.pdf、docs、.txt、.jpg)之类的文件。该怎么做?

【问题讨论】:

  • 如果您想获得帮助,请查看stackoverflow.com/help/how-to-ask。如果您想要简单的教程,最好在 dev.to 或其他平台上询问!
  • @SupriyaGoarai 你能解决吗

标签: react-native-gifted-chat


【解决方案1】:

你必须使用renderCustomView (Function) - Custom view inside the bubble 属性。 并将一些元信息添加到您的消息数据中,例如this is a SPECIAL message,如果您遇到特殊消息,最后在 renderCustomView 中进行测试。

【讨论】:

    【解决方案2】:

    react-native-gifted-chat 已经包含了对图片和视频的支持,使用了 IMessage 的 video 和 image 属性,只是通过了资源的链接

    {
      _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',
      // You can also add a video prop:
      video: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
      // Mark the message as sent, using one tick
      sent: true,
      // Mark the message as received, using two tick
      received: true,
      // Mark the message as pending with a clock loader
      pending: true,
      // Any additional custom parameters are passed through
    }
    

    对于其余类型,您必须使用其中一个渲染函数来实现自己的逻辑,我认为您可以 renderMessageImage 带有指向资源图标的链接并添加描述,您还应该处理点击事件开始下载

    【讨论】:

      猜你喜欢
      • 2022-07-11
      • 1970-01-01
      • 2018-05-25
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2020-03-15
      • 2021-02-12
      相关资源
      最近更新 更多