2018-12-21 10:55:35 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-07-17 19:10:27 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ActionSheet from 'react-native-actionsheet';
|
|
|
|
|
|
|
|
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(() => {
|
2018-08-01 19:35:06 +00:00
|
|
|
if (this.actionSheet && this.actionSheet.show) {
|
|
|
|
this.actionSheet.show();
|
|
|
|
}
|
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 (
|
|
|
|
<ActionSheet
|
2018-08-01 19:35:06 +00:00
|
|
|
ref={o => this.actionSheet = o}
|
2018-07-17 19:10:27 +00:00
|
|
|
options={this.options}
|
|
|
|
cancelButtonIndex={this.CANCEL_INDEX}
|
|
|
|
onPress={this.handleActionPress}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|