Browse Source

Merge branch 'main' of github.com:IGSD-UoW/WPD-MobileApp

master
GabrielTrettel 4 years ago
parent
commit
e6c7a6fab4
  1. 35
      src/app/components/forms/FormImagePicker.js

35
src/app/components/forms/FormImagePicker.js

@ -1,20 +1,41 @@
import React from "react";
import React, { useState } from "react";
import { useFormikContext } from "formik"; import { useFormikContext } from "formik";
import ErrorMessage from "./ErrorMessage"; import ErrorMessage from "./ErrorMessage";
import ImageInputList from "../ImageInputList"; import ImageInputList from "../ImageInputList";
import { View, Text, StyleSheet } from "react-native";
import { View, Text, StyleSheet, Modal, Alert } from "react-native";
import colors from "../../config/colors"; import colors from "../../config/colors";
import { dimensions } from "../../config/dimensions"; import { dimensions } from "../../config/dimensions";
function FormImagePicker({ name }) { function FormImagePicker({ name }) {
const { errors, setFieldValue, touched, values } = useFormikContext(); const { errors, setFieldValue, touched, values } = useFormikContext();
const imageUris = values[name]; const imageUris = values[name];
const [modalVisible, setModalVisible] = useState(false);
const handleAdd = (uri) => { const handleAdd = (uri) => {
setFieldValue(name, [...imageUris, uri]);
if (imageUris.length === 0) {
setFieldValue(name, [uri]);
} else {
createTwoButtonAlert(uri);
}
}; };
const createTwoButtonAlert = (uri) =>
Alert.alert(
"Substituir imagem?",
"É possível enviar apenas uma imagem",
[
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{ text: "OK", onPress: () => setFieldValue(name, [uri])}
],
{ cancelable: false }
);
const handleRemove = (uri) => { const handleRemove = (uri) => {
setFieldValue( setFieldValue(
name, name,
@ -43,6 +64,14 @@ const styles = StyleSheet.create({
marginBottom: 5, marginBottom: 5,
marginTop: 15, marginTop: 15,
}, },
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 22,
},
}); });
export default FormImagePicker; export default FormImagePicker;
Loading…
Cancel
Save