haxe-react / react-native

React Native externs for Haxe
61 stars 9 forks source link

How would one specify local images? #9

Closed Jarrio closed 7 years ago

Jarrio commented 7 years ago

I can't seem to find a way to reference require which is mentioned in the react docs. It then proceeds to say that we should store images in the source code tree but what is the correct location for that in this project setup? The haxe src folder, generated or the Android assets folder? I tried putting it in the assets folder and I can't seem to get the image to load after specifying the direct path and without?

kevinresol commented 7 years ago

require can be referenced as js.Lib.require For the file path, I just think that is it not related to this project. Keep in mind that Haxe and this library only helps you to generate the js file. Everything else still follows the rules set by react native.

Jarrio commented 7 years ago

It seems like it uses the generated/<platform> directory as the root. So I placed my image in bin/generated/android/0928.png and it was loaded. I've only tested this in debug so I'm not sure if there will be any differences for a release build.

With the image code being:

<Image source={require("./0928.png")} />

Thanks!

kevinresol commented 7 years ago

This is not unexpected. require resolves other files relative to the script itself.

Jarrio commented 7 years ago

I'm unfamiliar with javascript in general so this was not obvious, thanks for the help!