import { MaterialCommunityIcons } from "@expo/vector-icons"; import DateTimePicker, { AndroidNativeProps, DateTimePickerAndroid, DateTimePickerEvent, } from "@react-native-community/datetimepicker"; import React, { useState } from "react"; import { Modal, Platform, Text, TouchableOpacity, View, } from "react-native"; import MyText from "./text"; import { useTheme, tw } from "common-ui"; interface Props { value: Date | null; setValue: (date: Date | null) => void; showLabel?: boolean; // Optional prop to control label visibility placeholder?: string; // Optional custom placeholder } function DatePicker(props: Props) { const { value, setValue, showLabel = true, placeholder = "Select Date" } = props; const [show, setShow] = useState(false); const { theme } = useTheme(); const onChange = (event: DateTimePickerEvent, selectedDate?: Date) => { const currentDate = selectedDate || value; if (Platform.OS === "ios") setShow(false); setValue(currentDate); }; const showDatepicker = () => { if (Platform.OS === "android") { DateTimePickerAndroid.open({ value: value || new Date(), onChange: onChange, mode: "date", is24Hour: true, display: "default", } as AndroidNativeProps); } else { setShow(true); } }; return ( {showLabel && {placeholder}} {value?.toLocaleDateString() || placeholder} {/* Conditional rendering for iOS, as it uses the declarative API */} {show && Platform.OS === "ios" && ( setShow(false)} > setShow(false)} style={tw`mt-2.5 bg-blue-500 rounded py-2.5 items-center`} > Done )} ); } export default DatePicker;