【问题标题】:How to display pdf (documents) in react-native-gifted-chat如何在 react-native-gifted-chat 中显示 pdf(文档)
【发布时间】:2022-07-11 18:55:35
【问题描述】:

我通过 twilio 消息传递的天才聊天发送图像和 pdf。发送后,我无法在有天赋的聊天 ui 中显示文档。

这是天才聊天将接受的消息对象:

{
  _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
}

如何在此处附加 pdf(文档)链接

目前正在附加带有图像键的 pdf url,它返回空白,因为它将该 url 识别为图像。

我怎样才能显示 pdf 而不是空白?

这是当前结果

【问题讨论】:

    标签: react-native twilio-programmable-chat react-native-gifted-chat


    【解决方案1】:

    我认为您可以在消息对象中定义“文档”而不是使用“图像”。 然后你可以像这样在 props renderCustomView 中自定义你的文档消息:

    // Custom render message
    const renderCustomView = (props) => {
    // Custom document message bubble
      if (props.currentMessage.document) {
        // Your custom pdf message
      }
    }
    

    【讨论】: