import React, {useState, useCallback} from 'react' import {StyleProp, StyleSheet, TextStyle, View, ViewStyle} from 'react-native' import DateTimePicker, { DateTimePickerEvent, } from '@react-native-community/datetimepicker' import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' import {isIOS, isAndroid} from 'platform/detection' import {Button, ButtonType} from './Button' import {Text} from '../text/Text' import {TypographyVariant} from 'lib/ThemeContext' import {useTheme} from 'lib/ThemeContext' import {usePalette} from 'lib/hooks/usePalette' interface Props { testID?: string value: Date onChange: (date: Date) => void buttonType?: ButtonType buttonStyle?: StyleProp buttonLabelType?: TypographyVariant buttonLabelStyle?: StyleProp accessibilityLabel: string accessibilityHint: string accessibilityLabelledBy?: string } export function DateInput(props: Props) { const [show, setShow] = useState(false) const theme = useTheme() const pal = usePalette('default') const onChangeInternal = useCallback( (event: DateTimePickerEvent, date: Date | undefined) => { setShow(false) if (date) { props.onChange(date) } }, [setShow, props], ) const onPress = useCallback(() => { setShow(true) }, [setShow]) return ( {isAndroid && ( )} {(isIOS || show) && ( )} ) } const styles = StyleSheet.create({ button: { flexDirection: 'row', alignItems: 'center', gap: 10, }, })