import { StyleSheet, TextInput as TextInputNative, useWindowDimensions, View, } from 'react-native' import { Text, useTheme } from 'react-native-paper' import { clockTypes, PossibleClockTypes, PossibleInputTypes, toHourInputFormat, toHourOutputFormat, } from './timeUtils' import TimeInput from './TimeInput' import AmPmSwitcher from './AmPmSwitcher' import { useLatest } from '../shared/utils' import Color from 'color' import { getTranslation } from '../translations/utils' import { memo, useCallback, useRef } from 'react' import { sharedStyles } from '../shared/styles' function TimeInputs({ hours, minutes, onFocusInput, focused, inputType, onChange, is24Hour, inputFontSize, locale, }: { inputType: PossibleInputTypes focused: PossibleClockTypes hours: number minutes: number onFocusInput: (type: PossibleClockTypes) => any onChange: (hoursMinutesAndFocused: { hours: number minutes: number focused?: undefined | PossibleClockTypes }) => any is24Hour: boolean inputFontSize?: number locale?: string }) { const theme = useTheme() const startInput = useRef(null) const endInput = useRef(null) const dimensions = useWindowDimensions() const isLandscape = dimensions.width > dimensions.height const minutesRef = useLatest(minutes) const onSubmitStartInput = useCallback(() => { if (endInput.current) { endInput.current.focus() } }, [endInput]) const onSubmitEndInput = useCallback(() => { // TODO: close modal and persist time }, []) const onChangeHours = useCallback( (newHours: number) => { onChange({ hours: newHours, minutes: minutesRef.current, focused: clockTypes.hours, }) }, [onChange, minutesRef] ) return ( { let newHours = toHourOutputFormat( newHoursFromInput, hours, is24Hour ) if (newHoursFromInput > 24) { newHours = 24 } onChange({ hours: newHours, minutes, }) }} /> {inputType === 'keyboard' ? ( {getTranslation(locale, 'hour', 'Hour')} ) : null} { let newMinutes = newMinutesFromInput if (newMinutesFromInput > 59) { newMinutes = 59 } onChange({ hours, minutes: newMinutes, }) }} /> {inputType === 'keyboard' ? ( {getTranslation(locale, 'minute', 'Minute')} ) : null} {!is24Hour && ( <> )} ) } const styles = StyleSheet.create({ betweenDot: { height: 12, }, column: { flexDirection: 'column', }, dot: { width: 7, height: 7, borderRadius: 7 / 2, }, hoursAndMinutesSeparator: { fontSize: 65, width: 24, alignItems: 'center', }, inputContainer: { flexDirection: 'row', alignItems: 'center', }, spaceBetweenInputsAndSwitcher: { width: 12, }, }) export default memo(TimeInputs)