import React, { useEffect, useState, useContext } from "react"; import { StyleSheet, View, TouchableOpacity, PixelRatio } 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 } from "react-native"; import colors from "../config/colors"; import { TouchableNativeFeedback } from "react-native-gesture-handler"; import { insertRiverData } from "../database/databaseLoader"; import { showMessage } from "react-native-flash-message"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import assets from "../config/assets"; import { scaleDimsFromWidth, dimensions } from "../config/dimensions"; 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 RiverFloodSharingDataScreen(props) { const [riverScale, setRiverScale] = useState(-1); const context = useContext(EventLocationContext); useEffect(() => { context.defaultLocation(); }, []); const location = context.eventCoordinates; const address = context.eventLocation; const [error, setError] = useState(false); const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); const dims = scaleDimsFromWidth(80, 80, 20); return (
{ if (riverScale == -1) { setError(true); return; } insertRiverData({ ...values, riverScale, location, date, time, address }); showMessage({ message: "Informação enviada!", duration: 1950, icon: "success", type: "success", }); props.navigation.navigate("Home"); }} validationSchema={validationSchema} > setRiverScale(0)}> {riverScale == 0 ? ( ) : ( )} setRiverScale(1)}> {riverScale == 1 ? ( ) : ( )} setRiverScale(2)}> {riverScale == 2 ? ( ) : ( )} setRiverScale(3)}> {riverScale == 3 ? ( ) : ( )} {error && riverScale == -1 && ( Selecione o nível do rio )} {/*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: { borderRadius: 5, borderStyle: "dotted", borderColor: colors.white, borderWidth: borderWidth, alignItems: "center", }, imgs_row: { flexDirection: "row", justifyContent: "space-between", }, error_txt: { fontSize: 18, color: colors.danger, }, }); export default RiverFloodSharingDataScreen;