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