Skip to content

Instantly share code, notes, and snippets.

@gerswin
Created March 1, 2018 22:37
Show Gist options
  • Save gerswin/ad7b9de3a5ab8d8b68aa16798cd1affe to your computer and use it in GitHub Desktop.
Save gerswin/ad7b9de3a5ab8d8b68aa16798cd1affe to your computer and use it in GitHub Desktop.
import React from 'react';
import { Button, Image, View } from 'react-native';
import { ImagePicker } from 'expo';
export default class ImagePickerExample extends React.Component {
state = {
image: [],
};
render() {
// let { image } = this.state;
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Pick an image from camera roll"
onPress={this._pickImage}
/>
{this._renderImages()}
</View>
);
}
_renderImages() {
let images = [];
//let remainder = 4 - (this.state.devices % 4);
this.state.image.map((item, index) => {
images.push(
<Image
key={index}
source={{ uri: item }}
style={{ width: 100, height: 100 }}
/>
);
});
return images;
}
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
this.setState({
image: this.state.image.concat([result.uri]),
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment