My Goal is to show the Image in that white space whenever is touched (TouchableHighlight) from CameraRoll
to the <Image/>
. I can't find any tutorial to do this and I just have a little knowledge in JavaScript so I decided to ask a question in Stack Overflow.
I just want an idea to make this Goal done. Thank you, guys!
This is the image to be understandable, it is more of like Instagram.
Here are my Codes:
state = {
photos: [],
index: null,
pickedImage: null
}
componentDidMount() {
requestExternalStoragePermission();
this.getPhotos();
};
setIndex = (index) => {
if (index === this.state.index) {
index = null
}
this.setState({ index })
};
getPhotos = () => {
CameraRoll.getPhotos({
first: 200,
assetType: 'All'
})
.then(res => {
this.setState({
photos: res.edges,
});
})
.catch((err) => {
console.log('Error image: ' + err);
});
};
render() {
return(
<View style={styles.container}>
<Image source={this.state.index} style={styles.image}/>
<ScrollView contentContainerStyle={styles.scrollView} showsVerticalScrollIndicator={false}>
{this.state.photos.map((photos, index) => {
return(
<TouchableHighlight
style={{opacity: index === this.state.index ? .5 : 1}}
onPress={() => this.setIndex(index)}
key={index}
underlayColor='transparent'
>
<Image
style={{width: width / 3, height: width /3}}
source={{uri: photos.node.image.uri}}
resizeMode='cover'
/>
</TouchableHighlight>
);
})}
</ScrollView>
</View>
);
}