Added photo picker on Android

This commit is contained in:
John Lyon-Smith
2018-04-21 20:52:02 -07:00
parent 3c3ec55660
commit 4bc0a6cd30
10 changed files with 50 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ export class Home extends React.Component {
[
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.CAMERA,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
],
{
title: versionInfo.title,

View File

@@ -8,6 +8,7 @@ import {
Dimensions,
} from "react-native"
import { Icon } from "."
import ImagePicker from "react-native-image-picker"
import autobind from "autobind-decorator"
const getScreenPortraitDimensions = () => {
@@ -20,6 +21,36 @@ const getScreenPortraitDimensions = () => {
}
export class PhotoPanel extends Component {
@autobind
handlePhotoPress() {
ImagePicker.showImagePicker(
{
title: "Select Photo",
storageOptions: {
skipBackup: true,
path: "photos",
},
},
(response) => {
console.log("Response = ", response)
if (response.didCancel) {
console.log("User cancelled image picker")
} else if (response.error) {
console.log("ImagePicker Error: ", response.error)
} else if (response.customButton) {
console.log("User tapped custom button: ", response.customButton)
} else {
let source = { uri: response.uri }
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
console.log(source)
}
}
)
}
render() {
const { screenWidth, screenHeight } = getScreenPortraitDimensions()
const photoWidth = screenHeight / 4
@@ -62,7 +93,8 @@ export class PhotoPanel extends Component {
borderColor: "gray",
borderRadius: 4,
justifyContent: "center",
}}>
}}
onPress={this.handlePhotoPress}>
<Icon name="add" size={24} style={{ alignSelf: "center" }} />
</TouchableOpacity>
))}