|
|
@ -20,6 +20,10 @@ const FormDatePicker = (props) => { |
|
|
|
const [date, setDate] = useState(moment(defaultDate)); |
|
|
|
const [show, setShow] = useState(false); |
|
|
|
const [auxDate, setAuxDate] = useState(moment()); |
|
|
|
const [mode, setMode] = useState('date'); |
|
|
|
const [time, setTime] = useState(moment(defaultDate)); |
|
|
|
|
|
|
|
//-------------------------- Time picker ainda não está habilitado pra ios --------------------------------
|
|
|
|
|
|
|
|
const onChange = (e, selectedDate) => { |
|
|
|
setAuxDate(moment(selectedDate)); // variavel auxiliar para não alterar a data com a rolagem, apenas com o done
|
|
|
@ -28,23 +32,33 @@ const FormDatePicker = (props) => { |
|
|
|
const androidOnChange = (e, selectedDate) => { |
|
|
|
setShow(false); |
|
|
|
if (selectedDate) { |
|
|
|
setDate(moment(selectedDate)); |
|
|
|
props.onDateChange(selectedDate); |
|
|
|
if (mode == 'date') { |
|
|
|
setDate(moment(selectedDate)); |
|
|
|
props.onDateChange(selectedDate); |
|
|
|
setMode('time'); |
|
|
|
setShow(true); // to show the picker again in time mode
|
|
|
|
} else { |
|
|
|
setTime(moment(selectedDate)); |
|
|
|
props.onTimeChange(selectedDate); |
|
|
|
setShow(false); |
|
|
|
setMode('date'); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const onCancelPress = () => { |
|
|
|
//setDate(moment(defaultDate));
|
|
|
|
setShow(false); |
|
|
|
//console.log(moment(defaultDate).format("DD-MM-YYYY"))
|
|
|
|
}; |
|
|
|
|
|
|
|
const onDonePress = () => { |
|
|
|
setDate(moment(auxDate)); //atualizar a data com a variável auxiliar
|
|
|
|
props.onDateChange(auxDate); |
|
|
|
setShow(false); |
|
|
|
//console.log("done");
|
|
|
|
//console.log(date.format("DD-MM-YYYY"));
|
|
|
|
}; |
|
|
|
|
|
|
|
const formatDate = (date, time) => { |
|
|
|
time.getHours(); |
|
|
|
time.getMinuts(); |
|
|
|
}; |
|
|
|
|
|
|
|
const renderDatePicker = () => { |
|
|
@ -52,12 +66,18 @@ const FormDatePicker = (props) => { |
|
|
|
<DateTimePicker |
|
|
|
timeZoneOffsetInDays={-1} |
|
|
|
value={new Date(auxDate)} |
|
|
|
mode="date" |
|
|
|
mode={mode} |
|
|
|
is24Hour={true} |
|
|
|
minimumDate={new Date(moment().subtract(1, "month"))} |
|
|
|
maximumDate={new Date(moment())} |
|
|
|
formatChosenDate={(selectedDate) => { |
|
|
|
return moment(selectedDate).format("DD/MM/YYYY"); |
|
|
|
}} //formatar a data do selected date
|
|
|
|
if(mode == "date"){ |
|
|
|
return moment(selectedDate).format("DD/MM/YYYY"); |
|
|
|
} |
|
|
|
else{ |
|
|
|
return moment(selectedDate).format("HH:mm"); |
|
|
|
} |
|
|
|
}} //formatar a data e hora do selected date
|
|
|
|
display={Platform.OS === "ios" ? "spinner" : "default"} |
|
|
|
onChange={Platform.OS === "ios" ? onChange : androidOnChange} |
|
|
|
/> |
|
|
@ -77,7 +97,7 @@ const FormDatePicker = (props) => { |
|
|
|
<View style={styles.dateInput}> |
|
|
|
<Text style={{ fontSize: dimensions.text.default }}> |
|
|
|
{" "} |
|
|
|
{date.format("DD/MM/YYYY")} |
|
|
|
{date.format("DD/MM/YYYY")} {"\n"} {time.format("HH:mm")} |
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
<FontAwesome5 name="calendar-day" size={30} color="grey" /> |
|
|
@ -148,6 +168,7 @@ FormDatePicker.defaultProps = { |
|
|
|
textStyle: {}, |
|
|
|
defaultDate: moment(), |
|
|
|
onDateChange: () => {}, |
|
|
|
onTimeChange: () => {}, |
|
|
|
}; |
|
|
|
|
|
|
|
const styles = StyleSheet.create({ |
|
|
|