Created
March 1, 2018 22:37
-
-
Save gerswin/ad7b9de3a5ab8d8b68aa16798cd1affe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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