react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Windows] Static local image

Open PCharpentier opened this issue 11 years ago • 4 comments

I have a problem with the new asset system on Windows : http://stackoverflow.com/questions/33778766/react-native-android-static-local-image/33780354?noredirect=1#comment55335206_33780354

I have a file index.android.js in my repository App with this code :

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

It works if I put my image in App and in App/assets. If I just put my image in App, it doesn't work.

Then, I want write my code like this :

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

But, if I put my image in App/img, it doesn't work. Even if I add my image in App/assets/img, it doesn't work.

PCharpentier avatar Nov 18 '15 16:11 PCharpentier

I have the same issue here. The problem seems to be that react is generating invalid requests to the packager.

The asset provider (packager) serves the files well, but the request that comes from the app adds an additional dash to the URL, making it invalid.

capture

Any solution for this?

WoLfulus avatar Nov 19 '15 04:11 WoLfulus

Changing the line (packager/react-packager/src/Bundler/index.js)

 httpServerLocation: path.join('/assets', path.dirname(relPath)),

to

 httpServerLocation: path.join('assets', path.dirname(relPath)),

Location: https://github.com/facebook/react-native/blob/b907f40957bbd822cfab3a56d82363ffd58d2e78/packager/react-packager/src/Bundler/index.js#L306

This solves the issue, but I'm not sure if it will create additional issues on other platforms tho.

WoLfulus avatar Nov 19 '15 05:11 WoLfulus

@WoLfulus It's ok for us now on Windows with your information. Thinks

LaurentSouchet-Orange avatar Nov 19 '15 08:11 LaurentSouchet-Orange

@WoLfulus Thanks for your help.

PCharpentier avatar Nov 20 '15 11:11 PCharpentier