【问题标题】:How to reference a launch image in React Native如何在 React Native 中引用启动图像
【发布时间】:2019-04-29 04:28:56
【问题描述】:

我想在我的 React 应用程序中使用 iOS 启动图像作为背景图像,但我不知道如何引用它。我尝试了一些类似于以下内容的方法:

<Image source={{uri: "LaunchImage"}} />

但是我收到了这个错误:

Haste 模块地图中不存在模块 `LaunchImage`。

有什么想法吗?

【问题讨论】:

    标签: react-native launchimage


    【解决方案1】:

    请在您的项目 src 文件夹中包含一个图像,并请像这样使用 require() 调用图像路径

    <Image source={{uri: require('../Images/LaunchImage.png')}} />
    

    这里 LaunchImage.png 是它的文件名,'Images' 是文件夹名

    【讨论】:

    • 谢谢。当我指定确切的图像时,它看起来像是在工作:source={require("../ios/ProjectName/Images.xcassets/LaunchImage.launchimage/828x1792.png")}。是否无法自动选择确切的资产,就像在 Objective-C 或 Swift 中引用 LaunchImage 时一样?
    【解决方案2】:

    尝试使用图像背景标签,例如

      <ImageBackground source={...} style={{width: '100%', height: '100%'}}>
        <Text>Inside</Text>
      </ImageBackground>
    

    【讨论】:

    • 谢谢——我得到了同样的错误:“Module `LaunchImage` does not exist in the Haste module map”。
    • 我认为您需要在正确的位置提供 LaunchImage 的正确位置,而不仅仅是“LaunchImage”,而是像“../../LaunchImage”这样的源。
    • 正确的位置实际上是我想要弄清楚的。看到这个:stackoverflow.com/questions/19410066/…
    • 您是否尝试过使用正确的路径,我的路径是:- import splashscreen from '../Projectname/ios/projectname/Images.xcassets/splashscreen/splashscreen.imageset' 正在导入索引.因此,在您导入时对此进行更改
    • @G.Kumar 我添加了这一行:import launchImage from "../ios/PackageName/Images.xcassets/LaunchImage.launchimage"。这是相对于我的组件的正确路径。但是,我仍然收到“模块不存在”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    相关资源
    最近更新 更多