@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DateTimePickerKit.podspec +22 -0
- package/LICENSE +20 -0
- package/README.md +652 -2
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
- package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
- package/ios/DateTimePickerKit.h +11 -0
- package/ios/DateTimePickerKit.mm +84 -0
- package/ios/DateTimePickerModule.swift +474 -0
- package/lib/module/NativeDateTimePickerKit.js +5 -0
- package/lib/module/NativeDateTimePickerKit.js.map +1 -0
- package/lib/module/components/CalendarPicker.js +419 -0
- package/lib/module/components/CalendarPicker.js.map +1 -0
- package/lib/module/components/ClockPicker.js +273 -0
- package/lib/module/components/ClockPicker.js.map +1 -0
- package/lib/module/components/DatePicker.js +181 -0
- package/lib/module/components/DatePicker.js.map +1 -0
- package/lib/module/components/DateRangePicker.js +158 -0
- package/lib/module/components/DateRangePicker.js.map +1 -0
- package/lib/module/components/DateTimePicker.js +674 -0
- package/lib/module/components/DateTimePicker.js.map +1 -0
- package/lib/module/components/MonthPicker.js +145 -0
- package/lib/module/components/MonthPicker.js.map +1 -0
- package/lib/module/components/TimePicker.js +142 -0
- package/lib/module/components/TimePicker.js.map +1 -0
- package/lib/module/components/TimeSlotPicker.js +118 -0
- package/lib/module/components/TimeSlotPicker.js.map +1 -0
- package/lib/module/components/WheelPicker.js +159 -0
- package/lib/module/components/WheelPicker.js.map +1 -0
- package/lib/module/components/YearPicker.js +151 -0
- package/lib/module/components/YearPicker.js.map +1 -0
- package/lib/module/components/common/ModalWrapper.js +136 -0
- package/lib/module/components/common/ModalWrapper.js.map +1 -0
- package/lib/module/components/common/PickerHeader.js +82 -0
- package/lib/module/components/common/PickerHeader.js.map +1 -0
- package/lib/module/components/common/PresetsBar.js +66 -0
- package/lib/module/components/common/PresetsBar.js.map +1 -0
- package/lib/module/errors/DateTimePickerError.js +12 -0
- package/lib/module/errors/DateTimePickerError.js.map +1 -0
- package/lib/module/hooks/useDateTimePicker.js +73 -0
- package/lib/module/hooks/useDateTimePicker.js.map +1 -0
- package/lib/module/index.js +40 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/localization/index.js +6 -0
- package/lib/module/localization/index.js.map +1 -0
- package/lib/module/localization/locales.js +186 -0
- package/lib/module/localization/locales.js.map +1 -0
- package/lib/module/localization/types.js +2 -0
- package/lib/module/localization/types.js.map +1 -0
- package/lib/module/localization/useLocale.js +176 -0
- package/lib/module/localization/useLocale.js.map +1 -0
- package/lib/module/native/NativeDateTimePicker.js +110 -0
- package/lib/module/native/NativeDateTimePicker.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/presets/datePresets.js +75 -0
- package/lib/module/presets/datePresets.js.map +1 -0
- package/lib/module/presets/index.js +4 -0
- package/lib/module/presets/index.js.map +1 -0
- package/lib/module/slots/index.js +4 -0
- package/lib/module/slots/index.js.map +1 -0
- package/lib/module/slots/timeSlots.js +59 -0
- package/lib/module/slots/timeSlots.js.map +1 -0
- package/lib/module/theme/defaultTheme.js +91 -0
- package/lib/module/theme/defaultTheme.js.map +1 -0
- package/lib/module/theme/index.js +6 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/theme/types.js +2 -0
- package/lib/module/theme/types.js.map +1 -0
- package/lib/module/theme/useTheme.js +81 -0
- package/lib/module/theme/useTheme.js.map +1 -0
- package/lib/module/types/events.js +4 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/index.js +7 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/native.js +2 -0
- package/lib/module/types/native.js.map +1 -0
- package/lib/module/types/presentation.js +2 -0
- package/lib/module/types/presentation.js.map +1 -0
- package/lib/module/types/props.js +4 -0
- package/lib/module/types/props.js.map +1 -0
- package/lib/module/utils/constants.js +14 -0
- package/lib/module/utils/constants.js.map +1 -0
- package/lib/module/utils/dateConversion.js +224 -0
- package/lib/module/utils/dateConversion.js.map +1 -0
- package/lib/module/utils/dateFormatting.js +102 -0
- package/lib/module/utils/dateFormatting.js.map +1 -0
- package/lib/module/utils/dateValidation.js +161 -0
- package/lib/module/utils/dateValidation.js.map +1 -0
- package/lib/module/utils/index.js +7 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
- package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
- package/lib/typescript/src/components/CalendarPicker.d.ts +51 -0
- package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
- package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DatePicker.d.ts +44 -0
- package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts +56 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
- package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
- package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/TimePicker.d.ts +31 -0
- package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
- package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
- package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/YearPicker.d.ts +14 -0
- package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/common/ModalWrapper.d.ts +11 -0
- package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
- package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
- package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
- package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
- package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
- package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
- package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
- package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +23 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/localization/index.d.ts +4 -0
- package/lib/typescript/src/localization/index.d.ts.map +1 -0
- package/lib/typescript/src/localization/locales.d.ts +12 -0
- package/lib/typescript/src/localization/locales.d.ts.map +1 -0
- package/lib/typescript/src/localization/types.d.ts +23 -0
- package/lib/typescript/src/localization/types.d.ts.map +1 -0
- package/lib/typescript/src/localization/useLocale.d.ts +31 -0
- package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
- package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/presets/datePresets.d.ts +8 -0
- package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
- package/lib/typescript/src/presets/index.d.ts +2 -0
- package/lib/typescript/src/presets/index.d.ts.map +1 -0
- package/lib/typescript/src/slots/index.d.ts +2 -0
- package/lib/typescript/src/slots/index.d.ts.map +1 -0
- package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
- package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
- package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
- package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
- package/lib/typescript/src/theme/index.d.ts +4 -0
- package/lib/typescript/src/theme/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/types.d.ts +76 -0
- package/lib/typescript/src/theme/types.d.ts.map +1 -0
- package/lib/typescript/src/theme/useTheme.d.ts +4 -0
- package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/types/events.d.ts +8 -0
- package/lib/typescript/src/types/events.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +5 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/native.d.ts +26 -0
- package/lib/typescript/src/types/native.d.ts.map +1 -0
- package/lib/typescript/src/types/presentation.d.ts +26 -0
- package/lib/typescript/src/types/presentation.d.ts.map +1 -0
- package/lib/typescript/src/types/props.d.ts +221 -0
- package/lib/typescript/src/types/props.d.ts.map +1 -0
- package/lib/typescript/src/utils/constants.d.ts +12 -0
- package/lib/typescript/src/utils/constants.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateConversion.d.ts +46 -0
- package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
- package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
- package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +5 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +191 -4
- package/src/NativeDateTimePickerKit.ts +19 -0
- package/src/components/CalendarPicker.tsx +623 -0
- package/src/components/ClockPicker.tsx +403 -0
- package/src/components/DatePicker.tsx +276 -0
- package/src/components/DateRangePicker.tsx +251 -0
- package/src/components/DateTimePicker.tsx +1028 -0
- package/src/components/MonthPicker.tsx +216 -0
- package/src/components/TimePicker.tsx +203 -0
- package/src/components/TimeSlotPicker.tsx +163 -0
- package/src/components/WheelPicker.tsx +229 -0
- package/src/components/YearPicker.tsx +228 -0
- package/src/components/common/ModalWrapper.tsx +192 -0
- package/src/components/common/PickerHeader.tsx +121 -0
- package/src/components/common/PresetsBar.tsx +104 -0
- package/src/errors/DateTimePickerError.ts +29 -0
- package/src/hooks/useDateTimePicker.ts +100 -0
- package/src/index.tsx +92 -0
- package/src/localization/index.ts +3 -0
- package/src/localization/locales.ts +499 -0
- package/src/localization/types.ts +21 -0
- package/src/localization/useLocale.ts +197 -0
- package/src/native/NativeDateTimePicker.ts +154 -0
- package/src/presets/datePresets.ts +97 -0
- package/src/presets/index.ts +1 -0
- package/src/slots/index.ts +1 -0
- package/src/slots/timeSlots.ts +89 -0
- package/src/theme/defaultTheme.ts +102 -0
- package/src/theme/index.ts +3 -0
- package/src/theme/types.ts +82 -0
- package/src/theme/useTheme.ts +98 -0
- package/src/types/events.ts +8 -0
- package/src/types/index.ts +4 -0
- package/src/types/native.ts +28 -0
- package/src/types/presentation.ts +28 -0
- package/src/types/props.ts +291 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/dateConversion.ts +273 -0
- package/src/utils/dateFormatting.ts +166 -0
- package/src/utils/dateValidation.ts +178 -0
- package/src/utils/index.ts +4 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
5
|
+
import { DateTimePickerError } from "../errors/DateTimePickerError.js";
|
|
6
|
+
import { useLocale } from "../localization/index.js";
|
|
7
|
+
import { NativeDateTimePicker } from "../native/NativeDateTimePicker.js";
|
|
8
|
+
import { getStandardSinglePresets } from "../presets/index.js";
|
|
9
|
+
import { useTheme } from "../theme/index.js";
|
|
10
|
+
import { clampDate, clampTime, dateToTimestamp, normalizeDateWithTimezone, parseDate, timestampToDate } from "../utils/dateConversion.js";
|
|
11
|
+
import { isDateDisabled, validateDateRange, validateMinuteInterval } from "../utils/dateValidation.js";
|
|
12
|
+
import { CalendarPicker } from "./CalendarPicker.js";
|
|
13
|
+
import { ClockPicker } from "./ClockPicker.js";
|
|
14
|
+
import { ModalWrapper } from "./common/ModalWrapper.js";
|
|
15
|
+
import { PickerHeader } from "./common/PickerHeader.js";
|
|
16
|
+
import { PresetsBar } from "./common/PresetsBar.js";
|
|
17
|
+
import { WheelPicker } from "./WheelPicker.js";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export const DateTimePicker = /*#__PURE__*/forwardRef((props, ref) => {
|
|
20
|
+
const {
|
|
21
|
+
mode = 'date',
|
|
22
|
+
value: propValue,
|
|
23
|
+
defaultValue,
|
|
24
|
+
display = 'default',
|
|
25
|
+
disabled = false,
|
|
26
|
+
presentation = 'native',
|
|
27
|
+
minimumDate,
|
|
28
|
+
maximumDate,
|
|
29
|
+
minuteInterval,
|
|
30
|
+
disabledDates,
|
|
31
|
+
disabledWeekdays,
|
|
32
|
+
markedDates,
|
|
33
|
+
firstDayOfWeek,
|
|
34
|
+
locale: propLocale,
|
|
35
|
+
timeZoneOffsetInMinutes,
|
|
36
|
+
is24Hour,
|
|
37
|
+
theme: propTheme = 'auto',
|
|
38
|
+
title,
|
|
39
|
+
confirmText,
|
|
40
|
+
cancelText,
|
|
41
|
+
accentColor,
|
|
42
|
+
textColor,
|
|
43
|
+
backgroundColor,
|
|
44
|
+
showPresets = false,
|
|
45
|
+
customPresets,
|
|
46
|
+
onChange,
|
|
47
|
+
onConfirm,
|
|
48
|
+
onCancel,
|
|
49
|
+
onDismiss,
|
|
50
|
+
onOpen,
|
|
51
|
+
onError,
|
|
52
|
+
open: propOpen,
|
|
53
|
+
backdropOpacity,
|
|
54
|
+
animationType,
|
|
55
|
+
showHandle,
|
|
56
|
+
closeOnBackdropPress,
|
|
57
|
+
testID
|
|
58
|
+
} = props;
|
|
59
|
+
const effectiveMinDate = minimumDate ?? props.minDate;
|
|
60
|
+
const effectiveMaxDate = maximumDate ?? props.maxDate;
|
|
61
|
+
const effectiveTimeZone = props.timeZone ?? props.timeZoneName;
|
|
62
|
+
const effectiveOffsetMinutes = timeZoneOffsetInMinutes !== undefined ? timeZoneOffsetInMinutes : props.utcOffset !== undefined ? Math.abs(props.utcOffset) <= 14 ? props.utcOffset * 60 : props.utcOffset : undefined;
|
|
63
|
+
const effectiveOpen = propOpen !== undefined ? propOpen : props.isVisible !== undefined ? props.isVisible : props.visible !== undefined ? props.visible : undefined;
|
|
64
|
+
|
|
65
|
+
// Track internal date state with bounds clamping and timezone normalization
|
|
66
|
+
const initialDate = useMemo(() => {
|
|
67
|
+
let d = parseDate(propValue) || parseDate(defaultValue) || new Date();
|
|
68
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
69
|
+
d = normalizeDateWithTimezone(d, effectiveTimeZone, effectiveOffsetMinutes);
|
|
70
|
+
}
|
|
71
|
+
const clamped = clampDate(d, effectiveMinDate, effectiveMaxDate);
|
|
72
|
+
return clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : d;
|
|
73
|
+
}, [propValue, defaultValue, effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate]);
|
|
74
|
+
const [currentDate, setCurrentDate] = useState(initialDate);
|
|
75
|
+
const isOpenRef = useRef(false);
|
|
76
|
+
const dateRef = useRef(currentDate);
|
|
77
|
+
|
|
78
|
+
// JS modal presentation state
|
|
79
|
+
const [isJsModalVisible, setIsJsModalVisible] = useState(false);
|
|
80
|
+
const [dateTimeTab, setDateTimeTab] = useState('date');
|
|
81
|
+
const [activePresetId, setActivePresetId] = useState();
|
|
82
|
+
|
|
83
|
+
// Theme & Locale with custom overrides
|
|
84
|
+
const themeInput = useMemo(() => {
|
|
85
|
+
let base = typeof propTheme === 'object' ? {
|
|
86
|
+
...propTheme
|
|
87
|
+
} : {
|
|
88
|
+
mode: propTheme
|
|
89
|
+
};
|
|
90
|
+
if (props.themeColors) {
|
|
91
|
+
base = {
|
|
92
|
+
...base,
|
|
93
|
+
themeColors: {
|
|
94
|
+
...base.themeColors,
|
|
95
|
+
...props.themeColors
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (accentColor || textColor || backgroundColor) {
|
|
100
|
+
base = {
|
|
101
|
+
...base,
|
|
102
|
+
colors: {
|
|
103
|
+
...base.colors,
|
|
104
|
+
...(accentColor && {
|
|
105
|
+
accent: accentColor,
|
|
106
|
+
primary: accentColor,
|
|
107
|
+
selected: accentColor
|
|
108
|
+
}),
|
|
109
|
+
...(textColor && {
|
|
110
|
+
text: textColor
|
|
111
|
+
}),
|
|
112
|
+
...(backgroundColor && {
|
|
113
|
+
background: backgroundColor,
|
|
114
|
+
modalBackground: backgroundColor
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return base;
|
|
120
|
+
}, [propTheme, props.themeColors, accentColor, textColor, backgroundColor]);
|
|
121
|
+
const resolvedTheme = useTheme(themeInput);
|
|
122
|
+
const localeData = useLocale(propLocale);
|
|
123
|
+
|
|
124
|
+
// Keep dateRef synced
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
dateRef.current = currentDate;
|
|
127
|
+
}, [currentDate]);
|
|
128
|
+
|
|
129
|
+
// Update if propValue changes
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (propValue !== undefined && propValue !== null) {
|
|
132
|
+
let parsed = parseDate(propValue);
|
|
133
|
+
if (parsed) {
|
|
134
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
135
|
+
parsed = normalizeDateWithTimezone(parsed, effectiveTimeZone, effectiveOffsetMinutes);
|
|
136
|
+
}
|
|
137
|
+
const clamped = clampDate(parsed, effectiveMinDate, effectiveMaxDate);
|
|
138
|
+
const finalDate = clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : parsed;
|
|
139
|
+
setCurrentDate(finalDate);
|
|
140
|
+
dateRef.current = finalDate;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, [propValue, effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate]);
|
|
144
|
+
const buildNativeOptions = useCallback(targetDate => {
|
|
145
|
+
const minTimestamp = effectiveMinDate ? dateToTimestamp(effectiveMinDate) : undefined;
|
|
146
|
+
const maxTimestamp = effectiveMaxDate ? dateToTimestamp(effectiveMaxDate) : undefined;
|
|
147
|
+
const nativeTheme = typeof propTheme === 'string' && (propTheme === 'light' || propTheme === 'dark' || propTheme === 'auto') ? propTheme : 'auto';
|
|
148
|
+
return {
|
|
149
|
+
value: targetDate.getTime(),
|
|
150
|
+
minimumDate: minTimestamp ?? undefined,
|
|
151
|
+
maximumDate: maxTimestamp ?? undefined,
|
|
152
|
+
display,
|
|
153
|
+
locale: typeof propLocale === 'string' ? propLocale : propLocale?.code,
|
|
154
|
+
timeZoneOffsetInMinutes: effectiveOffsetMinutes,
|
|
155
|
+
is24Hour,
|
|
156
|
+
minuteInterval,
|
|
157
|
+
title,
|
|
158
|
+
confirmText,
|
|
159
|
+
cancelText,
|
|
160
|
+
theme: nativeTheme,
|
|
161
|
+
accentColor,
|
|
162
|
+
textColor,
|
|
163
|
+
backgroundColor
|
|
164
|
+
};
|
|
165
|
+
}, [effectiveMinDate, effectiveMaxDate, display, propLocale, effectiveOffsetMinutes, is24Hour, minuteInterval, title, confirmText, cancelText, propTheme, accentColor, textColor, backgroundColor]);
|
|
166
|
+
const openPicker = useCallback(async () => {
|
|
167
|
+
if (disabled) {
|
|
168
|
+
const err = new DateTimePickerError('UNKNOWN_ERROR', 'Cannot open picker: component is disabled.');
|
|
169
|
+
onError?.(err);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (minuteInterval !== undefined) {
|
|
173
|
+
if (!validateMinuteInterval(minuteInterval)) {
|
|
174
|
+
const err = new DateTimePickerError('INVALID_MINUTE_INTERVAL', `minuteInterval must be a positive integer that evenly divides 60. Received: ${minuteInterval}`);
|
|
175
|
+
onError?.(err);
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (effectiveMinDate && effectiveMaxDate) {
|
|
180
|
+
if (!validateDateRange(effectiveMinDate, effectiveMaxDate)) {
|
|
181
|
+
const err = new DateTimePickerError('DATE_OUT_OF_RANGE', 'minimumDate cannot be after maximumDate.');
|
|
182
|
+
onError?.(err);
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Presentation: JS Modal / Bottom Sheet / Fullscreen
|
|
188
|
+
if (presentation !== 'native') {
|
|
189
|
+
setIsJsModalVisible(true);
|
|
190
|
+
setDateTimeTab('date');
|
|
191
|
+
isOpenRef.current = true;
|
|
192
|
+
onOpen?.();
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Presentation: Native (TurboModule)
|
|
197
|
+
if (isOpenRef.current) {
|
|
198
|
+
const err = new DateTimePickerError('PICKER_ALREADY_OPEN', 'A native picker dialog is already active.');
|
|
199
|
+
onError?.(err);
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
isOpenRef.current = true;
|
|
203
|
+
onOpen?.();
|
|
204
|
+
const targetDate = dateRef.current;
|
|
205
|
+
const nativeOptions = buildNativeOptions(targetDate);
|
|
206
|
+
try {
|
|
207
|
+
let result;
|
|
208
|
+
switch (mode) {
|
|
209
|
+
case 'time':
|
|
210
|
+
result = await NativeDateTimePicker.openTimePicker(nativeOptions);
|
|
211
|
+
break;
|
|
212
|
+
case 'datetime':
|
|
213
|
+
result = await NativeDateTimePicker.openDateTimePicker(nativeOptions);
|
|
214
|
+
break;
|
|
215
|
+
case 'countdown':
|
|
216
|
+
result = await NativeDateTimePicker.openCountdownPicker(nativeOptions);
|
|
217
|
+
break;
|
|
218
|
+
case 'date':
|
|
219
|
+
default:
|
|
220
|
+
result = await NativeDateTimePicker.openDatePicker(nativeOptions);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
const action = result.action;
|
|
224
|
+
if (action === 'confirmed') {
|
|
225
|
+
const selectedDate = timestampToDate(result.timestamp);
|
|
226
|
+
if (isDateDisabled(selectedDate, disabledDates, disabledWeekdays)) {
|
|
227
|
+
const err = new DateTimePickerError('DATE_OUT_OF_RANGE', 'Selected date is in disabledDates or disabledWeekdays.');
|
|
228
|
+
onError?.(err);
|
|
229
|
+
}
|
|
230
|
+
setCurrentDate(selectedDate);
|
|
231
|
+
dateRef.current = selectedDate;
|
|
232
|
+
onChange?.(selectedDate);
|
|
233
|
+
onConfirm?.(selectedDate);
|
|
234
|
+
return selectedDate;
|
|
235
|
+
} else if (action === 'cancelled') {
|
|
236
|
+
onCancel?.();
|
|
237
|
+
return null;
|
|
238
|
+
} else {
|
|
239
|
+
onDismiss?.();
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
const normalized = error instanceof DateTimePickerError ? error : new DateTimePickerError('UNKNOWN_ERROR', error instanceof Error ? error.message : 'Unknown error', error);
|
|
244
|
+
onError?.(normalized);
|
|
245
|
+
throw normalized;
|
|
246
|
+
} finally {
|
|
247
|
+
isOpenRef.current = false;
|
|
248
|
+
}
|
|
249
|
+
}, [disabled, minuteInterval, effectiveMinDate, effectiveMaxDate, presentation, onOpen, buildNativeOptions, mode, disabledDates, disabledWeekdays, onChange, onConfirm, onCancel, onDismiss, onError]);
|
|
250
|
+
const closePicker = useCallback(async () => {
|
|
251
|
+
if (presentation !== 'native') {
|
|
252
|
+
setIsJsModalVisible(false);
|
|
253
|
+
isOpenRef.current = false;
|
|
254
|
+
onDismiss?.();
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
if (!isOpenRef.current) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const closed = await NativeDateTimePicker.closePicker();
|
|
262
|
+
isOpenRef.current = false;
|
|
263
|
+
onDismiss?.();
|
|
264
|
+
return closed;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
const normalized = error instanceof DateTimePickerError ? error : new DateTimePickerError('UNKNOWN_ERROR', error instanceof Error ? error.message : 'Failed to close picker', error);
|
|
267
|
+
onError?.(normalized);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}, [presentation, onDismiss, onError]);
|
|
271
|
+
const confirmProgrammatic = useCallback(async () => {
|
|
272
|
+
if (presentation !== 'native') {
|
|
273
|
+
const selectedDate = dateRef.current;
|
|
274
|
+
setIsJsModalVisible(false);
|
|
275
|
+
isOpenRef.current = false;
|
|
276
|
+
onChange?.(selectedDate);
|
|
277
|
+
onConfirm?.(selectedDate);
|
|
278
|
+
return selectedDate;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
const result = await NativeDateTimePicker.confirmPicker();
|
|
282
|
+
const selectedDate = timestampToDate(result.timestamp);
|
|
283
|
+
setCurrentDate(selectedDate);
|
|
284
|
+
dateRef.current = selectedDate;
|
|
285
|
+
isOpenRef.current = false;
|
|
286
|
+
onChange?.(selectedDate);
|
|
287
|
+
onConfirm?.(selectedDate);
|
|
288
|
+
return selectedDate;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
const normalized = error instanceof DateTimePickerError ? error : new DateTimePickerError('PICKER_NOT_OPEN', error instanceof Error ? error.message : 'Picker is not currently open to confirm', error);
|
|
291
|
+
onError?.(normalized);
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
}, [presentation, onChange, onConfirm, onError]);
|
|
295
|
+
const cancelProgrammatic = useCallback(async () => {
|
|
296
|
+
if (presentation !== 'native') {
|
|
297
|
+
setIsJsModalVisible(false);
|
|
298
|
+
isOpenRef.current = false;
|
|
299
|
+
onCancel?.();
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const cancelled = await NativeDateTimePicker.cancelPicker();
|
|
304
|
+
isOpenRef.current = false;
|
|
305
|
+
onCancel?.();
|
|
306
|
+
return cancelled;
|
|
307
|
+
} catch (error) {
|
|
308
|
+
const normalized = error instanceof DateTimePickerError ? error : new DateTimePickerError('PICKER_NOT_OPEN', error instanceof Error ? error.message : 'Picker is not currently open to cancel', error);
|
|
309
|
+
onError?.(normalized);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}, [presentation, onCancel, onError]);
|
|
313
|
+
const reset = useCallback(() => {
|
|
314
|
+
setCurrentDate(initialDate);
|
|
315
|
+
dateRef.current = initialDate;
|
|
316
|
+
setActivePresetId(undefined);
|
|
317
|
+
}, [initialDate]);
|
|
318
|
+
const getValue = useCallback(() => {
|
|
319
|
+
return dateRef.current;
|
|
320
|
+
}, []);
|
|
321
|
+
const setValue = useCallback(date => {
|
|
322
|
+
let parsed = parseDate(date);
|
|
323
|
+
if (parsed) {
|
|
324
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
325
|
+
parsed = normalizeDateWithTimezone(parsed, effectiveTimeZone, effectiveOffsetMinutes);
|
|
326
|
+
}
|
|
327
|
+
const clamped = clampDate(parsed, effectiveMinDate, effectiveMaxDate);
|
|
328
|
+
const finalDate = clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : parsed;
|
|
329
|
+
setCurrentDate(finalDate);
|
|
330
|
+
dateRef.current = finalDate;
|
|
331
|
+
}
|
|
332
|
+
}, [effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate]);
|
|
333
|
+
|
|
334
|
+
// Imperative handle
|
|
335
|
+
useImperativeHandle(ref, () => ({
|
|
336
|
+
open: openPicker,
|
|
337
|
+
close: closePicker,
|
|
338
|
+
confirm: confirmProgrammatic,
|
|
339
|
+
cancel: cancelProgrammatic,
|
|
340
|
+
reset,
|
|
341
|
+
getValue,
|
|
342
|
+
setValue
|
|
343
|
+
}), [openPicker, closePicker, confirmProgrammatic, cancelProgrammatic, reset, getValue, setValue]);
|
|
344
|
+
|
|
345
|
+
// Declarative open prop support
|
|
346
|
+
useEffect(() => {
|
|
347
|
+
if (effectiveOpen === true && !isOpenRef.current) {
|
|
348
|
+
openPicker().catch(() => {});
|
|
349
|
+
} else if (effectiveOpen === false && isOpenRef.current) {
|
|
350
|
+
closePicker().catch(() => {});
|
|
351
|
+
}
|
|
352
|
+
}, [effectiveOpen, openPicker, closePicker]);
|
|
353
|
+
|
|
354
|
+
// Presets handling
|
|
355
|
+
const presets = useMemo(() => {
|
|
356
|
+
if (!showPresets) return [];
|
|
357
|
+
return customPresets || getStandardSinglePresets();
|
|
358
|
+
}, [showPresets, customPresets]);
|
|
359
|
+
const handleSelectPreset = useCallback(preset => {
|
|
360
|
+
setActivePresetId(preset.id);
|
|
361
|
+
const val = preset.getValue();
|
|
362
|
+
if (val instanceof Date) {
|
|
363
|
+
let updated = val;
|
|
364
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
365
|
+
updated = normalizeDateWithTimezone(updated, effectiveTimeZone, effectiveOffsetMinutes);
|
|
366
|
+
}
|
|
367
|
+
const clamped = clampDate(updated, effectiveMinDate, effectiveMaxDate);
|
|
368
|
+
const finalDate = clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : updated;
|
|
369
|
+
setCurrentDate(finalDate);
|
|
370
|
+
dateRef.current = finalDate;
|
|
371
|
+
onChange?.(finalDate);
|
|
372
|
+
}
|
|
373
|
+
}, [effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate, onChange]);
|
|
374
|
+
const handleJsDateChange = useCallback(newDate => {
|
|
375
|
+
setActivePresetId(undefined);
|
|
376
|
+
let updated = newDate;
|
|
377
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
378
|
+
updated = normalizeDateWithTimezone(updated, effectiveTimeZone, effectiveOffsetMinutes);
|
|
379
|
+
}
|
|
380
|
+
const clamped = clampDate(updated, effectiveMinDate, effectiveMaxDate);
|
|
381
|
+
const finalDate = clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : updated;
|
|
382
|
+
setCurrentDate(finalDate);
|
|
383
|
+
dateRef.current = finalDate;
|
|
384
|
+
onChange?.(finalDate);
|
|
385
|
+
}, [effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate, onChange]);
|
|
386
|
+
const handleJsConfirm = useCallback(() => {
|
|
387
|
+
let finalDate = new Date(currentDate.getTime());
|
|
388
|
+
if (effectiveTimeZone || effectiveOffsetMinutes !== undefined) {
|
|
389
|
+
finalDate = normalizeDateWithTimezone(finalDate, effectiveTimeZone, effectiveOffsetMinutes);
|
|
390
|
+
}
|
|
391
|
+
const clamped = clampDate(finalDate, effectiveMinDate, effectiveMaxDate);
|
|
392
|
+
const confirmedDate = clamped ? clampTime(clamped, effectiveMinDate, effectiveMaxDate) : finalDate;
|
|
393
|
+
setIsJsModalVisible(false);
|
|
394
|
+
isOpenRef.current = false;
|
|
395
|
+
onChange?.(confirmedDate);
|
|
396
|
+
onConfirm?.(confirmedDate);
|
|
397
|
+
}, [currentDate, effectiveTimeZone, effectiveOffsetMinutes, effectiveMinDate, effectiveMaxDate, onChange, onConfirm]);
|
|
398
|
+
const handleJsCancel = useCallback(() => {
|
|
399
|
+
setIsJsModalVisible(false);
|
|
400
|
+
isOpenRef.current = false;
|
|
401
|
+
onCancel?.();
|
|
402
|
+
}, [onCancel]);
|
|
403
|
+
|
|
404
|
+
// If native, don't render JS UI (TurboModule handles presentation)
|
|
405
|
+
if (presentation === 'native') {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
const defaultHeaderTitle = title || (mode === 'time' ? localeData.selectTimeTitle : mode === 'datetime' ? localeData.selectDateTimeTitle : localeData.selectDateTitle);
|
|
409
|
+
const isModalVisible = isJsModalVisible;
|
|
410
|
+
|
|
411
|
+
// Render JS UI based on mode
|
|
412
|
+
const renderPickerBody = () => {
|
|
413
|
+
if (mode === 'time') {
|
|
414
|
+
return /*#__PURE__*/_jsx(ClockPicker, {
|
|
415
|
+
value: currentDate,
|
|
416
|
+
is24Hour: is24Hour,
|
|
417
|
+
minuteInterval: minuteInterval,
|
|
418
|
+
locale: localeData,
|
|
419
|
+
theme: resolvedTheme,
|
|
420
|
+
onChange: res => handleJsDateChange(res.date)
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (mode === 'countdown') {
|
|
424
|
+
const minutesItems = Array.from({
|
|
425
|
+
length: 60
|
|
426
|
+
}, (_, i) => ({
|
|
427
|
+
label: `${i} min`,
|
|
428
|
+
value: i
|
|
429
|
+
}));
|
|
430
|
+
return /*#__PURE__*/_jsx(View, {
|
|
431
|
+
style: styles.countdownContainer,
|
|
432
|
+
children: /*#__PURE__*/_jsx(WheelPicker, {
|
|
433
|
+
items: minutesItems,
|
|
434
|
+
selectedValue: currentDate.getMinutes(),
|
|
435
|
+
theme: resolvedTheme,
|
|
436
|
+
onChange: val => {
|
|
437
|
+
const d = new Date(currentDate);
|
|
438
|
+
d.setMinutes(val);
|
|
439
|
+
handleJsDateChange(d);
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if (mode === 'datetime') {
|
|
445
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
446
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
447
|
+
style: [styles.tabsRow, {
|
|
448
|
+
borderColor: resolvedTheme.colors.border,
|
|
449
|
+
backgroundColor: resolvedTheme.colors.card
|
|
450
|
+
}],
|
|
451
|
+
children: [/*#__PURE__*/_jsx(TouchableOpacity, {
|
|
452
|
+
onPress: () => setDateTimeTab('date'),
|
|
453
|
+
style: [styles.tabBtn, dateTimeTab === 'date' && {
|
|
454
|
+
backgroundColor: resolvedTheme.colors.primary
|
|
455
|
+
}],
|
|
456
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
457
|
+
style: [styles.tabText, {
|
|
458
|
+
color: dateTimeTab === 'date' ? resolvedTheme.colors.primaryText : resolvedTheme.colors.textSecondary,
|
|
459
|
+
fontWeight: dateTimeTab === 'date' ? 'bold' : 'normal'
|
|
460
|
+
}],
|
|
461
|
+
children: "Date"
|
|
462
|
+
})
|
|
463
|
+
}), /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
464
|
+
onPress: () => setDateTimeTab('time'),
|
|
465
|
+
style: [styles.tabBtn, dateTimeTab === 'time' && {
|
|
466
|
+
backgroundColor: resolvedTheme.colors.primary
|
|
467
|
+
}],
|
|
468
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
469
|
+
style: [styles.tabText, {
|
|
470
|
+
color: dateTimeTab === 'time' ? resolvedTheme.colors.primaryText : resolvedTheme.colors.textSecondary,
|
|
471
|
+
fontWeight: dateTimeTab === 'time' ? 'bold' : 'normal'
|
|
472
|
+
}],
|
|
473
|
+
children: "Time"
|
|
474
|
+
})
|
|
475
|
+
})]
|
|
476
|
+
}), dateTimeTab === 'date' ? /*#__PURE__*/_jsx(CalendarPicker, {
|
|
477
|
+
value: currentDate,
|
|
478
|
+
onChange: handleJsDateChange,
|
|
479
|
+
minimumDate: effectiveMinDate,
|
|
480
|
+
maximumDate: effectiveMaxDate,
|
|
481
|
+
disabledDates: disabledDates,
|
|
482
|
+
disabledWeekdays: disabledWeekdays,
|
|
483
|
+
markedDates: markedDates,
|
|
484
|
+
firstDayOfWeek: firstDayOfWeek,
|
|
485
|
+
locale: localeData,
|
|
486
|
+
theme: resolvedTheme
|
|
487
|
+
}) : /*#__PURE__*/_jsx(ClockPicker, {
|
|
488
|
+
value: currentDate,
|
|
489
|
+
is24Hour: is24Hour,
|
|
490
|
+
minuteInterval: minuteInterval,
|
|
491
|
+
locale: localeData,
|
|
492
|
+
theme: resolvedTheme,
|
|
493
|
+
onChange: res => {
|
|
494
|
+
const combined = new Date(currentDate);
|
|
495
|
+
combined.setHours(res.hour, res.minute);
|
|
496
|
+
handleJsDateChange(combined);
|
|
497
|
+
}
|
|
498
|
+
})]
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Default mode === 'date'
|
|
503
|
+
return /*#__PURE__*/_jsx(CalendarPicker, {
|
|
504
|
+
value: currentDate,
|
|
505
|
+
onChange: handleJsDateChange,
|
|
506
|
+
minimumDate: effectiveMinDate,
|
|
507
|
+
maximumDate: effectiveMaxDate,
|
|
508
|
+
disabledDates: disabledDates,
|
|
509
|
+
disabledWeekdays: disabledWeekdays,
|
|
510
|
+
markedDates: markedDates,
|
|
511
|
+
firstDayOfWeek: firstDayOfWeek,
|
|
512
|
+
locale: localeData,
|
|
513
|
+
theme: resolvedTheme
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
const content = /*#__PURE__*/_jsxs(View, {
|
|
517
|
+
style: styles.innerContent,
|
|
518
|
+
children: [presentation !== 'inline' && /*#__PURE__*/_jsx(PickerHeader, {
|
|
519
|
+
title: defaultHeaderTitle,
|
|
520
|
+
cancelText: cancelText || localeData.cancelText,
|
|
521
|
+
confirmText: confirmText || localeData.confirmText,
|
|
522
|
+
onCancel: handleJsCancel,
|
|
523
|
+
onConfirm: handleJsConfirm,
|
|
524
|
+
theme: resolvedTheme,
|
|
525
|
+
isRTL: localeData.isRTL
|
|
526
|
+
}), showPresets && presets.length > 0 && /*#__PURE__*/_jsx(PresetsBar, {
|
|
527
|
+
presets: presets,
|
|
528
|
+
activePresetId: activePresetId,
|
|
529
|
+
onSelectPreset: handleSelectPreset,
|
|
530
|
+
theme: resolvedTheme,
|
|
531
|
+
isRTL: localeData.isRTL
|
|
532
|
+
}), renderPickerBody()]
|
|
533
|
+
});
|
|
534
|
+
return /*#__PURE__*/_jsx(ModalWrapper, {
|
|
535
|
+
testID: testID,
|
|
536
|
+
presentation: presentation,
|
|
537
|
+
visible: isModalVisible,
|
|
538
|
+
onClose: handleJsCancel,
|
|
539
|
+
theme: resolvedTheme,
|
|
540
|
+
backdropOpacity: backdropOpacity,
|
|
541
|
+
animationType: animationType,
|
|
542
|
+
showHandle: showHandle,
|
|
543
|
+
closeOnBackdropPress: closeOnBackdropPress,
|
|
544
|
+
children: content
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
DateTimePicker.displayName = 'DateTimePicker';
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Imperative helper function to open the native Date Time Picker modal.
|
|
551
|
+
*/
|
|
552
|
+
export async function openDateTimePickerModal(options) {
|
|
553
|
+
const {
|
|
554
|
+
mode = 'date',
|
|
555
|
+
value = new Date(),
|
|
556
|
+
minimumDate,
|
|
557
|
+
maximumDate,
|
|
558
|
+
display = 'default',
|
|
559
|
+
locale,
|
|
560
|
+
timeZoneOffsetInMinutes,
|
|
561
|
+
is24Hour,
|
|
562
|
+
minuteInterval,
|
|
563
|
+
title,
|
|
564
|
+
confirmText,
|
|
565
|
+
cancelText,
|
|
566
|
+
theme = 'auto',
|
|
567
|
+
accentColor,
|
|
568
|
+
textColor,
|
|
569
|
+
backgroundColor,
|
|
570
|
+
disabledDates,
|
|
571
|
+
disabledWeekdays,
|
|
572
|
+
onChange,
|
|
573
|
+
onConfirm,
|
|
574
|
+
onCancel,
|
|
575
|
+
onDismiss,
|
|
576
|
+
onError
|
|
577
|
+
} = options;
|
|
578
|
+
if (minuteInterval !== undefined && !validateMinuteInterval(minuteInterval)) {
|
|
579
|
+
const err = new DateTimePickerError('INVALID_MINUTE_INTERVAL', `minuteInterval must be a positive integer dividing 60. Received: ${minuteInterval}`);
|
|
580
|
+
onError?.(err);
|
|
581
|
+
throw err;
|
|
582
|
+
}
|
|
583
|
+
if (minimumDate && maximumDate && !validateDateRange(minimumDate, maximumDate)) {
|
|
584
|
+
const err = new DateTimePickerError('DATE_OUT_OF_RANGE', 'minimumDate cannot be after maximumDate.');
|
|
585
|
+
onError?.(err);
|
|
586
|
+
throw err;
|
|
587
|
+
}
|
|
588
|
+
const parsedValue = parseDate(value) || new Date();
|
|
589
|
+
const minTimestamp = minimumDate ? dateToTimestamp(minimumDate) : undefined;
|
|
590
|
+
const maxTimestamp = maximumDate ? dateToTimestamp(maximumDate) : undefined;
|
|
591
|
+
const nativeTheme = typeof theme === 'string' && (theme === 'light' || theme === 'dark' || theme === 'auto') ? theme : 'auto';
|
|
592
|
+
const nativeOptions = {
|
|
593
|
+
value: parsedValue.getTime(),
|
|
594
|
+
minimumDate: minTimestamp ?? undefined,
|
|
595
|
+
maximumDate: maxTimestamp ?? undefined,
|
|
596
|
+
display,
|
|
597
|
+
locale: typeof locale === 'string' ? locale : locale?.code,
|
|
598
|
+
timeZoneOffsetInMinutes,
|
|
599
|
+
is24Hour,
|
|
600
|
+
minuteInterval,
|
|
601
|
+
title,
|
|
602
|
+
confirmText,
|
|
603
|
+
cancelText,
|
|
604
|
+
theme: nativeTheme,
|
|
605
|
+
accentColor,
|
|
606
|
+
textColor,
|
|
607
|
+
backgroundColor
|
|
608
|
+
};
|
|
609
|
+
try {
|
|
610
|
+
let result;
|
|
611
|
+
switch (mode) {
|
|
612
|
+
case 'time':
|
|
613
|
+
result = await NativeDateTimePicker.openTimePicker(nativeOptions);
|
|
614
|
+
break;
|
|
615
|
+
case 'datetime':
|
|
616
|
+
result = await NativeDateTimePicker.openDateTimePicker(nativeOptions);
|
|
617
|
+
break;
|
|
618
|
+
case 'countdown':
|
|
619
|
+
result = await NativeDateTimePicker.openCountdownPicker(nativeOptions);
|
|
620
|
+
break;
|
|
621
|
+
case 'date':
|
|
622
|
+
default:
|
|
623
|
+
result = await NativeDateTimePicker.openDatePicker(nativeOptions);
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
const selectedDate = timestampToDate(result.timestamp);
|
|
627
|
+
if (result.action === 'confirmed') {
|
|
628
|
+
if (isDateDisabled(selectedDate, disabledDates, disabledWeekdays)) {
|
|
629
|
+
const err = new DateTimePickerError('DATE_OUT_OF_RANGE', 'Selected date is disabled.');
|
|
630
|
+
onError?.(err);
|
|
631
|
+
}
|
|
632
|
+
onChange?.(selectedDate);
|
|
633
|
+
onConfirm?.(selectedDate);
|
|
634
|
+
return selectedDate;
|
|
635
|
+
} else if (result.action === 'cancelled') {
|
|
636
|
+
onCancel?.();
|
|
637
|
+
return null;
|
|
638
|
+
} else {
|
|
639
|
+
onDismiss?.();
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
} catch (error) {
|
|
643
|
+
const normalized = error instanceof DateTimePickerError ? error : new DateTimePickerError('UNKNOWN_ERROR', error instanceof Error ? error.message : 'Unknown error', error);
|
|
644
|
+
onError?.(normalized);
|
|
645
|
+
throw normalized;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const styles = StyleSheet.create({
|
|
649
|
+
innerContent: {
|
|
650
|
+
width: '100%'
|
|
651
|
+
},
|
|
652
|
+
countdownContainer: {
|
|
653
|
+
padding: 16
|
|
654
|
+
},
|
|
655
|
+
tabsRow: {
|
|
656
|
+
flexDirection: 'row',
|
|
657
|
+
marginHorizontal: 16,
|
|
658
|
+
marginTop: 12,
|
|
659
|
+
marginBottom: 8,
|
|
660
|
+
borderRadius: 8,
|
|
661
|
+
borderWidth: 1,
|
|
662
|
+
overflow: 'hidden'
|
|
663
|
+
},
|
|
664
|
+
tabBtn: {
|
|
665
|
+
flex: 1,
|
|
666
|
+
paddingVertical: 8,
|
|
667
|
+
alignItems: 'center',
|
|
668
|
+
justifyContent: 'center'
|
|
669
|
+
},
|
|
670
|
+
tabText: {
|
|
671
|
+
fontSize: 14
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
//# sourceMappingURL=DateTimePicker.js.map
|