From e490e6614d9c191da0152155fbda3d3abb93a3b4 Mon Sep 17 00:00:00 2001 From: analuizaff Date: Mon, 21 Dec 2020 12:47:20 -0300 Subject: [PATCH] Date picker at pluviometer sharing data screen --- .../screens/PluviometerSharingDataScreen.js | 131 ++++++++++-------- 1 file changed, 77 insertions(+), 54 deletions(-) diff --git a/src/app/screens/PluviometerSharingDataScreen.js b/src/app/screens/PluviometerSharingDataScreen.js index 7c7218a..8f7cbf1 100644 --- a/src/app/screens/PluviometerSharingDataScreen.js +++ b/src/app/screens/PluviometerSharingDataScreen.js @@ -1,6 +1,6 @@ import React, { useState } from "react"; -import { StyleSheet, Text, View, Image } from "react-native"; +import { StyleSheet, Text, View, Image, Button, TouchableHighlight, Platform } from "react-native"; import * as Yup from "yup"; import { @@ -14,6 +14,12 @@ import DatePicker from "react-native-datepicker"; import useLocation from "../hooks/useLocation"; import FormImagePicker from "../components/forms/FormImagePicker"; import { insertPluviometerData } from "../database/databaseLoader"; +import RNDateTimePicker from '@react-native-community/datetimepicker'; +import { TextInput, TouchableOpacity } from "react-native-gesture-handler"; +import DateTimePicker from '@react-native-community/datetimepicker'; +import { FontAwesome5 } from '@expo/vector-icons'; + +import moment from 'moment'; const validationSchema = Yup.object().shape({ pluviometer: Yup.number().required().min(1).max(10000).label("pluviometer"), @@ -23,14 +29,47 @@ const validationSchema = Yup.object().shape({ function PluviometerSharingDataScreen(props) { const location = useLocation(); - var day = new Date().getDate(); - var month = new Date().getMonth() + 1; - var year = new Date().getFullYear(); + /*-------------------------------------------DATETIMEPICKER------------------------------------------------*/ + + const { textStyle, defaultDate } = props; + const [date, setDate] = useState(moment(defaultDate)) + const [show, setShow] = useState(false); + + const onAndroidChange = (e, selectedDate) => { + setShow(false); + if (selectedDate) { + setDate(moment(selectedDate)); + //props.onDateChange(selectedDate); + } + } + + const onCancelPress = () => { + setDate(moment(defaultDate)); + setShow(false); + } + + const onDonePress = () => { + // props.onDateChange(date); + setShow(false); + } - var currentDate = day + "/" + month + "/" + year; + const renderDatePicker = () => { + return ( + + ) + } - const [date, setDate] = useState(currentDate); + /*---------------------------------------------------------------------------------------------------------*/ + // var day = new Date().getDate(); + // var month = new Date().getMonth() + 1; + // var year = new Date().getFullYear(); return ( @@ -55,15 +94,7 @@ function PluviometerSharingDataScreen(props) { validationSchema={validationSchema} > - + Quantidade de chuva: - + Data da coleta: - { - setDate(date); - }} - /> + setShow(true)}> + + + {date.format('DD/MM/YYYY')} + + + {show && renderDatePicker()} + + - @@ -137,8 +142,26 @@ const styles = StyleSheet.create({ justifyContent: "center", alignItems: "center", }, - datePickerStyle: { - width: 180, + datePickerView: { + width: 280, + flexDirection: "row", + justifyContent:"space-between", + paddingVertical:15, + }, + datepickerStyle: { + borderRadius: 25, + width: 280, + backgroundColor: "#f8f4f4", + }, + dateIcon: { + marginRight:15, + }, + labelStyle:{ + fontSize: 16, + fontWeight: "bold", + textAlign: "left", + color: "#1976D2", + marginBottom: 5, }, });