import React, { Component } from 'react';
import {
Image,
KeyboardAvoidingView,
StyleSheet,
TextInput,
View
} from 'react-native';
import { SimpleLineIcons } from '@expo/vector-icons';
import { ImagePicker, Permissions } from 'expo';
import TouchableItem from './TouchableItem';
export default class JournalItemInput extends Component {
state = { photo: null };
_hasCameraPermissions = async () => {
let permission = await Permissions.askAsync(Permissions.CAMERA);
if (permission.status !== 'granted') {
console.log('Permission to camera was denied');
return false;
}
permission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (permission.status !== 'granted') {
console.log('Permission to camera roll was denied');
return false;
}
return true;
};
_launchCamera = async () => {
if (this._hasCameraPermissions()) {
const result = await ImagePicker.launchCameraAsync();
if (!result.cancelled) {
this.setState({ photo: result.uri });
this.textInput.focus();
}
}
};
_submit(text) {
this.textInput.clear();
this.props.onSubmit(text);
}
render() {
const photoIcon = this.state.photo ? (
) : (
);
return (
this._launchCamera()}>
{photoIcon}
(this.textInput = input)}
placeholder="Tagebucheintrag erstellen"
returnKeyType="done"
underlineColorAndroid="transparent"
onSubmitEditing={event => this._submit(event.nativeEvent.text)}
/>
);
}
}
const styles = StyleSheet.create({
inputContainer: {
flexDirection: 'row',
borderColor: 'deepskyblue',
borderRadius: 8,
borderWidth: 1,
margin: 5,
paddingHorizontal: 5
},
input: {
flex: 1,
height: 40
},
photoIcon: {
alignSelf: 'center',
marginLeft: 5,
marginRight: 15
},
imagePreview: {
width: 24,
height: 24
}
});