【问题标题】:How to display the image preview in react native app?如何在反应原生应用程序中显示图像预览?
【发布时间】:2018-06-23 17:42:00
【问题描述】:

我可以知道如何在 React Native 应用中显示图像预览吗?在 iOS 中,如果它是 http url,我可以显示,但在 Android 平台中,我无法查看图像,如下面的屏幕截图所示:

在 Android 中运行的 React Native 应用程序:

iOS 平台的图像预览:

在代码中,附件字段等于 this.state.attachment,因此可以看到 http url,但是当我将其与图像连接时,图像预览为空白。但是,如果我在 iOS 中硬编码确切的 http url 地址,它可以显示图像。

//in iOS this one can show the image but Android cannot
let Image_Http_URL = { uri : 'http://localhost:3000/api/containers/container/download/FMS-SiteIcon_v2.jpg'};

//this one is both cannot but in url can show the http url address
let Image_Http_URL = { uri : 'this.state.attachment' };

<Image
 style={{width: 200, height: 200}}
 source={Image_Http_URL}
/>

<FloatLabelTextInput
 onChangeText={(attachment) => {
 this.setState({attachment})
 }}
value={this.state.attachment}
editable={false}
placeholder="Attachment"
style={styles.input}/>

请帮忙,谢谢。

【问题讨论】:

  • Image IOS/Android 组件两边都使用原生组件。要在这个组件中成像,两者都有一种方法。调试您的代码并交叉检查所有内容。
  • @Heisen-Berg,你的意思是这样吗? localhost:3000/api/containers/container/download/…'}} /> 我这样放的也不能在Android中显示。

标签: android ios image react-native preview


【解决方案1】:

this.state.attachment 不应包含在字符串中,试试{ uri : this.state.attachment };{ uri : {this.state.attachment} };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多