@izonnet-web-solution/react-native-date-time-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.
Files changed (216) hide show
  1. package/DateTimePickerKit.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +532 -2
  4. package/android/build.gradle +36 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
  7. package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
  8. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
  9. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
  10. package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
  11. package/ios/DateTimePickerKit.h +11 -0
  12. package/ios/DateTimePickerKit.mm +84 -0
  13. package/ios/DateTimePickerModule.swift +474 -0
  14. package/lib/module/NativeDateTimePickerKit.js +5 -0
  15. package/lib/module/NativeDateTimePickerKit.js.map +1 -0
  16. package/lib/module/components/CalendarPicker.js +414 -0
  17. package/lib/module/components/CalendarPicker.js.map +1 -0
  18. package/lib/module/components/ClockPicker.js +273 -0
  19. package/lib/module/components/ClockPicker.js.map +1 -0
  20. package/lib/module/components/DatePicker.js +174 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +154 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +598 -0
  25. package/lib/module/components/DateTimePicker.js.map +1 -0
  26. package/lib/module/components/MonthPicker.js +145 -0
  27. package/lib/module/components/MonthPicker.js.map +1 -0
  28. package/lib/module/components/TimePicker.js +140 -0
  29. package/lib/module/components/TimePicker.js.map +1 -0
  30. package/lib/module/components/TimeSlotPicker.js +118 -0
  31. package/lib/module/components/TimeSlotPicker.js.map +1 -0
  32. package/lib/module/components/WheelPicker.js +138 -0
  33. package/lib/module/components/WheelPicker.js.map +1 -0
  34. package/lib/module/components/YearPicker.js +151 -0
  35. package/lib/module/components/YearPicker.js.map +1 -0
  36. package/lib/module/components/common/ModalWrapper.js +130 -0
  37. package/lib/module/components/common/ModalWrapper.js.map +1 -0
  38. package/lib/module/components/common/PickerHeader.js +82 -0
  39. package/lib/module/components/common/PickerHeader.js.map +1 -0
  40. package/lib/module/components/common/PresetsBar.js +66 -0
  41. package/lib/module/components/common/PresetsBar.js.map +1 -0
  42. package/lib/module/errors/DateTimePickerError.js +12 -0
  43. package/lib/module/errors/DateTimePickerError.js.map +1 -0
  44. package/lib/module/hooks/useDateTimePicker.js +73 -0
  45. package/lib/module/hooks/useDateTimePicker.js.map +1 -0
  46. package/lib/module/index.js +40 -0
  47. package/lib/module/index.js.map +1 -0
  48. package/lib/module/localization/index.js +6 -0
  49. package/lib/module/localization/index.js.map +1 -0
  50. package/lib/module/localization/locales.js +186 -0
  51. package/lib/module/localization/locales.js.map +1 -0
  52. package/lib/module/localization/types.js +2 -0
  53. package/lib/module/localization/types.js.map +1 -0
  54. package/lib/module/localization/useLocale.js +126 -0
  55. package/lib/module/localization/useLocale.js.map +1 -0
  56. package/lib/module/native/NativeDateTimePicker.js +110 -0
  57. package/lib/module/native/NativeDateTimePicker.js.map +1 -0
  58. package/lib/module/package.json +1 -0
  59. package/lib/module/presets/datePresets.js +75 -0
  60. package/lib/module/presets/datePresets.js.map +1 -0
  61. package/lib/module/presets/index.js +4 -0
  62. package/lib/module/presets/index.js.map +1 -0
  63. package/lib/module/slots/index.js +4 -0
  64. package/lib/module/slots/index.js.map +1 -0
  65. package/lib/module/slots/timeSlots.js +59 -0
  66. package/lib/module/slots/timeSlots.js.map +1 -0
  67. package/lib/module/theme/defaultTheme.js +91 -0
  68. package/lib/module/theme/defaultTheme.js.map +1 -0
  69. package/lib/module/theme/index.js +6 -0
  70. package/lib/module/theme/index.js.map +1 -0
  71. package/lib/module/theme/types.js +2 -0
  72. package/lib/module/theme/types.js.map +1 -0
  73. package/lib/module/theme/useTheme.js +59 -0
  74. package/lib/module/theme/useTheme.js.map +1 -0
  75. package/lib/module/types/events.js +4 -0
  76. package/lib/module/types/events.js.map +1 -0
  77. package/lib/module/types/index.js +7 -0
  78. package/lib/module/types/index.js.map +1 -0
  79. package/lib/module/types/native.js +2 -0
  80. package/lib/module/types/native.js.map +1 -0
  81. package/lib/module/types/presentation.js +2 -0
  82. package/lib/module/types/presentation.js.map +1 -0
  83. package/lib/module/types/props.js +4 -0
  84. package/lib/module/types/props.js.map +1 -0
  85. package/lib/module/utils/constants.js +14 -0
  86. package/lib/module/utils/constants.js.map +1 -0
  87. package/lib/module/utils/dateConversion.js +115 -0
  88. package/lib/module/utils/dateConversion.js.map +1 -0
  89. package/lib/module/utils/dateFormatting.js +102 -0
  90. package/lib/module/utils/dateFormatting.js.map +1 -0
  91. package/lib/module/utils/dateValidation.js +161 -0
  92. package/lib/module/utils/dateValidation.js.map +1 -0
  93. package/lib/module/utils/index.js +7 -0
  94. package/lib/module/utils/index.js.map +1 -0
  95. package/lib/typescript/package.json +1 -0
  96. package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
  97. package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
  98. package/lib/typescript/src/components/CalendarPicker.d.ts +35 -0
  99. package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
  100. package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
  101. package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
  102. package/lib/typescript/src/components/DatePicker.d.ts +32 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +41 -0
  105. package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
  106. package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
  107. package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
  108. package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
  109. package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
  110. package/lib/typescript/src/components/TimePicker.d.ts +25 -0
  111. package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
  112. package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
  113. package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
  114. package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
  115. package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
  116. package/lib/typescript/src/components/YearPicker.d.ts +14 -0
  117. package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
  118. package/lib/typescript/src/components/common/ModalWrapper.d.ts +10 -0
  119. package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
  120. package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
  121. package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
  122. package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
  123. package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
  124. package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
  125. package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
  127. package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +23 -0
  129. package/lib/typescript/src/index.d.ts.map +1 -0
  130. package/lib/typescript/src/localization/index.d.ts +4 -0
  131. package/lib/typescript/src/localization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/localization/locales.d.ts +12 -0
  133. package/lib/typescript/src/localization/locales.d.ts.map +1 -0
  134. package/lib/typescript/src/localization/types.d.ts +23 -0
  135. package/lib/typescript/src/localization/types.d.ts.map +1 -0
  136. package/lib/typescript/src/localization/useLocale.d.ts +31 -0
  137. package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
  138. package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
  139. package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
  140. package/lib/typescript/src/presets/datePresets.d.ts +8 -0
  141. package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
  142. package/lib/typescript/src/presets/index.d.ts +2 -0
  143. package/lib/typescript/src/presets/index.d.ts.map +1 -0
  144. package/lib/typescript/src/slots/index.d.ts +2 -0
  145. package/lib/typescript/src/slots/index.d.ts.map +1 -0
  146. package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
  147. package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
  148. package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
  149. package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
  150. package/lib/typescript/src/theme/index.d.ts +4 -0
  151. package/lib/typescript/src/theme/index.d.ts.map +1 -0
  152. package/lib/typescript/src/theme/types.d.ts +65 -0
  153. package/lib/typescript/src/theme/types.d.ts.map +1 -0
  154. package/lib/typescript/src/theme/useTheme.d.ts +4 -0
  155. package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/types/events.d.ts +8 -0
  157. package/lib/typescript/src/types/events.d.ts.map +1 -0
  158. package/lib/typescript/src/types/index.d.ts +5 -0
  159. package/lib/typescript/src/types/index.d.ts.map +1 -0
  160. package/lib/typescript/src/types/native.d.ts +26 -0
  161. package/lib/typescript/src/types/native.d.ts.map +1 -0
  162. package/lib/typescript/src/types/presentation.d.ts +19 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +68 -0
  165. package/lib/typescript/src/types/props.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/constants.d.ts +12 -0
  167. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  168. package/lib/typescript/src/utils/dateConversion.d.ts +27 -0
  169. package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
  170. package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
  171. package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
  172. package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
  173. package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
  174. package/lib/typescript/src/utils/index.d.ts +5 -0
  175. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  176. package/package.json +183 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +593 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +246 -0
  181. package/src/components/DateRangePicker.tsx +226 -0
  182. package/src/components/DateTimePicker.tsx +862 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +190 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +199 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +184 -0
  189. package/src/components/common/PickerHeader.tsx +121 -0
  190. package/src/components/common/PresetsBar.tsx +104 -0
  191. package/src/errors/DateTimePickerError.ts +29 -0
  192. package/src/hooks/useDateTimePicker.ts +100 -0
  193. package/src/index.tsx +92 -0
  194. package/src/localization/index.ts +3 -0
  195. package/src/localization/locales.ts +499 -0
  196. package/src/localization/types.ts +21 -0
  197. package/src/localization/useLocale.ts +137 -0
  198. package/src/native/NativeDateTimePicker.ts +154 -0
  199. package/src/presets/datePresets.ts +97 -0
  200. package/src/presets/index.ts +1 -0
  201. package/src/slots/index.ts +1 -0
  202. package/src/slots/timeSlots.ts +89 -0
  203. package/src/theme/defaultTheme.ts +102 -0
  204. package/src/theme/index.ts +3 -0
  205. package/src/theme/types.ts +70 -0
  206. package/src/theme/useTheme.ts +75 -0
  207. package/src/types/events.ts +8 -0
  208. package/src/types/index.ts +4 -0
  209. package/src/types/native.ts +28 -0
  210. package/src/types/presentation.ts +21 -0
  211. package/src/types/props.ts +104 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +127 -0
  214. package/src/utils/dateFormatting.ts +166 -0
  215. package/src/utils/dateValidation.ts +178 -0
  216. package/src/utils/index.ts +4 -0
@@ -0,0 +1,185 @@
1
+ package com.datetimepickerkit
2
+
3
+ import android.app.DatePickerDialog
4
+ import android.content.Context
5
+ import android.os.Build
6
+ import android.widget.DatePicker
7
+ import com.facebook.react.bridge.Arguments
8
+ import com.facebook.react.bridge.Promise
9
+ import com.facebook.react.bridge.ReadableMap
10
+ import com.facebook.react.bridge.WritableMap
11
+ import java.util.Calendar
12
+ import java.util.Locale
13
+ import java.util.TimeZone
14
+
15
+ class DatePickerHelper(
16
+ private val context: Context,
17
+ private val options: ReadableMap,
18
+ private val promise: Promise,
19
+ private val onDismissCallback: () -> Unit
20
+ ) {
21
+ private var isHandled = false
22
+ private var datePickerDialog: DatePickerDialog? = null
23
+ private val calendar = Calendar.getInstance()
24
+
25
+ fun show(): DatePickerDialog {
26
+ val initialTimestamp = if (options.hasKey("value") && !options.isNull("value")) {
27
+ options.getDouble("value").toLong()
28
+ } else {
29
+ System.currentTimeMillis()
30
+ }
31
+
32
+ if (options.hasKey("timeZoneOffsetInMinutes") && !options.isNull("timeZoneOffsetInMinutes")) {
33
+ val offsetMinutes = options.getInt("timeZoneOffsetInMinutes")
34
+ val sign = if (offsetMinutes < 0) "-" else "+"
35
+ val absOffset = Math.abs(offsetMinutes)
36
+ val hours = absOffset / 60
37
+ val minutes = absOffset % 60
38
+ val tz = TimeZone.getTimeZone(String.format(Locale.US, "GMT%s%02d:%02d", sign, hours, minutes))
39
+ calendar.timeZone = tz
40
+ }
41
+
42
+ calendar.timeInMillis = initialTimestamp
43
+
44
+ val year = calendar.get(Calendar.YEAR)
45
+ val month = calendar.get(Calendar.MONTH)
46
+ val day = calendar.get(Calendar.DAY_OF_MONTH)
47
+
48
+ val display = if (options.hasKey("display") && !options.isNull("display")) {
49
+ options.getString("display")
50
+ } else {
51
+ "default"
52
+ }
53
+
54
+ // Determine theme based on display or theme options
55
+ val themeId = when (display) {
56
+ "spinner" -> android.R.style.Theme_DeviceDefault_Dialog_Alert
57
+ else -> 0 // default dialog theme
58
+ }
59
+
60
+ val dialog = if (themeId != 0) {
61
+ DatePickerDialog(context, themeId, { _: DatePicker, selectedYear: Int, selectedMonth: Int, selectedDay: Int ->
62
+ if (!isHandled) {
63
+ isHandled = true
64
+ calendar.set(Calendar.YEAR, selectedYear)
65
+ calendar.set(Calendar.MONTH, selectedMonth)
66
+ calendar.set(Calendar.DAY_OF_MONTH, selectedDay)
67
+ resolveSuccess("confirmed", calendar.timeInMillis)
68
+ }
69
+ }, year, month, day)
70
+ } else {
71
+ DatePickerDialog(context, { _: DatePicker, selectedYear: Int, selectedMonth: Int, selectedDay: Int ->
72
+ if (!isHandled) {
73
+ isHandled = true
74
+ calendar.set(Calendar.YEAR, selectedYear)
75
+ calendar.set(Calendar.MONTH, selectedMonth)
76
+ calendar.set(Calendar.DAY_OF_MONTH, selectedDay)
77
+ resolveSuccess("confirmed", calendar.timeInMillis)
78
+ }
79
+ }, year, month, day)
80
+ }
81
+
82
+ val datePicker = dialog.datePicker
83
+
84
+ // Minimum date
85
+ if (options.hasKey("minimumDate") && !options.isNull("minimumDate")) {
86
+ val minDate = options.getDouble("minimumDate").toLong()
87
+ datePicker.minDate = minDate
88
+ }
89
+
90
+ // Maximum date
91
+ if (options.hasKey("maximumDate") && !options.isNull("maximumDate")) {
92
+ val maxDate = options.getDouble("maximumDate").toLong()
93
+ datePicker.maxDate = maxDate
94
+ }
95
+
96
+ // Custom title
97
+ if (options.hasKey("title") && !options.isNull("title")) {
98
+ val title = options.getString("title")
99
+ if (!title.isNullOrEmpty()) {
100
+ dialog.setTitle(title)
101
+ }
102
+ }
103
+
104
+ // Custom button labels
105
+ if (options.hasKey("confirmText") && !options.isNull("confirmText")) {
106
+ val confirmText = options.getString("confirmText")
107
+ if (!confirmText.isNullOrEmpty()) {
108
+ dialog.setButton(DatePickerDialog.BUTTON_POSITIVE, confirmText, dialog)
109
+ }
110
+ }
111
+
112
+ if (options.hasKey("cancelText") && !options.isNull("cancelText")) {
113
+ val cancelText = options.getString("cancelText")
114
+ if (!cancelText.isNullOrEmpty()) {
115
+ dialog.setButton(DatePickerDialog.BUTTON_NEGATIVE, cancelText, dialog)
116
+ }
117
+ }
118
+
119
+ dialog.setOnCancelListener {
120
+ if (!isHandled) {
121
+ isHandled = true
122
+ resolveSuccess("cancelled", initialTimestamp)
123
+ }
124
+ }
125
+
126
+ dialog.setOnDismissListener {
127
+ onDismissCallback()
128
+ if (!isHandled) {
129
+ isHandled = true
130
+ resolveSuccess("dismissed", initialTimestamp)
131
+ }
132
+ }
133
+
134
+ datePickerDialog = dialog
135
+ dialog.show()
136
+ return dialog
137
+ }
138
+
139
+ fun updateSelectedDate(timestamp: Long) {
140
+ calendar.timeInMillis = timestamp
141
+ datePickerDialog?.datePicker?.updateDate(
142
+ calendar.get(Calendar.YEAR),
143
+ calendar.get(Calendar.MONTH),
144
+ calendar.get(Calendar.DAY_OF_MONTH)
145
+ )
146
+ }
147
+
148
+ fun confirmAndDismiss(): Long {
149
+ val ts = getSelectedTimestamp()
150
+ if (!isHandled) {
151
+ isHandled = true
152
+ datePickerDialog?.dismiss()
153
+ resolveSuccess("confirmed", ts)
154
+ } else {
155
+ datePickerDialog?.dismiss()
156
+ }
157
+ return ts
158
+ }
159
+
160
+ fun cancelAndDismiss() {
161
+ if (!isHandled) {
162
+ isHandled = true
163
+ datePickerDialog?.cancel()
164
+ resolveSuccess("cancelled", initialTimestamp)
165
+ } else {
166
+ datePickerDialog?.cancel()
167
+ }
168
+ }
169
+
170
+ fun getSelectedTimestamp(): Long {
171
+ datePickerDialog?.datePicker?.let { dp ->
172
+ val cal = Calendar.getInstance()
173
+ cal.set(dp.year, dp.month, dp.dayOfMonth, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND))
174
+ return cal.timeInMillis
175
+ }
176
+ return calendar.timeInMillis
177
+ }
178
+
179
+ private fun resolveSuccess(action: String, timestamp: Long) {
180
+ val map: WritableMap = Arguments.createMap()
181
+ map.putString("action", action)
182
+ map.putDouble("timestamp", timestamp.toDouble())
183
+ promise.resolve(map)
184
+ }
185
+ }
@@ -0,0 +1,214 @@
1
+ package com.datetimepickerkit
2
+
3
+ import android.app.DatePickerDialog
4
+ import android.app.Dialog
5
+ import android.app.TimePickerDialog
6
+ import android.content.Context
7
+ import android.text.format.DateFormat
8
+ import android.widget.DatePicker
9
+ import android.widget.TimePicker
10
+ import com.facebook.react.bridge.Arguments
11
+ import com.facebook.react.bridge.Promise
12
+ import com.facebook.react.bridge.ReadableMap
13
+ import com.facebook.react.bridge.WritableMap
14
+ import java.util.Calendar
15
+ import java.util.Locale
16
+ import java.util.TimeZone
17
+
18
+ class DateTimePickerHelper(
19
+ private val context: Context,
20
+ private val options: ReadableMap,
21
+ private val promise: Promise,
22
+ private val onDismissCallback: () -> Unit
23
+ ) {
24
+ private var isHandled = false
25
+ private var isTransitioningToTime = false
26
+ private var currentDialog: Dialog? = null
27
+ private val calendar = Calendar.getInstance()
28
+ private val initialTimestamp: Long
29
+
30
+ init {
31
+ initialTimestamp = if (options.hasKey("value") && !options.isNull("value")) {
32
+ options.getDouble("value").toLong()
33
+ } else {
34
+ System.currentTimeMillis()
35
+ }
36
+
37
+ if (options.hasKey("timeZoneOffsetInMinutes") && !options.isNull("timeZoneOffsetInMinutes")) {
38
+ val offsetMinutes = options.getInt("timeZoneOffsetInMinutes")
39
+ val sign = if (offsetMinutes < 0) "-" else "+"
40
+ val absOffset = Math.abs(offsetMinutes)
41
+ val hours = absOffset / 60
42
+ val minutes = absOffset % 60
43
+ val tz = TimeZone.getTimeZone(String.format(Locale.US, "GMT%s%02d:%02d", sign, hours, minutes))
44
+ calendar.timeZone = tz
45
+ }
46
+
47
+ calendar.timeInMillis = initialTimestamp
48
+ }
49
+
50
+ fun show(): Dialog {
51
+ showDateStep()
52
+ return currentDialog!!
53
+ }
54
+
55
+ private fun showDateStep() {
56
+ val year = calendar.get(Calendar.YEAR)
57
+ val month = calendar.get(Calendar.MONTH)
58
+ val day = calendar.get(Calendar.DAY_OF_MONTH)
59
+
60
+ val dateDialog = DatePickerDialog(context, { _: DatePicker, selectedYear: Int, selectedMonth: Int, selectedDay: Int ->
61
+ calendar.set(Calendar.YEAR, selectedYear)
62
+ calendar.set(Calendar.MONTH, selectedMonth)
63
+ calendar.set(Calendar.DAY_OF_MONTH, selectedDay)
64
+ isTransitioningToTime = true
65
+ showTimeStep()
66
+ }, year, month, day)
67
+
68
+ if (options.hasKey("minimumDate") && !options.isNull("minimumDate")) {
69
+ dateDialog.datePicker.minDate = options.getDouble("minimumDate").toLong()
70
+ }
71
+
72
+ if (options.hasKey("maximumDate") && !options.isNull("maximumDate")) {
73
+ dateDialog.datePicker.maxDate = options.getDouble("maximumDate").toLong()
74
+ }
75
+
76
+ val title = if (options.hasKey("title") && !options.isNull("title")) {
77
+ options.getString("title")
78
+ } else {
79
+ "Select Date"
80
+ }
81
+ if (!title.isNullOrEmpty()) {
82
+ dateDialog.setTitle(title)
83
+ }
84
+
85
+ dateDialog.setOnCancelListener {
86
+ if (!isHandled) {
87
+ isHandled = true
88
+ resolveSuccess("cancelled", initialTimestamp)
89
+ }
90
+ }
91
+
92
+ dateDialog.setOnDismissListener {
93
+ if (!isTransitioningToTime) {
94
+ onDismissCallback()
95
+ if (!isHandled) {
96
+ isHandled = true
97
+ resolveSuccess("dismissed", initialTimestamp)
98
+ }
99
+ }
100
+ }
101
+
102
+ currentDialog = dateDialog
103
+ dateDialog.show()
104
+ }
105
+
106
+ private fun showTimeStep() {
107
+ isTransitioningToTime = false
108
+
109
+ val hour = calendar.get(Calendar.HOUR_OF_DAY)
110
+ val minute = calendar.get(Calendar.MINUTE)
111
+
112
+ val minuteInterval = if (options.hasKey("minuteInterval") && !options.isNull("minuteInterval")) {
113
+ options.getInt("minuteInterval")
114
+ } else {
115
+ 1
116
+ }
117
+
118
+ val is24Hour = if (options.hasKey("is24Hour") && !options.isNull("is24Hour")) {
119
+ options.getBoolean("is24Hour")
120
+ } else {
121
+ DateFormat.is24HourFormat(context)
122
+ }
123
+
124
+ val timeDialog = TimePickerDialog(context, { _: TimePicker, hourOfDay: Int, minuteOfHour: Int ->
125
+ if (!isHandled) {
126
+ isHandled = true
127
+ val snappedMinute = snapMinute(minuteOfHour, minuteInterval)
128
+ calendar.set(Calendar.HOUR_OF_DAY, hourOfDay)
129
+ calendar.set(Calendar.MINUTE, snappedMinute)
130
+ calendar.set(Calendar.SECOND, 0)
131
+ calendar.set(Calendar.MILLISECOND, 0)
132
+ resolveSuccess("confirmed", calendar.timeInMillis)
133
+ }
134
+ }, hour, minute, is24Hour)
135
+
136
+ timeDialog.setTitle("Select Time")
137
+
138
+ timeDialog.setOnCancelListener {
139
+ if (!isHandled) {
140
+ isHandled = true
141
+ resolveSuccess("cancelled", initialTimestamp)
142
+ }
143
+ }
144
+
145
+ timeDialog.setOnDismissListener {
146
+ onDismissCallback()
147
+ if (!isHandled) {
148
+ isHandled = true
149
+ resolveSuccess("dismissed", initialTimestamp)
150
+ }
151
+ }
152
+
153
+ currentDialog = timeDialog
154
+ timeDialog.show()
155
+ }
156
+
157
+ fun confirmAndDismiss(): Long {
158
+ val ts = getSelectedTimestamp()
159
+ if (!isHandled) {
160
+ isHandled = true
161
+ currentDialog?.dismiss()
162
+ currentDialog = null
163
+ resolveSuccess("confirmed", ts)
164
+ } else {
165
+ currentDialog?.dismiss()
166
+ currentDialog = null
167
+ }
168
+ return ts
169
+ }
170
+
171
+ fun cancelAndDismiss() {
172
+ if (!isHandled) {
173
+ isHandled = true
174
+ currentDialog?.cancel()
175
+ currentDialog = null
176
+ resolveSuccess("cancelled", initialTimestamp)
177
+ } else {
178
+ currentDialog?.cancel()
179
+ currentDialog = null
180
+ }
181
+ }
182
+
183
+ fun updateSelectedDate(timestamp: Long) {
184
+ calendar.timeInMillis = timestamp
185
+ }
186
+
187
+ fun getSelectedTimestamp(): Long {
188
+ return calendar.timeInMillis
189
+ }
190
+
191
+ fun dismissCurrentDialog() {
192
+ currentDialog?.dismiss()
193
+ currentDialog = null
194
+ }
195
+
196
+ private fun snapMinute(minute: Int, interval: Int): Int {
197
+ if (interval <= 1) return minute
198
+ val remainder = minute % interval
199
+ return if (remainder == 0) {
200
+ minute
201
+ } else if (remainder >= interval / 2) {
202
+ (minute + (interval - remainder)).coerceAtMost(59)
203
+ } else {
204
+ minute - remainder
205
+ }
206
+ }
207
+
208
+ private fun resolveSuccess(action: String, timestamp: Long) {
209
+ val map: WritableMap = Arguments.createMap()
210
+ map.putString("action", action)
211
+ map.putDouble("timestamp", timestamp.toDouble())
212
+ promise.resolve(map)
213
+ }
214
+ }
@@ -0,0 +1,258 @@
1
+ package com.datetimepickerkit
2
+
3
+ import android.app.Dialog
4
+ import com.facebook.react.bridge.Arguments
5
+ import com.facebook.react.bridge.Promise
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.UiThreadUtil
9
+ import com.facebook.react.bridge.WritableMap
10
+
11
+ class DateTimePickerKitModule(reactContext: ReactApplicationContext) :
12
+ NativeDateTimePickerKitSpec(reactContext) {
13
+
14
+ private var activeDialog: Dialog? = null
15
+ private var activeDatePickerHelper: DatePickerHelper? = null
16
+ private var activeTimePickerHelper: TimePickerHelper? = null
17
+ private var activeDateTimePickerHelper: DateTimePickerHelper? = null
18
+ private var isPickerOpen = false
19
+ private var storedTimestamp: Long = System.currentTimeMillis()
20
+
21
+ override fun openDatePicker(options: ReadableMap, promise: Promise) {
22
+ val activity = reactApplicationContext.currentActivity
23
+ if (activity == null || activity.isFinishing || activity.isDestroyed) {
24
+ promise.reject("ACTIVITY_UNAVAILABLE", "Current activity is unavailable.")
25
+ return
26
+ }
27
+
28
+ if (isPickerOpen) {
29
+ promise.reject("PICKER_ALREADY_OPEN", "A picker dialog is already open.")
30
+ return
31
+ }
32
+
33
+ UiThreadUtil.runOnUiThread {
34
+ try {
35
+ isPickerOpen = true
36
+ val helper = DatePickerHelper(activity, options, promise) {
37
+ isPickerOpen = false
38
+ activeDialog = null
39
+ activeDatePickerHelper = null
40
+ }
41
+ activeDatePickerHelper = helper
42
+ activeDialog = helper.show()
43
+ } catch (e: Exception) {
44
+ isPickerOpen = false
45
+ activeDialog = null
46
+ activeDatePickerHelper = null
47
+ promise.reject("PRESENTATION_FAILED", e.message ?: "Failed to open date picker", e)
48
+ }
49
+ }
50
+ }
51
+
52
+ override fun openTimePicker(options: ReadableMap, promise: Promise) {
53
+ val activity = reactApplicationContext.currentActivity
54
+ if (activity == null || activity.isFinishing || activity.isDestroyed) {
55
+ promise.reject("ACTIVITY_UNAVAILABLE", "Current activity is unavailable.")
56
+ return
57
+ }
58
+
59
+ if (isPickerOpen) {
60
+ promise.reject("PICKER_ALREADY_OPEN", "A picker dialog is already open.")
61
+ return
62
+ }
63
+
64
+ UiThreadUtil.runOnUiThread {
65
+ try {
66
+ isPickerOpen = true
67
+ val helper = TimePickerHelper(activity, options, promise) {
68
+ isPickerOpen = false
69
+ activeDialog = null
70
+ activeTimePickerHelper = null
71
+ }
72
+ activeTimePickerHelper = helper
73
+ activeDialog = helper.show()
74
+ } catch (e: Exception) {
75
+ isPickerOpen = false
76
+ activeDialog = null
77
+ activeTimePickerHelper = null
78
+ promise.reject("PRESENTATION_FAILED", e.message ?: "Failed to open time picker", e)
79
+ }
80
+ }
81
+ }
82
+
83
+ override fun openDateTimePicker(options: ReadableMap, promise: Promise) {
84
+ val activity = reactApplicationContext.currentActivity
85
+ if (activity == null || activity.isFinishing || activity.isDestroyed) {
86
+ promise.reject("ACTIVITY_UNAVAILABLE", "Current activity is unavailable.")
87
+ return
88
+ }
89
+
90
+ if (isPickerOpen) {
91
+ promise.reject("PICKER_ALREADY_OPEN", "A picker dialog is already open.")
92
+ return
93
+ }
94
+
95
+ UiThreadUtil.runOnUiThread {
96
+ try {
97
+ isPickerOpen = true
98
+ val helper = DateTimePickerHelper(activity, options, promise) {
99
+ isPickerOpen = false
100
+ activeDialog = null
101
+ activeDateTimePickerHelper = null
102
+ }
103
+ activeDateTimePickerHelper = helper
104
+ activeDialog = helper.show()
105
+ } catch (e: Exception) {
106
+ isPickerOpen = false
107
+ activeDialog = null
108
+ activeDateTimePickerHelper = null
109
+ promise.reject("PRESENTATION_FAILED", e.message ?: "Failed to open datetime picker", e)
110
+ }
111
+ }
112
+ }
113
+
114
+ override fun openCountdownPicker(options: ReadableMap, promise: Promise) {
115
+ // Android SDK does not natively offer a standard countdown timer dialog
116
+ promise.reject(
117
+ "UNSUPPORTED_FEATURE",
118
+ "Countdown picker mode is not natively supported on Android."
119
+ )
120
+ }
121
+
122
+ override fun closePicker(promise: Promise) {
123
+ UiThreadUtil.runOnUiThread {
124
+ try {
125
+ if (!isPickerOpen || activeDialog == null) {
126
+ promise.resolve(false)
127
+ return@runOnUiThread
128
+ }
129
+
130
+ activeDialog?.dismiss()
131
+ activeDateTimePickerHelper?.dismissCurrentDialog()
132
+ activeDialog = null
133
+ activeDatePickerHelper = null
134
+ activeTimePickerHelper = null
135
+ activeDateTimePickerHelper = null
136
+ isPickerOpen = false
137
+ promise.resolve(true)
138
+ } catch (e: Exception) {
139
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to close picker", e)
140
+ }
141
+ }
142
+ }
143
+
144
+ override fun confirmPicker(promise: Promise) {
145
+ UiThreadUtil.runOnUiThread {
146
+ try {
147
+ if (!isPickerOpen) {
148
+ promise.reject("PICKER_NOT_OPEN", "Picker is not currently open.")
149
+ return@runOnUiThread
150
+ }
151
+
152
+ val timestamp = when {
153
+ activeDatePickerHelper != null -> activeDatePickerHelper!!.confirmAndDismiss()
154
+ activeTimePickerHelper != null -> activeTimePickerHelper!!.confirmAndDismiss()
155
+ activeDateTimePickerHelper != null -> activeDateTimePickerHelper!!.confirmAndDismiss()
156
+ else -> {
157
+ activeDialog?.dismiss()
158
+ storedTimestamp
159
+ }
160
+ }
161
+
162
+ storedTimestamp = timestamp
163
+ activeDialog = null
164
+ activeDatePickerHelper = null
165
+ activeTimePickerHelper = null
166
+ activeDateTimePickerHelper = null
167
+ isPickerOpen = false
168
+
169
+ val map: WritableMap = Arguments.createMap()
170
+ map.putString("action", "confirmed")
171
+ map.putDouble("timestamp", timestamp.toDouble())
172
+ promise.resolve(map)
173
+ } catch (e: Exception) {
174
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to confirm picker", e)
175
+ }
176
+ }
177
+ }
178
+
179
+ override fun cancelPicker(promise: Promise) {
180
+ UiThreadUtil.runOnUiThread {
181
+ try {
182
+ if (!isPickerOpen) {
183
+ promise.reject("PICKER_NOT_OPEN", "Picker is not currently open.")
184
+ return@runOnUiThread
185
+ }
186
+
187
+ when {
188
+ activeDatePickerHelper != null -> activeDatePickerHelper!!.cancelAndDismiss()
189
+ activeTimePickerHelper != null -> activeTimePickerHelper!!.cancelAndDismiss()
190
+ activeDateTimePickerHelper != null -> activeDateTimePickerHelper!!.cancelAndDismiss()
191
+ else -> activeDialog?.cancel()
192
+ }
193
+
194
+ activeDialog = null
195
+ activeDatePickerHelper = null
196
+ activeTimePickerHelper = null
197
+ activeDateTimePickerHelper = null
198
+ isPickerOpen = false
199
+ promise.resolve(true)
200
+ } catch (e: Exception) {
201
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to cancel picker", e)
202
+ }
203
+ }
204
+ }
205
+
206
+ override fun setSelectedDate(timestamp: Double, promise: Promise) {
207
+ UiThreadUtil.runOnUiThread {
208
+ try {
209
+ val longTimestamp = timestamp.toLong()
210
+ storedTimestamp = longTimestamp
211
+
212
+ activeDatePickerHelper?.updateSelectedDate(longTimestamp)
213
+ activeTimePickerHelper?.updateSelectedTime(longTimestamp)
214
+ activeDateTimePickerHelper?.updateSelectedDate(longTimestamp)
215
+
216
+ promise.resolve(true)
217
+ } catch (e: Exception) {
218
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to set selected date", e)
219
+ }
220
+ }
221
+ }
222
+
223
+ override fun getSelectedDate(promise: Promise) {
224
+ try {
225
+ val timestamp = when {
226
+ activeDatePickerHelper != null -> activeDatePickerHelper!!.getSelectedTimestamp()
227
+ activeTimePickerHelper != null -> activeTimePickerHelper!!.getSelectedTimestamp()
228
+ activeDateTimePickerHelper != null -> activeDateTimePickerHelper!!.getSelectedTimestamp()
229
+ else -> storedTimestamp
230
+ }
231
+
232
+ val map: WritableMap = Arguments.createMap()
233
+ map.putString("action", "confirmed")
234
+ map.putDouble("timestamp", timestamp.toDouble())
235
+ promise.resolve(map)
236
+ } catch (e: Exception) {
237
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to get selected date", e)
238
+ }
239
+ }
240
+
241
+ override fun resetPicker(promise: Promise) {
242
+ UiThreadUtil.runOnUiThread {
243
+ try {
244
+ storedTimestamp = System.currentTimeMillis()
245
+ activeDatePickerHelper?.updateSelectedDate(storedTimestamp)
246
+ activeTimePickerHelper?.updateSelectedTime(storedTimestamp)
247
+ activeDateTimePickerHelper?.updateSelectedDate(storedTimestamp)
248
+ promise.resolve(true)
249
+ } catch (e: Exception) {
250
+ promise.reject("UNKNOWN_ERROR", e.message ?: "Failed to reset picker", e)
251
+ }
252
+ }
253
+ }
254
+
255
+ companion object {
256
+ const val NAME = NativeDateTimePickerKitSpec.NAME
257
+ }
258
+ }
@@ -0,0 +1,30 @@
1
+ package com.datetimepickerkit
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+
9
+ class DateTimePickerKitPackage : BaseReactPackage() {
10
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
11
+ return if (name == DateTimePickerKitModule.NAME) {
12
+ DateTimePickerKitModule(reactContext)
13
+ } else {
14
+ null
15
+ }
16
+ }
17
+
18
+ override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
19
+ mapOf(
20
+ DateTimePickerKitModule.NAME to ReactModuleInfo(
21
+ name = DateTimePickerKitModule.NAME,
22
+ className = DateTimePickerKitModule.NAME,
23
+ canOverrideExistingModule = false,
24
+ needsEagerInit = false,
25
+ isCxxModule = false,
26
+ isTurboModule = true
27
+ )
28
+ )
29
+ }
30
+ }