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