import * as React from 'react' import { View, StyleSheet, useWindowDimensions, TextInput as TextInputNative, } from 'react-native' import { MD2Theme, 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 '../utils' import Color from 'color' function TimeInputs({ hours, minutes, onFocusInput, focused, inputType, onChange, is24Hour, inputFontSize, }: { 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 }) { const startInput = React.useRef(null) const endInput = React.useRef(null) const dimensions = useWindowDimensions() const isLandscape = dimensions.width > dimensions.height const theme = useTheme() const onSubmitStartInput = React.useCallback(() => { if (endInput.current) { endInput.current.focus() } }, [endInput]) const onSubmitEndInput = React.useCallback(() => { // TODO: close modal and persist time }, []) const minutesRef = useLatest(minutes) const onChangeHours = React.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' ? ( Hour ) : null} { let newMinutes = newMinutesFromInput if (newMinutesFromInput > 59) { newMinutes = 59 } onChange({ hours, minutes: newMinutes, }) }} /> {inputType === 'keyboard' ? ( Minute ) : null} {!is24Hour && ( <> )} ) } const styles = StyleSheet.create({ column: { flexDirection: 'column', }, spaceBetweenInputsAndSwitcher: { width: 12 }, inputContainer: { flexDirection: 'row', alignItems: 'center', }, inputContainerLandscape: { flex: 1, }, hoursAndMinutesSeparator: { fontSize: 65, width: 24, alignItems: 'center', }, spaceDot: { flex: 1, }, dot: { width: 7, height: 7, borderRadius: 7 / 2, }, betweenDot: { height: 12, }, }) export default React.memo(TimeInputs)