Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [...]
- constructor(props){
- super(props);
- this.state = {
- responseImage: [],
- }
- this.responseArray= []
- }
- escolherImagem(){
- const options = {
- title: 'Escolha uma imagem',
- storageOptions: {
- skipBackup: true,
- path: 'images'
- }
- };
- return ImagePicker.showImagePicker(options, (response) => {
- console.log('Response = ', response);
- this.responseArray.push(response);
- console.log('responseArray', this.responseArray)
- this.setState({responseImage: this.responseArray});
- console.log('responseImage', this.state.responseImage)
- if (response.didCancel) {
- console.log('User cancelled image picker');
- }
- else if (response.error) {
- console.log('ImagePicker Error: ', response.error);
- Alert.alert(
- 'Erro',
- 'Escolha um formado válido de imagem',
- [
- {text: 'OK', onPress: () => false},
- ],
- { cancelable: false }
- )
- }
- });
- }
- chooseImages(){
- return(
- <TouchableHighlight
- style={{marginHorizontal: 15}}
- underlayColor='#f8f8ff'
- activeOpacity = {0.3}
- onPress={() => this.escolherImagem()}
- >
- <Icon name="ios-image" color="#6495ed" size={55} />
- </TouchableHighlight>
- );
- }
- renderImages(){
- return(
- <View style={{flexDirection:'row'}} >
- {this.state.responseImage.map( (imagem, index) => {
- return(
- <View key={imagem.path}>
- <View>
- /**Deletar Imagem */
- <TouchableHighlight
- style={{marginHorizontal: 15}}
- underlayColor='#f8f8ff'
- activeOpacity = {0.3}
- onPress={() => {
- this.setState( {responseImage: this.responseArray.splice(index, index)})
- } }
- >
- <Icon name="ios-close" color="#6495ed" size={25} />
- </TouchableHighlight>
- <Image
- style={{width: 100, height: 100, marginHorizontal: 5}}
- source={{uri: 'data:image/jpeg;base64,' + imagem.data}}
- />
- </View>
- </View>
- );
- })}
- </View>
- );
- }
- [...]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement