React Naitve Android adds local images,

Source: Internet
Author: User

React Naitve Android adds local images,

Put the image file UePbdph.png in the same directory as index. android. js and introduce the following in index. android. js:

<Image source={require('./UePbdph.png')} style={styles.thumbnail}/>

Environment:

React version: 15.0.2

React-nativeb version: 0.26.2

React-native-cli version: 0.2.0

 

Open\ Node_modules \ react-native \ Libraries \ Image \ AssetSourceResolver. js file:

function getScaledAssetPath(asset): string {  var scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());  var scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';  var assetDir = assetPathUtils.getBasePath(asset);  return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;}

Changed:

function getScaledAssetPath(asset) {  var scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());  var scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';  var assetDir = assetPathUtils.getBasePath(asset);  //return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;   var imagePath = assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;  if (imagePath[0] == "/" || imagePath[0] == "\\") {      imagePath = imagePath.substr(1);  }  return imagePath;}

 

Problem:

1. If you put an image in a folder, for example, create an img folder in the root directory, and put the image in it, you can change the import method:

<Image source = {require ('./img/UePbdph.png')} style = {styles. thumbnail}/>

An error is reported. Why?

2. Where should I package it into an app in the root directory?

The above questions still need to be answered through further research. Please help me, tks!

 

 

Reference: http://blog.csdn.net/sbsujjbcy/article/details/49981529

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.