|
|
@@ -10,7 +10,7 @@ import { useModel } from "flooks";
|
|
|
import * as ImagePicker from "expo-image-picker";
|
|
|
import { Image, Platform } from "react-native";
|
|
|
|
|
|
-const _pickImage = loading => {
|
|
|
+const _pickImage = (loading, aspect) => {
|
|
|
return ImagePicker.requestCameraRollPermissionsAsync()
|
|
|
.then(res => {
|
|
|
if (!res.granted) {
|
|
|
@@ -19,8 +19,8 @@ const _pickImage = loading => {
|
|
|
return ImagePicker.launchImageLibraryAsync({
|
|
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
|
|
allowsEditing: true,
|
|
|
- aspect: [1, 1],
|
|
|
- quality: 1,
|
|
|
+ aspect: aspect || [(1, 1)],
|
|
|
+ quality: 0.6,
|
|
|
base64: true,
|
|
|
});
|
|
|
}
|
|
|
@@ -43,17 +43,33 @@ export default function UpLoadImage(props) {
|
|
|
const { loading } = useModel("loadingModel", true);
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
const renderPulseIcon = props => <Icon {...props} name="plus-outline" />;
|
|
|
+ const { aspect, size } = props;
|
|
|
+
|
|
|
+ const width = React.useMemo(() => {
|
|
|
+ if (size) {
|
|
|
+ return size;
|
|
|
+ } else {
|
|
|
+ return 67;
|
|
|
+ }
|
|
|
+ }, [size, aspect]);
|
|
|
+
|
|
|
+ const height = React.useMemo(() => {
|
|
|
+ if (size && aspect) {
|
|
|
+ return (size / aspect[0]) * aspect[1];
|
|
|
+ } else if (size) {
|
|
|
+ return size;
|
|
|
+ } else {
|
|
|
+ return 67;
|
|
|
+ }
|
|
|
+ }, [size, aspect]);
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
<Button
|
|
|
- style={[
|
|
|
- props.style,
|
|
|
- props.size ? { width: props.size, height: props.size } : {},
|
|
|
- ]}
|
|
|
+ style={[props.style, { width, height }]}
|
|
|
appearance="imageButton"
|
|
|
onPress={() => {
|
|
|
- _pickImage(loading).then(img => {
|
|
|
+ _pickImage(loading, aspect).then(img => {
|
|
|
httpPost("/upload/base64", {
|
|
|
base64: img,
|
|
|
}).then(res => {
|