Skip to content Skip to sidebar Skip to footer

React-native - Image Require Local Path From JSON

Hello comunity :) I am working on a testapp in react-native and try to get Images from a local storage place. Actual what i am doing: I give an image directlink source to a var and

Solution 1:

seems it similar with this issue1 issue2

i think if you use require() to add your image,you should give a static path,not a variable. because they need know the specific image source to bundle. use json is just like a uncertain source so it doesnt work now there is a pr to this,


Solution 2:

The best solution I found today is that no solution for object - variable for dynamically loading from json file in react-native, but have to convert that image to base64 format and add it to json file, after that dispatch it from there by normal.

export class AppModule { }
function _loadDataSoundFromJson(){ 
  return new Promise((resolve,reject)=>{ 
    if (soundData){ 
      setTimeout(function(){ 
        resolve(soundData) },1500) 
    }
	else { 
      reject("No data found") 
    }}); 
};

_renderNoPlaying = (item) => {
   return ( 
     <View style={styles.horizontalContainer}> 
     <Image 
       	source={{uri : item.img!=null?item.img:nullImg.nil}} 
       	resizeMethod={'scale'} 
     	style={{
     		width:150,
     		height:120, 
     		borderTopLeftRadius:20,
     		borderTopRightRadius:20}}
     /> 
     <Text style={styles.titleItem}>{item.key}</Text> 
)}

Post a Comment for "React-native - Image Require Local Path From JSON"