I am at beginner's stage of react native trying to parse an array of objects from image library, I have gone through multiple solutions but encountering various errors.
Following is the json I get after selecting image.
[
{
modificationDate:'1552035213000',
size:2097434,
mime:'image/jpeg',
height:4608,
width:2218,
path:'file:///data/user/0/com.matrimonialapp/cache/react-native-image-crop-picker/image-cefaffca-0fad-4b1a-aae5-1e7393a5da3f.jpg'
},
{
modificationDate:'1552035213000',
size:2097434,
mime:'image/jpeg',
height:4608,
width:2218,
path:'file:///data/user/0/com.matrimonialapp/cache/react-native-image-crop-picker/image-d6052c1f-c075-47dc-a759-ff99d4d082a8.jpg'
},
{
modificationDate:'1552035213000',
size:2097434,
mime:'image/jpeg',
height:4608,
width:2218,
path:'file:///data/user/0/com.matrimonialapp/cache/react-native-image-crop-picker/image-73537151-5f6c-4ece-9ee8-9e018b243ace.jpg'
},
{
modificationDate:'1552035213000',
size:1048858,
mime:'image/jpeg',
height:4608,
width:2218,
path:'file:///data/user/0/com.matrimonialapp/cache/react-native-image-crop-picker/image-8ff9fe38-8050-447e-aea8-64976672fbef.jpg'
}
]
The solution which I have been trying is from the following link.
The solutions which I have tried out are
let markers = [...this.state.markers];
let index = markers.findIndex(el => el.name === 'name');
markers[index] = {...markers[index], key: value};
this.setState({ markers });
What I am not getting is where they are getting value variable. I need to create an array out of the 'path' key. Following is my code
constructor(props){
super(props);
this.ShowPicker = this.ShowPicker.bind(this);
this.createModal = this.createModal.bind(this);
this.state = {date:"06/07/1988",valueInTens:0,valueInUnits:0,valueInFeet:0,valueInInches:0,checkedForKids:false,checkedForDrink:false,checkedForSmoke:false,filePath: {},dataForMaritalStatus:"",showSlider:false,language:"English"
,isModalVisible:false,checked:false,mImages:[] };
}
my method to open picker library
chooseFile = () => {
var options = {
title: 'Select Image',
customButtons: [
{ name: 'customOptionKey', title: 'Choose Photo from Custom Option' },
],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.openPicker({
multiple: true
}).then(images => {
-> images // I need to create array out of this object
// let markers = [...this.state.mImages];
// let index = markers.findIndex(images => images.name === 'path');
// markers[index] = {...markers[index], key: value};
// this.setState({ markers });
// let newMarkers = mImages.map(el => (
// el.name==='name'? {...el, key: value}: el
// ))
//this.setState({ markers });
this.setState((mImages:images);
console.log(images);
});
this is where I need to ass the images
<Gallery
style={{height:200,width:300, flex: 1, backgroundColor: 'white' }}
// images={[
// ]}
/>