2019-01-30 12:11:02 +00:00
|
|
|
import { PureComponent } from 'react';
|
2018-07-17 19:10:27 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-30 12:11:02 +00:00
|
|
|
import ActionSheet from 'react-native-action-sheet';
|
2018-07-17 19:10:27 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
export default class FilesActions extends PureComponent {
|
2018-07-17 19:10:27 +00:00
|
|
|
static propTypes = {
|
|
|
|
hideActions: PropTypes.func.isRequired,
|
|
|
|
takePhoto: PropTypes.func.isRequired,
|
|
|
|
chooseFromLibrary: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Cancel
|
|
|
|
this.options = [I18n.t('Cancel')];
|
|
|
|
this.CANCEL_INDEX = 0;
|
|
|
|
|
|
|
|
// Photo
|
|
|
|
this.options.push(I18n.t('Take_a_photo'));
|
|
|
|
this.PHOTO_INDEX = 1;
|
|
|
|
|
|
|
|
// Library
|
|
|
|
this.options.push(I18n.t('Choose_from_library'));
|
|
|
|
this.LIBRARY_INDEX = 2;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2019-01-30 12:11:02 +00:00
|
|
|
this.showActionSheet();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showActionSheet = () => {
|
|
|
|
ActionSheet.showActionSheetWithOptions({
|
|
|
|
options: this.options,
|
|
|
|
cancelButtonIndex: this.CANCEL_INDEX
|
|
|
|
}, (actionIndex) => {
|
|
|
|
this.handleActionPress(actionIndex);
|
2018-07-17 19:10:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleActionPress = (actionIndex) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { takePhoto, chooseFromLibrary, hideActions } = this.props;
|
2018-07-17 19:10:27 +00:00
|
|
|
switch (actionIndex) {
|
|
|
|
case this.PHOTO_INDEX:
|
|
|
|
takePhoto();
|
|
|
|
break;
|
|
|
|
case this.LIBRARY_INDEX:
|
|
|
|
chooseFromLibrary();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
hideActions();
|
2018-07-17 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-01-30 12:11:02 +00:00
|
|
|
null
|
2018-07-17 19:10:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|