@izonnet-web-solution/react-native-date-picker-kit 0.0.0-stage → 1.0.0
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/CHANGELOG.md +35 -0
- package/LICENSE +5 -0
- package/README.md +942 -2
- package/assets/screenshots/calendar-picker-blue.jpg +0 -0
- package/assets/screenshots/calendar-picker.jpg +0 -0
- package/assets/screenshots/datetime-picker-date.jpg +0 -0
- package/assets/screenshots/datetime-picker-time-blue.jpg +0 -0
- package/assets/screenshots/input-modal-picker.jpg +0 -0
- package/assets/screenshots/manual-entry-single.jpg +0 -0
- package/assets/screenshots/manual-entry-split.jpg +0 -0
- package/assets/screenshots/month-year-selector-modal.jpg +0 -0
- package/assets/screenshots/range-picker.jpg +0 -0
- package/assets/screenshots/time-12h-wheel.jpg +0 -0
- package/assets/screenshots/time-24h-military-blue.jpg +0 -0
- package/assets/screenshots/wheel-date-picker.jpg +0 -0
- package/lib/components/Calendar/Calendar.d.ts +35 -0
- package/lib/components/Calendar/Calendar.d.ts.map +1 -0
- package/lib/components/Calendar/Calendar.js +126 -0
- package/lib/components/Calendar/Calendar.js.map +1 -0
- package/lib/components/Calendar/CalendarGrid.d.ts +11 -0
- package/lib/components/Calendar/CalendarGrid.d.ts.map +1 -0
- package/lib/components/Calendar/CalendarGrid.js +22 -0
- package/lib/components/Calendar/CalendarGrid.js.map +1 -0
- package/lib/components/Calendar/CalendarHeader.d.ts +23 -0
- package/lib/components/Calendar/CalendarHeader.d.ts.map +1 -0
- package/lib/components/Calendar/CalendarHeader.js +62 -0
- package/lib/components/Calendar/CalendarHeader.js.map +1 -0
- package/lib/components/Calendar/DateCell.d.ts +11 -0
- package/lib/components/Calendar/DateCell.d.ts.map +1 -0
- package/lib/components/Calendar/DateCell.js +71 -0
- package/lib/components/Calendar/DateCell.js.map +1 -0
- package/lib/components/Calendar/MonthYearSelectorModal.d.ts +17 -0
- package/lib/components/Calendar/MonthYearSelectorModal.d.ts.map +1 -0
- package/lib/components/Calendar/MonthYearSelectorModal.js +253 -0
- package/lib/components/Calendar/MonthYearSelectorModal.js.map +1 -0
- package/lib/components/Calendar/WeekDays.d.ts +13 -0
- package/lib/components/Calendar/WeekDays.d.ts.map +1 -0
- package/lib/components/Calendar/WeekDays.js +34 -0
- package/lib/components/Calendar/WeekDays.js.map +1 -0
- package/lib/components/Calendar/index.d.ts +7 -0
- package/lib/components/Calendar/index.d.ts.map +1 -0
- package/lib/components/Calendar/index.js +23 -0
- package/lib/components/Calendar/index.js.map +1 -0
- package/lib/components/DatePicker.d.ts +4 -0
- package/lib/components/DatePicker.d.ts.map +1 -0
- package/lib/components/DatePicker.js +498 -0
- package/lib/components/DatePicker.js.map +1 -0
- package/lib/components/Input/CalendarPopup.d.ts +26 -0
- package/lib/components/Input/CalendarPopup.d.ts.map +1 -0
- package/lib/components/Input/CalendarPopup.js +60 -0
- package/lib/components/Input/CalendarPopup.js.map +1 -0
- package/lib/components/Input/DateInput.d.ts +29 -0
- package/lib/components/Input/DateInput.d.ts.map +1 -0
- package/lib/components/Input/DateInput.js +110 -0
- package/lib/components/Input/DateInput.js.map +1 -0
- package/lib/components/Input/index.d.ts +3 -0
- package/lib/components/Input/index.d.ts.map +1 -0
- package/lib/components/Input/index.js +19 -0
- package/lib/components/Input/index.js.map +1 -0
- package/lib/components/ManualDateInput/DateInputField.d.ts +19 -0
- package/lib/components/ManualDateInput/DateInputField.d.ts.map +1 -0
- package/lib/components/ManualDateInput/DateInputField.js +345 -0
- package/lib/components/ManualDateInput/DateInputField.js.map +1 -0
- package/lib/components/ManualDateInput/DateValidationMessage.d.ts +8 -0
- package/lib/components/ManualDateInput/DateValidationMessage.d.ts.map +1 -0
- package/lib/components/ManualDateInput/DateValidationMessage.js +45 -0
- package/lib/components/ManualDateInput/DateValidationMessage.js.map +1 -0
- package/lib/components/ManualDateInput/ManualDateInput.d.ts +19 -0
- package/lib/components/ManualDateInput/ManualDateInput.d.ts.map +1 -0
- package/lib/components/ManualDateInput/ManualDateInput.js +18 -0
- package/lib/components/ManualDateInput/ManualDateInput.js.map +1 -0
- package/lib/components/ManualDateInput/index.d.ts +4 -0
- package/lib/components/ManualDateInput/index.d.ts.map +1 -0
- package/lib/components/ManualDateInput/index.js +20 -0
- package/lib/components/ManualDateInput/index.js.map +1 -0
- package/lib/components/Range/RangeDateCell.d.ts +11 -0
- package/lib/components/Range/RangeDateCell.d.ts.map +1 -0
- package/lib/components/Range/RangeDateCell.js +107 -0
- package/lib/components/Range/RangeDateCell.js.map +1 -0
- package/lib/components/Range/RangePicker.d.ts +29 -0
- package/lib/components/Range/RangePicker.d.ts.map +1 -0
- package/lib/components/Range/RangePicker.js +261 -0
- package/lib/components/Range/RangePicker.js.map +1 -0
- package/lib/components/Range/index.d.ts +3 -0
- package/lib/components/Range/index.d.ts.map +1 -0
- package/lib/components/Range/index.js +19 -0
- package/lib/components/Range/index.js.map +1 -0
- package/lib/components/Time/ClockDial.d.ts +15 -0
- package/lib/components/Time/ClockDial.d.ts.map +1 -0
- package/lib/components/Time/ClockDial.js +347 -0
- package/lib/components/Time/ClockDial.js.map +1 -0
- package/lib/components/Time/DateTimePicker.d.ts +31 -0
- package/lib/components/Time/DateTimePicker.d.ts.map +1 -0
- package/lib/components/Time/DateTimePicker.js +197 -0
- package/lib/components/Time/DateTimePicker.js.map +1 -0
- package/lib/components/Time/TimePicker.d.ts +31 -0
- package/lib/components/Time/TimePicker.d.ts.map +1 -0
- package/lib/components/Time/TimePicker.js +550 -0
- package/lib/components/Time/TimePicker.js.map +1 -0
- package/lib/components/Time/WheelTimePicker.d.ts +27 -0
- package/lib/components/Time/WheelTimePicker.d.ts.map +1 -0
- package/lib/components/Time/WheelTimePicker.js +203 -0
- package/lib/components/Time/WheelTimePicker.js.map +1 -0
- package/lib/components/Time/index.d.ts +5 -0
- package/lib/components/Time/index.d.ts.map +1 -0
- package/lib/components/Time/index.js +21 -0
- package/lib/components/Time/index.js.map +1 -0
- package/lib/components/Wheel/WheelColumn.d.ts +17 -0
- package/lib/components/Wheel/WheelColumn.d.ts.map +1 -0
- package/lib/components/Wheel/WheelColumn.js +192 -0
- package/lib/components/Wheel/WheelColumn.js.map +1 -0
- package/lib/components/Wheel/WheelPicker.d.ts +26 -0
- package/lib/components/Wheel/WheelPicker.d.ts.map +1 -0
- package/lib/components/Wheel/WheelPicker.js +123 -0
- package/lib/components/Wheel/WheelPicker.js.map +1 -0
- package/lib/components/Wheel/index.d.ts +3 -0
- package/lib/components/Wheel/index.d.ts.map +1 -0
- package/lib/components/Wheel/index.js +19 -0
- package/lib/components/Wheel/index.js.map +1 -0
- package/lib/components/common/Button.d.ts +17 -0
- package/lib/components/common/Button.d.ts.map +1 -0
- package/lib/components/common/Button.js +77 -0
- package/lib/components/common/Button.js.map +1 -0
- package/lib/components/common/IconButton.d.ts +14 -0
- package/lib/components/common/IconButton.d.ts.map +1 -0
- package/lib/components/common/IconButton.js +150 -0
- package/lib/components/common/IconButton.js.map +1 -0
- package/lib/components/common/Modal.d.ts +13 -0
- package/lib/components/common/Modal.d.ts.map +1 -0
- package/lib/components/common/Modal.js +65 -0
- package/lib/components/common/Modal.js.map +1 -0
- package/lib/components/common/index.d.ts +4 -0
- package/lib/components/common/index.d.ts.map +1 -0
- package/lib/components/common/index.js +20 -0
- package/lib/components/common/index.js.map +1 -0
- package/lib/components/index.d.ts +9 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +25 -0
- package/lib/components/index.js.map +1 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +20 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useCalendar.d.ts +34 -0
- package/lib/hooks/useCalendar.d.ts.map +1 -0
- package/lib/hooks/useCalendar.js +93 -0
- package/lib/hooks/useCalendar.js.map +1 -0
- package/lib/hooks/useDatePicker.d.ts +28 -0
- package/lib/hooks/useDatePicker.d.ts.map +1 -0
- package/lib/hooks/useDatePicker.js +150 -0
- package/lib/hooks/useDatePicker.js.map +1 -0
- package/lib/hooks/useDateRange.d.ts +23 -0
- package/lib/hooks/useDateRange.d.ts.map +1 -0
- package/lib/hooks/useDateRange.js +82 -0
- package/lib/hooks/useDateRange.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +29 -0
- package/lib/index.js.map +1 -0
- package/lib/localization/en.d.ts +3 -0
- package/lib/localization/en.d.ts.map +1 -0
- package/lib/localization/en.js +80 -0
- package/lib/localization/en.js.map +1 -0
- package/lib/localization/gu.d.ts +3 -0
- package/lib/localization/gu.d.ts.map +1 -0
- package/lib/localization/gu.js +80 -0
- package/lib/localization/gu.js.map +1 -0
- package/lib/localization/hi.d.ts +3 -0
- package/lib/localization/hi.d.ts.map +1 -0
- package/lib/localization/hi.js +80 -0
- package/lib/localization/hi.js.map +1 -0
- package/lib/localization/index.d.ts +8 -0
- package/lib/localization/index.d.ts.map +1 -0
- package/lib/localization/index.js +32 -0
- package/lib/localization/index.js.map +1 -0
- package/lib/themes/dark.d.ts +3 -0
- package/lib/themes/dark.d.ts.map +1 -0
- package/lib/themes/dark.js +30 -0
- package/lib/themes/dark.js.map +1 -0
- package/lib/themes/index.d.ts +16 -0
- package/lib/themes/index.d.ts.map +1 -0
- package/lib/themes/index.js +56 -0
- package/lib/themes/index.js.map +1 -0
- package/lib/themes/light.d.ts +3 -0
- package/lib/themes/light.d.ts.map +1 -0
- package/lib/themes/light.js +30 -0
- package/lib/themes/light.js.map +1 -0
- package/lib/types/index.d.ts +344 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/utils/calendarUtils.d.ts +27 -0
- package/lib/utils/calendarUtils.d.ts.map +1 -0
- package/lib/utils/calendarUtils.js +108 -0
- package/lib/utils/calendarUtils.js.map +1 -0
- package/lib/utils/dateFormatting.d.ts +29 -0
- package/lib/utils/dateFormatting.d.ts.map +1 -0
- package/lib/utils/dateFormatting.js +114 -0
- package/lib/utils/dateFormatting.js.map +1 -0
- package/lib/utils/dateParsing.d.ts +23 -0
- package/lib/utils/dateParsing.d.ts.map +1 -0
- package/lib/utils/dateParsing.js +289 -0
- package/lib/utils/dateParsing.js.map +1 -0
- package/lib/utils/dateUtils.d.ts +20 -0
- package/lib/utils/dateUtils.d.ts.map +1 -0
- package/lib/utils/dateUtils.js +115 -0
- package/lib/utils/dateUtils.js.map +1 -0
- package/lib/utils/dateValidation.d.ts +36 -0
- package/lib/utils/dateValidation.d.ts.map +1 -0
- package/lib/utils/dateValidation.js +196 -0
- package/lib/utils/dateValidation.js.map +1 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +23 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/timeUtils.d.ts +78 -0
- package/lib/utils/timeUtils.d.ts.map +1 -0
- package/lib/utils/timeUtils.js +335 -0
- package/lib/utils/timeUtils.js.map +1 -0
- package/package.json +92 -3
- package/src/components/Calendar/Calendar.tsx +314 -0
- package/src/components/Calendar/CalendarGrid.tsx +47 -0
- package/src/components/Calendar/CalendarHeader.tsx +176 -0
- package/src/components/Calendar/DateCell.tsx +118 -0
- package/src/components/Calendar/MonthYearSelectorModal.tsx +407 -0
- package/src/components/Calendar/WeekDays.tsx +49 -0
- package/src/components/Calendar/index.ts +6 -0
- package/src/components/DatePicker.tsx +834 -0
- package/src/components/Input/CalendarPopup.tsx +168 -0
- package/src/components/Input/DateInput.tsx +259 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/ManualDateInput/DateInputField.tsx +493 -0
- package/src/components/ManualDateInput/DateValidationMessage.tsx +65 -0
- package/src/components/ManualDateInput/ManualDateInput.tsx +66 -0
- package/src/components/ManualDateInput/index.ts +3 -0
- package/src/components/Range/RangeDateCell.tsx +174 -0
- package/src/components/Range/RangePicker.tsx +484 -0
- package/src/components/Range/index.ts +2 -0
- package/src/components/Time/ClockDial.tsx +450 -0
- package/src/components/Time/DateTimePicker.tsx +395 -0
- package/src/components/Time/TimePicker.tsx +899 -0
- package/src/components/Time/WheelTimePicker.tsx +356 -0
- package/src/components/Time/index.ts +4 -0
- package/src/components/Wheel/WheelColumn.tsx +300 -0
- package/src/components/Wheel/WheelPicker.tsx +265 -0
- package/src/components/Wheel/index.ts +2 -0
- package/src/components/common/Button.tsx +125 -0
- package/src/components/common/IconButton.tsx +237 -0
- package/src/components/common/Modal.tsx +137 -0
- package/src/components/common/index.ts +3 -0
- package/src/components/index.ts +8 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useCalendar.ts +153 -0
- package/src/hooks/useDatePicker.ts +216 -0
- package/src/hooks/useDateRange.ts +135 -0
- package/src/index.ts +17 -0
- package/src/localization/en.ts +78 -0
- package/src/localization/gu.ts +78 -0
- package/src/localization/hi.ts +78 -0
- package/src/localization/index.ts +31 -0
- package/src/themes/dark.ts +28 -0
- package/src/themes/index.ts +73 -0
- package/src/themes/light.ts +28 -0
- package/src/types/index.ts +452 -0
- package/src/utils/calendarUtils.ts +152 -0
- package/src/utils/dateFormatting.ts +125 -0
- package/src/utils/dateParsing.ts +335 -0
- package/src/utils/dateUtils.ts +117 -0
- package/src/utils/dateValidation.ts +276 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/timeUtils.ts +416 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import React, { useMemo, useRef, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
PanResponder,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import type { DatePickerTheme, TimePeriod } from '../../types';
|
|
9
|
+
import {
|
|
10
|
+
padZero,
|
|
11
|
+
isHourDisabled,
|
|
12
|
+
isMinuteDisabled,
|
|
13
|
+
TimeValidationOptions,
|
|
14
|
+
} from '../../utils/timeUtils';
|
|
15
|
+
|
|
16
|
+
export interface ClockDialProps {
|
|
17
|
+
mode: 'hours' | 'minutes';
|
|
18
|
+
value: number; // current hours (1..12 or 0..23) or minutes (0..59)
|
|
19
|
+
is24Hour?: boolean;
|
|
20
|
+
period?: TimePeriod;
|
|
21
|
+
onSelect: (value: number) => void;
|
|
22
|
+
theme: DatePickerTheme;
|
|
23
|
+
validationOptions?: TimeValidationOptions;
|
|
24
|
+
size?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const ClockDial: React.FC<ClockDialProps> = ({
|
|
28
|
+
mode,
|
|
29
|
+
value,
|
|
30
|
+
is24Hour = false,
|
|
31
|
+
period = 'AM',
|
|
32
|
+
onSelect,
|
|
33
|
+
theme,
|
|
34
|
+
validationOptions,
|
|
35
|
+
size = 260,
|
|
36
|
+
}) => {
|
|
37
|
+
const center = size / 2;
|
|
38
|
+
const radius = size / 2 - 28;
|
|
39
|
+
const innerRadius = radius - 36; // for 24h secondary inner circle
|
|
40
|
+
|
|
41
|
+
const dialRef = useRef<View>(null);
|
|
42
|
+
const dialLayoutRef = useRef<{ pageX: number; pageY: number }>({
|
|
43
|
+
pageX: 0,
|
|
44
|
+
pageY: 0,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Keep latest props in refs for pan responder callbacks
|
|
48
|
+
const stateRef = useRef({
|
|
49
|
+
mode,
|
|
50
|
+
value,
|
|
51
|
+
is24Hour,
|
|
52
|
+
period,
|
|
53
|
+
validationOptions,
|
|
54
|
+
onSelect,
|
|
55
|
+
center,
|
|
56
|
+
radius,
|
|
57
|
+
innerRadius,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
stateRef.current = {
|
|
62
|
+
mode,
|
|
63
|
+
value,
|
|
64
|
+
is24Hour,
|
|
65
|
+
period,
|
|
66
|
+
validationOptions,
|
|
67
|
+
onSelect,
|
|
68
|
+
center,
|
|
69
|
+
radius,
|
|
70
|
+
innerRadius,
|
|
71
|
+
};
|
|
72
|
+
}, [mode, value, is24Hour, period, validationOptions, onSelect, center, radius, innerRadius]);
|
|
73
|
+
|
|
74
|
+
const updateDialPosition = () => {
|
|
75
|
+
dialRef.current?.measureInWindow((x, y) => {
|
|
76
|
+
if (x !== undefined && y !== undefined) {
|
|
77
|
+
dialLayoutRef.current = { pageX: x, pageY: y };
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Convert touch screen coordinates to selected hour or minute
|
|
83
|
+
const handleTouchCoord = (pageX: number, pageY: number) => {
|
|
84
|
+
const s = stateRef.current;
|
|
85
|
+
const { pageX: dialX, pageY: dialY } = dialLayoutRef.current;
|
|
86
|
+
const touchX = pageX - dialX;
|
|
87
|
+
const touchY = pageY - dialY;
|
|
88
|
+
const dx = touchX - s.center;
|
|
89
|
+
const dy = touchY - s.center;
|
|
90
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
91
|
+
|
|
92
|
+
if (dist < 12) return; // ignore center pivot
|
|
93
|
+
|
|
94
|
+
let angle = (Math.atan2(dy, dx) * 180) / Math.PI + 90;
|
|
95
|
+
if (angle < 0) angle += 360;
|
|
96
|
+
|
|
97
|
+
if (s.mode === 'minutes') {
|
|
98
|
+
const selectedMinute = Math.round(angle / 6) % 60;
|
|
99
|
+
if (!isMinuteDisabled(selectedMinute, s.value, s.is24Hour, s.period, s.validationOptions)) {
|
|
100
|
+
s.onSelect(selectedMinute);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
if (s.is24Hour) {
|
|
104
|
+
const isInnerTouch = dist < (s.radius + s.innerRadius) / 2;
|
|
105
|
+
let h = Math.round(angle / 30) % 12;
|
|
106
|
+
if (isInnerTouch) {
|
|
107
|
+
h = h === 0 ? 12 : h + 12;
|
|
108
|
+
}
|
|
109
|
+
if (!isHourDisabled(h, true, undefined, s.validationOptions)) {
|
|
110
|
+
s.onSelect(h);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
let h = Math.round(angle / 30) % 12;
|
|
114
|
+
if (h === 0) h = 12;
|
|
115
|
+
if (!isHourDisabled(h, false, s.period, s.validationOptions)) {
|
|
116
|
+
s.onSelect(h);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// PanResponder to track continuous drag gestures (e.g. smoothly moving from 25 to 27)
|
|
123
|
+
const panResponder = useMemo(
|
|
124
|
+
() =>
|
|
125
|
+
PanResponder.create({
|
|
126
|
+
onStartShouldSetPanResponder: () => true,
|
|
127
|
+
onMoveShouldSetPanResponder: () => true,
|
|
128
|
+
onPanResponderGrant: (evt) => {
|
|
129
|
+
const { pageX, pageY, locationX, locationY } = evt.nativeEvent;
|
|
130
|
+
if (dialLayoutRef.current.pageX === 0 && dialLayoutRef.current.pageY === 0) {
|
|
131
|
+
dialLayoutRef.current = {
|
|
132
|
+
pageX: pageX - locationX,
|
|
133
|
+
pageY: pageY - locationY,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
updateDialPosition();
|
|
137
|
+
handleTouchCoord(pageX, pageY);
|
|
138
|
+
},
|
|
139
|
+
onPanResponderMove: (evt) => {
|
|
140
|
+
handleTouchCoord(evt.nativeEvent.pageX, evt.nativeEvent.pageY);
|
|
141
|
+
},
|
|
142
|
+
onPanResponderRelease: (evt) => {
|
|
143
|
+
handleTouchCoord(evt.nativeEvent.pageX, evt.nativeEvent.pageY);
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
[]
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// Calculate clock hand angle and radius based on mode and current value
|
|
150
|
+
const { handAngleDeg, currentR } = useMemo(() => {
|
|
151
|
+
if (mode === 'hours') {
|
|
152
|
+
if (is24Hour) {
|
|
153
|
+
if (value >= 12) {
|
|
154
|
+
const idx = value - 12;
|
|
155
|
+
return { handAngleDeg: idx * 30 - 90, currentR: innerRadius };
|
|
156
|
+
} else {
|
|
157
|
+
const idx = value === 0 ? 0 : value;
|
|
158
|
+
return { handAngleDeg: idx * 30 - 90, currentR: radius };
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
const idx = value === 12 ? 0 : value;
|
|
162
|
+
return { handAngleDeg: idx * 30 - 90, currentR: radius };
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
// Minutes: 0..59, each minute is exactly 6 degrees (e.g. 25 = 60°, 27 = 72°)
|
|
166
|
+
const deg = (value % 60) * 6 - 90;
|
|
167
|
+
return { handAngleDeg: deg, currentR: radius };
|
|
168
|
+
}
|
|
169
|
+
}, [mode, value, is24Hour, innerRadius, radius]);
|
|
170
|
+
|
|
171
|
+
const handAngleRad = handAngleDeg * (Math.PI / 180);
|
|
172
|
+
const handTipX = center + currentR * Math.cos(handAngleRad);
|
|
173
|
+
const handTipY = center + currentR * Math.sin(handAngleRad);
|
|
174
|
+
|
|
175
|
+
// Numbers to display on the dial
|
|
176
|
+
const majorItems = useMemo(() => {
|
|
177
|
+
if (mode === 'hours') {
|
|
178
|
+
if (is24Hour) {
|
|
179
|
+
// Outer ring: 00..11, Inner ring: 12..23
|
|
180
|
+
const outer = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((h, i) => {
|
|
181
|
+
const actualH = h === 12 ? 0 : h;
|
|
182
|
+
const disabled = isHourDisabled(actualH, true, undefined, validationOptions);
|
|
183
|
+
return { num: actualH, label: padZero(actualH), index: i, isInner: false, disabled };
|
|
184
|
+
});
|
|
185
|
+
const inner = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23].map((h, i) => {
|
|
186
|
+
const disabled = isHourDisabled(h, true, undefined, validationOptions);
|
|
187
|
+
return { num: h, label: String(h), index: i, isInner: true, disabled };
|
|
188
|
+
});
|
|
189
|
+
return [...outer, ...inner];
|
|
190
|
+
} else {
|
|
191
|
+
// 1..12 in outer ring
|
|
192
|
+
return [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((h, i) => {
|
|
193
|
+
const disabled = isHourDisabled(h, false, period, validationOptions);
|
|
194
|
+
return { num: h, label: String(h), index: i, isInner: false, disabled };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
// Minutes: 00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
|
|
199
|
+
return [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55].map((m, i) => {
|
|
200
|
+
const disabled = isMinuteDisabled(m, value, is24Hour, period, validationOptions);
|
|
201
|
+
return { num: m, label: padZero(m), index: i, isInner: false, disabled };
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}, [mode, is24Hour, period, value, validationOptions]);
|
|
205
|
+
|
|
206
|
+
// Minute tick marks (1..59 excluding multiples of 5)
|
|
207
|
+
const minuteTicks = useMemo(() => {
|
|
208
|
+
if (mode !== 'minutes') return [];
|
|
209
|
+
const ticks = [];
|
|
210
|
+
for (let m = 0; m < 60; m++) {
|
|
211
|
+
if (m % 5 !== 0) {
|
|
212
|
+
const disabled = isMinuteDisabled(m, value, is24Hour, period, validationOptions);
|
|
213
|
+
ticks.push({
|
|
214
|
+
num: m,
|
|
215
|
+
angle: (m * 6 - 90) * (Math.PI / 180),
|
|
216
|
+
disabled,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return ticks;
|
|
221
|
+
}, [mode, value, is24Hour, period, validationOptions]);
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<View
|
|
225
|
+
ref={dialRef}
|
|
226
|
+
onLayout={() => updateDialPosition()}
|
|
227
|
+
{...panResponder.panHandlers}
|
|
228
|
+
style={[
|
|
229
|
+
styles.clockContainer,
|
|
230
|
+
{
|
|
231
|
+
width: size,
|
|
232
|
+
height: size,
|
|
233
|
+
borderRadius: size / 2,
|
|
234
|
+
backgroundColor: `${theme.primaryColor}06`,
|
|
235
|
+
borderColor: `${theme.primaryColor}22`,
|
|
236
|
+
},
|
|
237
|
+
]}
|
|
238
|
+
>
|
|
239
|
+
{/* Decorative Minute Track Ring */}
|
|
240
|
+
<View
|
|
241
|
+
pointerEvents="none"
|
|
242
|
+
style={[
|
|
243
|
+
styles.trackRing,
|
|
244
|
+
{
|
|
245
|
+
left: center - radius,
|
|
246
|
+
top: center - radius,
|
|
247
|
+
width: radius * 2,
|
|
248
|
+
height: radius * 2,
|
|
249
|
+
borderRadius: radius,
|
|
250
|
+
borderColor: `${theme.primaryColor}14`,
|
|
251
|
+
},
|
|
252
|
+
]}
|
|
253
|
+
/>
|
|
254
|
+
|
|
255
|
+
{/* 24h Inner Track Ring if applicable */}
|
|
256
|
+
{mode === 'hours' && is24Hour && (
|
|
257
|
+
<View
|
|
258
|
+
pointerEvents="none"
|
|
259
|
+
style={[
|
|
260
|
+
styles.trackRing,
|
|
261
|
+
{
|
|
262
|
+
left: center - innerRadius,
|
|
263
|
+
top: center - innerRadius,
|
|
264
|
+
width: innerRadius * 2,
|
|
265
|
+
height: innerRadius * 2,
|
|
266
|
+
borderRadius: innerRadius,
|
|
267
|
+
borderColor: `${theme.primaryColor}14`,
|
|
268
|
+
},
|
|
269
|
+
]}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
|
|
273
|
+
{/* Center Pivot Point */}
|
|
274
|
+
<View
|
|
275
|
+
pointerEvents="none"
|
|
276
|
+
style={[
|
|
277
|
+
styles.centerPivot,
|
|
278
|
+
{
|
|
279
|
+
left: center - 5,
|
|
280
|
+
top: center - 5,
|
|
281
|
+
backgroundColor: theme.primaryColor,
|
|
282
|
+
borderColor: '#FFFFFF',
|
|
283
|
+
},
|
|
284
|
+
]}
|
|
285
|
+
/>
|
|
286
|
+
|
|
287
|
+
{/* Clock Hand Pointer Line */}
|
|
288
|
+
<View
|
|
289
|
+
pointerEvents="none"
|
|
290
|
+
style={{
|
|
291
|
+
position: 'absolute',
|
|
292
|
+
left: center,
|
|
293
|
+
top: center - 1.5,
|
|
294
|
+
width: currentR,
|
|
295
|
+
height: 3,
|
|
296
|
+
backgroundColor: theme.primaryColor,
|
|
297
|
+
transformOrigin: 'left center',
|
|
298
|
+
transform: [{ rotate: `${handAngleDeg}deg` }],
|
|
299
|
+
}}
|
|
300
|
+
/>
|
|
301
|
+
|
|
302
|
+
{/* Hand Tip Highlight Bubble with Glowing Effect */}
|
|
303
|
+
<View
|
|
304
|
+
pointerEvents="none"
|
|
305
|
+
style={[
|
|
306
|
+
styles.handTipBubble,
|
|
307
|
+
{
|
|
308
|
+
left: handTipX - 17,
|
|
309
|
+
top: handTipY - 17,
|
|
310
|
+
backgroundColor: theme.primaryColor,
|
|
311
|
+
shadowColor: theme.primaryColor,
|
|
312
|
+
shadowOffset: { width: 0, height: 3 },
|
|
313
|
+
shadowOpacity: 0.45,
|
|
314
|
+
shadowRadius: 5,
|
|
315
|
+
elevation: 5,
|
|
316
|
+
},
|
|
317
|
+
]}
|
|
318
|
+
>
|
|
319
|
+
<Text style={styles.handTipText}>
|
|
320
|
+
{mode === 'minutes' ? padZero(value) : (is24Hour ? padZero(value) : String(value))}
|
|
321
|
+
</Text>
|
|
322
|
+
</View>
|
|
323
|
+
|
|
324
|
+
{/* Minute Tick Marks (pointerEvents="none" so gesture stays on main surface) */}
|
|
325
|
+
{minuteTicks.map((tick) => {
|
|
326
|
+
const tx = center + radius * Math.cos(tick.angle);
|
|
327
|
+
const ty = center + radius * Math.sin(tick.angle);
|
|
328
|
+
const isSelected = tick.num === value;
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<View
|
|
332
|
+
key={`tick-${tick.num}`}
|
|
333
|
+
pointerEvents="none"
|
|
334
|
+
style={[
|
|
335
|
+
styles.tickDot,
|
|
336
|
+
{
|
|
337
|
+
left: tx - (isSelected ? 3.5 : 1.5),
|
|
338
|
+
top: ty - (isSelected ? 3.5 : 1.5),
|
|
339
|
+
width: isSelected ? 7 : 3,
|
|
340
|
+
height: isSelected ? 7 : 3,
|
|
341
|
+
borderRadius: isSelected ? 3.5 : 1.5,
|
|
342
|
+
backgroundColor: isSelected
|
|
343
|
+
? theme.primaryColor
|
|
344
|
+
: tick.disabled
|
|
345
|
+
? `${theme.textColor}12`
|
|
346
|
+
: `${theme.textColor}35`,
|
|
347
|
+
},
|
|
348
|
+
]}
|
|
349
|
+
/>
|
|
350
|
+
);
|
|
351
|
+
})}
|
|
352
|
+
|
|
353
|
+
{/* Major Numbers (00, 05, 10... 55) */}
|
|
354
|
+
{majorItems.map((item) => {
|
|
355
|
+
const r = item.isInner ? innerRadius : radius;
|
|
356
|
+
const angle = (item.index * 30 - 90) * (Math.PI / 180);
|
|
357
|
+
const x = center + r * Math.cos(angle);
|
|
358
|
+
const y = center + r * Math.sin(angle);
|
|
359
|
+
const isSelected = item.num === value;
|
|
360
|
+
const btnSize = item.isInner ? 28 : 34;
|
|
361
|
+
|
|
362
|
+
return (
|
|
363
|
+
<View
|
|
364
|
+
key={`${item.num}-${item.isInner}`}
|
|
365
|
+
pointerEvents="none"
|
|
366
|
+
style={[
|
|
367
|
+
styles.numberNode,
|
|
368
|
+
{
|
|
369
|
+
left: x - btnSize / 2,
|
|
370
|
+
top: y - btnSize / 2,
|
|
371
|
+
width: btnSize,
|
|
372
|
+
height: btnSize,
|
|
373
|
+
borderRadius: btnSize / 2,
|
|
374
|
+
backgroundColor: isSelected ? theme.primaryColor : 'transparent',
|
|
375
|
+
opacity: item.disabled ? 0.3 : 1,
|
|
376
|
+
},
|
|
377
|
+
]}
|
|
378
|
+
>
|
|
379
|
+
<Text
|
|
380
|
+
style={[
|
|
381
|
+
styles.numberText,
|
|
382
|
+
{
|
|
383
|
+
color: isSelected
|
|
384
|
+
? '#FFFFFF'
|
|
385
|
+
: item.isInner
|
|
386
|
+
? theme.secondaryTextColor
|
|
387
|
+
: theme.textColor,
|
|
388
|
+
fontSize: item.isInner ? 11 : 13,
|
|
389
|
+
fontWeight: isSelected ? '800' : '600',
|
|
390
|
+
},
|
|
391
|
+
]}
|
|
392
|
+
>
|
|
393
|
+
{item.label}
|
|
394
|
+
</Text>
|
|
395
|
+
</View>
|
|
396
|
+
);
|
|
397
|
+
})}
|
|
398
|
+
</View>
|
|
399
|
+
);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const styles = StyleSheet.create({
|
|
403
|
+
clockContainer: {
|
|
404
|
+
borderWidth: 1.5,
|
|
405
|
+
position: 'relative',
|
|
406
|
+
alignSelf: 'center',
|
|
407
|
+
marginVertical: 12,
|
|
408
|
+
},
|
|
409
|
+
trackRing: {
|
|
410
|
+
position: 'absolute',
|
|
411
|
+
borderWidth: 1,
|
|
412
|
+
borderStyle: 'dashed',
|
|
413
|
+
},
|
|
414
|
+
centerPivot: {
|
|
415
|
+
position: 'absolute',
|
|
416
|
+
width: 10,
|
|
417
|
+
height: 10,
|
|
418
|
+
borderRadius: 5,
|
|
419
|
+
borderWidth: 1.5,
|
|
420
|
+
zIndex: 6,
|
|
421
|
+
},
|
|
422
|
+
handTipBubble: {
|
|
423
|
+
position: 'absolute',
|
|
424
|
+
width: 34,
|
|
425
|
+
height: 34,
|
|
426
|
+
borderRadius: 17,
|
|
427
|
+
justifyContent: 'center',
|
|
428
|
+
alignItems: 'center',
|
|
429
|
+
zIndex: 12,
|
|
430
|
+
},
|
|
431
|
+
handTipText: {
|
|
432
|
+
color: '#FFFFFF',
|
|
433
|
+
fontSize: 13,
|
|
434
|
+
fontWeight: '900',
|
|
435
|
+
textAlign: 'center',
|
|
436
|
+
},
|
|
437
|
+
tickDot: {
|
|
438
|
+
position: 'absolute',
|
|
439
|
+
zIndex: 8,
|
|
440
|
+
},
|
|
441
|
+
numberNode: {
|
|
442
|
+
position: 'absolute',
|
|
443
|
+
justifyContent: 'center',
|
|
444
|
+
alignItems: 'center',
|
|
445
|
+
zIndex: 10,
|
|
446
|
+
},
|
|
447
|
+
numberText: {
|
|
448
|
+
textAlign: 'center',
|
|
449
|
+
},
|
|
450
|
+
});
|