|
@ -8,7 +8,7 @@ import { |
|
|
Platform, |
|
|
Platform, |
|
|
TouchableOpacity, |
|
|
TouchableOpacity, |
|
|
} from "react-native"; |
|
|
} from "react-native"; |
|
|
import { MaterialCommunityIcons } from '@expo/vector-icons' |
|
|
|
|
|
|
|
|
import { MaterialCommunityIcons } from "@expo/vector-icons"; |
|
|
import DateTimePicker from "@react-native-community/datetimepicker"; |
|
|
import DateTimePicker from "@react-native-community/datetimepicker"; |
|
|
|
|
|
|
|
|
import moment from "moment"; |
|
|
import moment from "moment"; |
|
@ -20,7 +20,7 @@ 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 [mode, setMode] = useState("date"); |
|
|
const [time, setTime] = useState(moment(defaultDate)); |
|
|
const [time, setTime] = useState(moment(defaultDate)); |
|
|
|
|
|
|
|
|
//-------------------------- Time picker ainda não está habilitado pra ios --------------------------------
|
|
|
//-------------------------- Time picker ainda não está habilitado pra ios --------------------------------
|
|
@ -32,16 +32,16 @@ const FormDatePicker = (props) => { |
|
|
const androidOnChange = (e, selectedDate) => { |
|
|
const androidOnChange = (e, selectedDate) => { |
|
|
setShow(false); |
|
|
setShow(false); |
|
|
if (selectedDate) { |
|
|
if (selectedDate) { |
|
|
if (mode == 'date') { |
|
|
|
|
|
|
|
|
if (mode == "date") { |
|
|
setDate(moment(selectedDate)); |
|
|
setDate(moment(selectedDate)); |
|
|
props.onDateChange(selectedDate); |
|
|
props.onDateChange(selectedDate); |
|
|
setMode('time'); |
|
|
|
|
|
|
|
|
setMode("time"); |
|
|
setShow(true); // to show the picker again in time mode
|
|
|
setShow(true); // to show the picker again in time mode
|
|
|
} else { |
|
|
} else { |
|
|
setTime(moment(selectedDate)); |
|
|
setTime(moment(selectedDate)); |
|
|
props.onTimeChange(selectedDate); |
|
|
props.onTimeChange(selectedDate); |
|
|
setShow(false); |
|
|
setShow(false); |
|
|
setMode('date'); |
|
|
|
|
|
|
|
|
setMode("date"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -73,8 +73,7 @@ const FormDatePicker = (props) => { |
|
|
formatChosenDate={(selectedDate) => { |
|
|
formatChosenDate={(selectedDate) => { |
|
|
if (mode == "date") { |
|
|
if (mode == "date") { |
|
|
return moment(selectedDate).format("DD/MM/YYYY"); |
|
|
return moment(selectedDate).format("DD/MM/YYYY"); |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
return moment(selectedDate).format("HH:mm"); |
|
|
return moment(selectedDate).format("HH:mm"); |
|
|
} |
|
|
} |
|
|
}} //formatar a data e hora do selected date
|
|
|
}} //formatar a data e hora do selected date
|
|
@ -95,11 +94,17 @@ const FormDatePicker = (props) => { |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<View style={styles.dateIcon}> |
|
|
<View style={styles.dateIcon}> |
|
|
<MaterialCommunityIcons name="calendar-today" size={30} color="white" alignItems="center" /> |
|
|
|
|
|
|
|
|
<MaterialCommunityIcons |
|
|
|
|
|
name="calendar-today" |
|
|
|
|
|
size={30} |
|
|
|
|
|
color="white" |
|
|
|
|
|
alignItems="center" |
|
|
|
|
|
/> |
|
|
</View> |
|
|
</View> |
|
|
<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")} {"\n "} {time.format("HH:mm")} |
|
|
|
|
|
|
|
|
{" "} |
|
|
|
|
|
{date.format("DD/MM/YYYY")} {"\n "} {time.format("HH:mm")} |
|
|
</Text> |
|
|
</Text> |
|
|
</View> |
|
|
</View> |
|
|
</View> |
|
|
</View> |
|
@ -189,19 +194,19 @@ const styles = StyleSheet.create({ |
|
|
justifyContent: "center", |
|
|
justifyContent: "center", |
|
|
}, |
|
|
}, |
|
|
dateInput: { |
|
|
dateInput: { |
|
|
flex: 0.80, |
|
|
|
|
|
|
|
|
flex: 0.8, |
|
|
backgroundColor: colors.white, |
|
|
backgroundColor: colors.white, |
|
|
borderRadius: 25, |
|
|
borderRadius: 25, |
|
|
marginVertical: 10, |
|
|
marginVertical: 10, |
|
|
}, |
|
|
}, |
|
|
dateIcon: { |
|
|
dateIcon: { |
|
|
backgroundColor: colors.cerulean, |
|
|
|
|
|
|
|
|
backgroundColor: colors.primary, |
|
|
padding: 8, |
|
|
padding: 8, |
|
|
width: 20, |
|
|
width: 20, |
|
|
alignItems: "center", |
|
|
alignItems: "center", |
|
|
borderRadius: 5, |
|
|
borderRadius: 5, |
|
|
flex: 0.20, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
flex: 0.2, |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
export default FormDatePicker; |
|
|
export default FormDatePicker; |