Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docusaurus/docs/time-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ The icon used to toggle between the OS input. Defaults to `keyboard-outline`. Yo
**clockIcon**
`Type: string | undefined`
The icon used to toggle between time picker and input. Defaults to `clock-outline`. You can pass the name of an icon from [MaterialCommunityIcons](https://materialdesignicons.com/).

**use24HourClock**
`Type: boolean | undefined`
Flag indicating if the time input should use the 24 hours clock. Defaults to the system clock.

**inputFontSize**
`Type: number | undefined`
Font size of the time input. Defaults to 57. Useful when using a custom font.
4 changes: 3 additions & 1 deletion src/Time/TimeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface TimeInputProps
pressed: boolean
onChanged: (n: number) => any
inputType: PossibleInputTypes
inputFontSize?: number
}

function TimeInput(
Expand All @@ -34,6 +35,7 @@ function TimeInput(
onPress,
onChanged,
inputType,
inputFontSize = 57,
...rest
}: TimeInputProps,
ref: any
Expand Down Expand Up @@ -77,6 +79,7 @@ function TimeInput(
// eslint-disable-next-line react-native/no-inline-styles
{
color,
fontSize: inputFontSize,
backgroundColor,
borderRadius: theme.roundness * 2,
borderColor:
Expand Down Expand Up @@ -123,7 +126,6 @@ function TimeInput(
const styles = StyleSheet.create({
root: { position: 'relative', height: 80, width: 96 },
input: {
fontSize: 57,
textAlign: 'center',
textAlignVertical: 'center',
width: 96,
Expand Down
4 changes: 4 additions & 0 deletions src/Time/TimeInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function TimeInputs({
inputType,
onChange,
is24Hour,
inputFontSize,
}: {
inputType: PossibleInputTypes
focused: PossibleClockTypes
Expand All @@ -39,6 +40,7 @@ function TimeInputs({
focused?: undefined | PossibleClockTypes
}) => any
is24Hour: boolean
inputFontSize?: number
}) {
const startInput = React.useRef<TextInputNative | null>(null)
const endInput = React.useRef<TextInputNative | null>(null)
Expand Down Expand Up @@ -78,6 +80,7 @@ function TimeInputs({
<View style={styles.column}>
<TimeInput
ref={startInput}
inputFontSize={inputFontSize}
placeholder={'00'}
value={toHourInputFormat(hours, is24Hour)}
clockType={clockTypes.hours}
Expand Down Expand Up @@ -145,6 +148,7 @@ function TimeInputs({
<View style={styles.column}>
<TimeInput
ref={endInput}
inputFontSize={inputFontSize}
placeholder={'00'}
value={minutes}
clockType={clockTypes.minutes}
Expand Down
10 changes: 9 additions & 1 deletion src/Time/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function TimePicker({
inputType,
onChange,
locale,
use24HourClock,
inputFontSize,
}: {
locale?: undefined | string
inputType: PossibleInputTypes
Expand All @@ -44,6 +46,8 @@ function TimePicker({
minutes: number
onFocusInput: (type: PossibleClockTypes) => any
onChange: onChangeFunc
use24HourClock?: boolean
inputFontSize?: number
}) {
const [displayMode, setDisplayMode] = React.useState<'AM' | 'PM' | undefined>(
undefined
Expand All @@ -53,14 +57,17 @@ function TimePicker({

// method to check whether we have 24 hours in clock or 12
const is24Hour = React.useMemo(() => {
if (use24HourClock !== undefined) {
return use24HourClock
}
const formatter = new Intl.DateTimeFormat(locale, {
hour: '2-digit',
minute: '2-digit',
timeZone: 'UTC',
})
const formatted = formatter.format(new Date(Date.UTC(2020, 1, 1, 23)))
return formatted.includes('23')
}, [locale])
}, [locale, use24HourClock])

// Initialize display Mode according the hours value
React.useEffect(() => {
Expand Down Expand Up @@ -104,6 +111,7 @@ function TimePicker({
>
<TimeInputs
inputType={inputType}
inputFontSize={inputFontSize}
hours={hours}
minutes={minutes}
is24Hour={is24Hour}
Expand Down
6 changes: 6 additions & 0 deletions src/Time/TimePickerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function TimePickerModal({
locale,
keyboardIcon = 'keyboard-outline',
clockIcon = 'clock-outline',
use24HourClock,
inputFontSize,
}: {
locale?: undefined | string
label?: string
Expand All @@ -69,6 +71,8 @@ export function TimePickerModal({
animationType?: 'slide' | 'fade' | 'none'
keyboardIcon?: string
clockIcon?: string
use24HourClock?: boolean
inputFontSize?: number
}) {
const theme = useTheme()

Expand Down Expand Up @@ -188,6 +192,8 @@ export function TimePickerModal({
<TimePicker
locale={locale}
inputType={inputType}
use24HourClock={use24HourClock}
inputFontSize={inputFontSize}
focused={focused}
hours={localHours}
minutes={localMinutes}
Expand Down