elephant-com
Version:
the general component for elephant washing shoes
42 lines (39 loc) • 1.21 kB
JavaScript
/* eslint-disable no-useless-escape */
import { ActionSheet } from 'antd-mobile';
import ImagePicker from 'react-native-image-crop-picker';
export const ImagePickerCustom = ({ title, options, callback }) => {
const BUTTONS = ['拍摄', '从手机相册选择', '取消'];
const imagePickerOptions = { ...{
width: 300,
height: 300,
cropping: true,
includeBase64: true,
},
...options };
ActionSheet.showActionSheetWithOptions({
options: BUTTONS,
cancelButtonIndex: BUTTONS.length - 1,
message: title,
maskClosable: true,
},
(buttonIndex) => {
if (buttonIndex === 0) {
ImagePicker.openCamera(imagePickerOptions).then((image) => {
callback({
base64: `data:image/jpg;base64,${image.data}`,
path: image.path,
filename: image.path.replace(/^.*[\\\/]/, ''),
});
});
}
if (buttonIndex === 1) {
ImagePicker.openPicker(imagePickerOptions).then((image) => {
callback({
base64: `data:image/jpg;base64,${image.data}`,
path: image.path,
filename: image.path.replace(/^.*[\\\/]/, ''),
});
});
}
});
};