import React, { useContext, useEffect, useState } from "react"; import { StyleSheet, View, ScrollView } from "react-native"; import * as Yup from "yup"; import { Form, FormPicker as Picker, SubmitButton, FormField, } from "../components/forms"; import Screen from "../components/Screen"; import FormImagePicker from "../components/forms/FormImagePicker"; import useLocation from "../hooks/useLocation"; import { Image, Text, TouchableOpacity } from "react-native"; import colors from "../config/colors"; import { TouchableNativeFeedback } from "react-native-gesture-handler"; import { insertRainData } from "../database/databaseLoader"; import { showMessage } from "react-native-flash-message"; import { scaleDimsFromWidth, dimensions } from "../config/dimensions"; import assets from "../config/assets"; import moment from "moment"; import FormDatePicker from "../components/forms/FormDatePicker"; import FormLocationPicker from "../components/forms/FormLocationPicker"; import { EventLocationContext } from "../context/EventLocationContext"; const validationSchema = Yup.object().shape({ images: Yup.array(), description: Yup.string().label("Description"), }); const borderWidth = 4; function RainSharingDataScreen(props) { const [rain, setRain] = useState(-1); const [error, setError] = useState(false); const dims = scaleDimsFromWidth(85, 85, 27); const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); const context = useContext(EventLocationContext); useEffect(() => { context.defaultLocation(); }, []); const location = context.eventCoordinates; return (
{ if (rain == -1) { setError(true); return; } insertRainData({ ...values, rain, location, date, time }); showMessage({ message: "Informação enviada!", duration: 1950, icon: "success", type: "success", onPress: () => {}, }); props.navigation.navigate("Home"); }} validationSchema={validationSchema} > setRain(0)}> setRain(1)}> setRain(2)}> setRain(3)}> setRain(4)}> {/* setRain(5)}> Pancada de chuva */} {error && rain == -1 && ( Selecione o nível da chuva )} {/*Data da coleta:*/} setDate(value)} onTimeChange={(value) => setTime(value)} /> {/*Local do evento:*/} props.navigation.navigate("FormMap")} >
); } const styles = StyleSheet.create({ container: { padding: 10, backgroundColor: colors.white, }, img_block: { flex: 1, borderRadius: 5, borderStyle: "dotted", borderColor: colors.white, borderWidth: borderWidth, alignItems: "center", }, imgs_row: { flexDirection: "row", justifyContent: "space-between", }, error_txt: { fontSize: dimensions.text.default, color: colors.danger, }, }); export default RainSharingDataScreen;