@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.
- package/DateTimePickerKit.podspec +22 -0
- package/LICENSE +20 -0
- package/README.md +532 -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 +414 -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 +174 -0
- package/lib/module/components/DatePicker.js.map +1 -0
- package/lib/module/components/DateRangePicker.js +154 -0
- package/lib/module/components/DateRangePicker.js.map +1 -0
- package/lib/module/components/DateTimePicker.js +598 -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 +140 -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 +138 -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 +130 -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 +126 -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 +59 -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 +115 -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 +35 -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 +32 -0
- package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts +41 -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 +25 -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 +10 -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 +65 -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 +19 -0
- package/lib/typescript/src/types/presentation.d.ts.map +1 -0
- package/lib/typescript/src/types/props.d.ts +68 -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 +27 -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 +183 -4
- package/src/NativeDateTimePickerKit.ts +19 -0
- package/src/components/CalendarPicker.tsx +593 -0
- package/src/components/ClockPicker.tsx +403 -0
- package/src/components/DatePicker.tsx +246 -0
- package/src/components/DateRangePicker.tsx +226 -0
- package/src/components/DateTimePicker.tsx +862 -0
- package/src/components/MonthPicker.tsx +216 -0
- package/src/components/TimePicker.tsx +190 -0
- package/src/components/TimeSlotPicker.tsx +163 -0
- package/src/components/WheelPicker.tsx +199 -0
- package/src/components/YearPicker.tsx +228 -0
- package/src/components/common/ModalWrapper.tsx +184 -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 +137 -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 +70 -0
- package/src/theme/useTheme.ts +75 -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 +21 -0
- package/src/types/props.ts +104 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/dateConversion.ts +127 -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,474 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc(DateTimePickerKitImpl)
|
|
5
|
+
public class DateTimePickerKitImpl: NSObject {
|
|
6
|
+
|
|
7
|
+
@objc public static let shared = DateTimePickerKitImpl()
|
|
8
|
+
|
|
9
|
+
private var isPickerOpen: Bool = false
|
|
10
|
+
private var activeViewController: UIViewController?
|
|
11
|
+
private var activePicker: UIDatePicker?
|
|
12
|
+
private var storedTimestamp: Double = Date().timeIntervalSince1970 * 1000
|
|
13
|
+
private var activeResolve: ((Any?) -> Void)?
|
|
14
|
+
private var activeReject: ((String, String, Error?) -> Void)?
|
|
15
|
+
|
|
16
|
+
private override init() {
|
|
17
|
+
super.init()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@objc(openDatePickerWithOptions:resolve:reject:)
|
|
21
|
+
public func openDatePicker(
|
|
22
|
+
options: [String: Any],
|
|
23
|
+
resolve: @escaping (Any?) -> Void,
|
|
24
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
25
|
+
) {
|
|
26
|
+
presentPicker(mode: .date, options: options, resolve: resolve, reject: reject)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@objc(openTimePickerWithOptions:resolve:reject:)
|
|
30
|
+
public func openTimePicker(
|
|
31
|
+
options: [String: Any],
|
|
32
|
+
resolve: @escaping (Any?) -> Void,
|
|
33
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
34
|
+
) {
|
|
35
|
+
presentPicker(mode: .time, options: options, resolve: resolve, reject: reject)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objc(openDateTimePickerWithOptions:resolve:reject:)
|
|
39
|
+
public func openDateTimePicker(
|
|
40
|
+
options: [String: Any],
|
|
41
|
+
resolve: @escaping (Any?) -> Void,
|
|
42
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
43
|
+
) {
|
|
44
|
+
presentPicker(mode: .dateAndTime, options: options, resolve: resolve, reject: reject)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@objc(openCountdownPickerWithOptions:resolve:reject:)
|
|
48
|
+
public func openCountdownPicker(
|
|
49
|
+
options: [String: Any],
|
|
50
|
+
resolve: @escaping (Any?) -> Void,
|
|
51
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
52
|
+
) {
|
|
53
|
+
presentPicker(mode: .countDownTimer, options: options, resolve: resolve, reject: reject)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@objc(closePickerWithResolve:reject:)
|
|
57
|
+
public func closePicker(
|
|
58
|
+
resolve: @escaping (Any?) -> Void,
|
|
59
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
60
|
+
) {
|
|
61
|
+
DispatchQueue.main.async { [weak self] in
|
|
62
|
+
guard let self = self else { return }
|
|
63
|
+
if !self.isPickerOpen || self.activeViewController == nil {
|
|
64
|
+
resolve(false)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let openResolve = self.activeResolve
|
|
69
|
+
let ts = self.storedTimestamp
|
|
70
|
+
self.cleanupAndDismiss(action: "dismissed") {
|
|
71
|
+
openResolve?([
|
|
72
|
+
"action": "dismissed",
|
|
73
|
+
"timestamp": ts
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
resolve(true)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@objc(confirmPickerWithResolve:reject:)
|
|
81
|
+
public func confirmPicker(
|
|
82
|
+
resolve: @escaping (Any?) -> Void,
|
|
83
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
84
|
+
) {
|
|
85
|
+
DispatchQueue.main.async { [weak self] in
|
|
86
|
+
guard let self = self else { return }
|
|
87
|
+
guard self.isPickerOpen, let picker = self.activePicker else {
|
|
88
|
+
reject("PICKER_NOT_OPEN", "Picker is not currently open.", nil)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let timestamp = picker.date.timeIntervalSince1970 * 1000
|
|
93
|
+
self.storedTimestamp = timestamp
|
|
94
|
+
let openResolve = self.activeResolve
|
|
95
|
+
|
|
96
|
+
self.cleanupAndDismiss(action: "confirmed") {
|
|
97
|
+
openResolve?([
|
|
98
|
+
"action": "confirmed",
|
|
99
|
+
"timestamp": timestamp
|
|
100
|
+
])
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
resolve([
|
|
104
|
+
"action": "confirmed",
|
|
105
|
+
"timestamp": timestamp
|
|
106
|
+
])
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@objc(cancelPickerWithResolve:reject:)
|
|
111
|
+
public func cancelPicker(
|
|
112
|
+
resolve: @escaping (Any?) -> Void,
|
|
113
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
114
|
+
) {
|
|
115
|
+
DispatchQueue.main.async { [weak self] in
|
|
116
|
+
guard let self = self else { return }
|
|
117
|
+
guard self.isPickerOpen else {
|
|
118
|
+
reject("PICKER_NOT_OPEN", "Picker is not currently open.", nil)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let openResolve = self.activeResolve
|
|
123
|
+
let ts = self.storedTimestamp
|
|
124
|
+
self.cleanupAndDismiss(action: "cancelled") {
|
|
125
|
+
openResolve?([
|
|
126
|
+
"action": "cancelled",
|
|
127
|
+
"timestamp": ts
|
|
128
|
+
])
|
|
129
|
+
}
|
|
130
|
+
resolve(true)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@objc(setSelectedDate:resolve:reject:)
|
|
135
|
+
public func setSelectedDate(
|
|
136
|
+
timestamp: Double,
|
|
137
|
+
resolve: @escaping (Any?) -> Void,
|
|
138
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
139
|
+
) {
|
|
140
|
+
DispatchQueue.main.async { [weak self] in
|
|
141
|
+
guard let self = self else { return }
|
|
142
|
+
self.storedTimestamp = timestamp
|
|
143
|
+
let date = Date(timeIntervalSince1970: timestamp / 1000)
|
|
144
|
+
self.activePicker?.setDate(date, animated: true)
|
|
145
|
+
resolve(true)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@objc(getSelectedDateWithResolve:reject:)
|
|
150
|
+
public func getSelectedDate(
|
|
151
|
+
resolve: @escaping (Any?) -> Void,
|
|
152
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
153
|
+
) {
|
|
154
|
+
DispatchQueue.main.async { [weak self] in
|
|
155
|
+
guard let self = self else { return }
|
|
156
|
+
let timestamp = self.activePicker?.date.timeIntervalSince1970.advanced(by: 0) ?? (self.storedTimestamp / 1000)
|
|
157
|
+
resolve([
|
|
158
|
+
"action": "confirmed",
|
|
159
|
+
"timestamp": timestamp * 1000
|
|
160
|
+
])
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@objc(resetPickerWithResolve:reject:)
|
|
165
|
+
public func resetPicker(
|
|
166
|
+
resolve: @escaping (Any?) -> Void,
|
|
167
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
168
|
+
) {
|
|
169
|
+
DispatchQueue.main.async { [weak self] in
|
|
170
|
+
guard let self = self else { return }
|
|
171
|
+
self.storedTimestamp = Date().timeIntervalSince1970 * 1000
|
|
172
|
+
let now = Date()
|
|
173
|
+
self.activePicker?.setDate(now, animated: true)
|
|
174
|
+
resolve(true)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// MARK: - Presentation Implementation
|
|
179
|
+
|
|
180
|
+
private func presentPicker(
|
|
181
|
+
mode: UIDatePicker.Mode,
|
|
182
|
+
options: [String: Any],
|
|
183
|
+
resolve: @escaping (Any?) -> Void,
|
|
184
|
+
reject: @escaping (String, String, Error?) -> Void
|
|
185
|
+
) {
|
|
186
|
+
DispatchQueue.main.async { [weak self] in
|
|
187
|
+
guard let self = self else { return }
|
|
188
|
+
|
|
189
|
+
if self.isPickerOpen {
|
|
190
|
+
reject("PICKER_ALREADY_OPEN", "A date time picker is already open.", nil)
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
guard let topVC = self.getTopViewController() else {
|
|
195
|
+
reject("PRESENTATION_FAILED", "Could not find a presenting view controller.", nil)
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
self.isPickerOpen = true
|
|
200
|
+
self.activeResolve = resolve
|
|
201
|
+
self.activeReject = reject
|
|
202
|
+
|
|
203
|
+
let initialMs = options["value"] as? Double ?? (Date().timeIntervalSince1970 * 1000)
|
|
204
|
+
self.storedTimestamp = initialMs
|
|
205
|
+
let initialDate = Date(timeIntervalSince1970: initialMs / 1000)
|
|
206
|
+
|
|
207
|
+
let picker = UIDatePicker()
|
|
208
|
+
picker.datePickerMode = mode
|
|
209
|
+
picker.date = initialDate
|
|
210
|
+
picker.translatesAutoresizingMaskIntoConstraints = false
|
|
211
|
+
|
|
212
|
+
// Display style
|
|
213
|
+
let display = options["display"] as? String ?? "default"
|
|
214
|
+
switch display {
|
|
215
|
+
case "spinner":
|
|
216
|
+
picker.preferredDatePickerStyle = .wheels
|
|
217
|
+
case "compact":
|
|
218
|
+
picker.preferredDatePickerStyle = .compact
|
|
219
|
+
case "inline":
|
|
220
|
+
picker.preferredDatePickerStyle = .inline
|
|
221
|
+
default:
|
|
222
|
+
if mode == .dateAndTime {
|
|
223
|
+
picker.preferredDatePickerStyle = .compact
|
|
224
|
+
} else if mode == .date {
|
|
225
|
+
picker.preferredDatePickerStyle = .inline
|
|
226
|
+
} else {
|
|
227
|
+
picker.preferredDatePickerStyle = .wheels
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Minimum Date
|
|
232
|
+
if let minMs = options["minimumDate"] as? Double {
|
|
233
|
+
picker.minimumDate = Date(timeIntervalSince1970: minMs / 1000)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Maximum Date
|
|
237
|
+
if let maxMs = options["maximumDate"] as? Double {
|
|
238
|
+
picker.maximumDate = Date(timeIntervalSince1970: maxMs / 1000)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Minute Interval
|
|
242
|
+
if let interval = options["minuteInterval"] as? Int, interval >= 1 && interval <= 30 {
|
|
243
|
+
picker.minuteInterval = interval
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Locale
|
|
247
|
+
if let localeStr = options["locale"] as? String, !localeStr.isEmpty {
|
|
248
|
+
picker.locale = Locale(identifier: localeStr)
|
|
249
|
+
} else {
|
|
250
|
+
picker.locale = Locale.current
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// TimeZone
|
|
254
|
+
if let offsetMinutes = options["timeZoneOffsetInMinutes"] as? Int {
|
|
255
|
+
if let tz = TimeZone(secondsFromGMT: offsetMinutes * 60) {
|
|
256
|
+
picker.timeZone = tz
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Theme
|
|
261
|
+
let modalVC = UIViewController()
|
|
262
|
+
modalVC.modalPresentationStyle = .overFullScreen
|
|
263
|
+
modalVC.modalTransitionStyle = .crossDissolve
|
|
264
|
+
|
|
265
|
+
if let theme = options["theme"] as? String {
|
|
266
|
+
switch theme {
|
|
267
|
+
case "dark":
|
|
268
|
+
modalVC.overrideUserInterfaceStyle = .dark
|
|
269
|
+
case "light":
|
|
270
|
+
modalVC.overrideUserInterfaceStyle = .light
|
|
271
|
+
default:
|
|
272
|
+
modalVC.overrideUserInterfaceStyle = .unspecified
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Accent color
|
|
277
|
+
if let accentHex = options["accentColor"] as? String, let color = self.colorFromHex(accentHex) {
|
|
278
|
+
picker.tintColor = color
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
self.activePicker = picker
|
|
282
|
+
|
|
283
|
+
// Container View
|
|
284
|
+
let overlayView = UIView()
|
|
285
|
+
overlayView.backgroundColor = UIColor.black.withAlphaComponent(0.4)
|
|
286
|
+
overlayView.translatesAutoresizingMaskIntoConstraints = false
|
|
287
|
+
|
|
288
|
+
let sheetView = UIView()
|
|
289
|
+
sheetView.backgroundColor = UIColor { trait in
|
|
290
|
+
trait.userInterfaceStyle == .dark ? UIColor(white: 0.15, alpha: 1.0) : UIColor.white
|
|
291
|
+
}
|
|
292
|
+
sheetView.layer.cornerRadius = 16
|
|
293
|
+
sheetView.layer.masksToBounds = true
|
|
294
|
+
sheetView.translatesAutoresizingMaskIntoConstraints = false
|
|
295
|
+
sheetView.accessibilityViewIsModal = true
|
|
296
|
+
|
|
297
|
+
// Header Bar
|
|
298
|
+
let headerView = UIView()
|
|
299
|
+
headerView.translatesAutoresizingMaskIntoConstraints = false
|
|
300
|
+
|
|
301
|
+
let cancelBtn = UIButton(type: .system)
|
|
302
|
+
let cancelText = options["cancelText"] as? String ?? "Cancel"
|
|
303
|
+
cancelBtn.setTitle(cancelText, for: .normal)
|
|
304
|
+
cancelBtn.accessibilityLabel = cancelText
|
|
305
|
+
cancelBtn.accessibilityTraits = .button
|
|
306
|
+
cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
|
|
307
|
+
cancelBtn.translatesAutoresizingMaskIntoConstraints = false
|
|
308
|
+
cancelBtn.addTarget(self, action: #selector(self.handleCancelTap), for: .touchUpInside)
|
|
309
|
+
|
|
310
|
+
let titleLabel = UILabel()
|
|
311
|
+
let titleText = options["title"] as? String ?? ""
|
|
312
|
+
titleLabel.text = titleText
|
|
313
|
+
titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
|
314
|
+
titleLabel.textAlignment = .center
|
|
315
|
+
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
316
|
+
|
|
317
|
+
let confirmBtn = UIButton(type: .system)
|
|
318
|
+
let confirmText = options["confirmText"] as? String ?? "Confirm"
|
|
319
|
+
confirmBtn.setTitle(confirmText, for: .normal)
|
|
320
|
+
confirmBtn.accessibilityLabel = confirmText
|
|
321
|
+
confirmBtn.accessibilityTraits = .button
|
|
322
|
+
confirmBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
|
323
|
+
confirmBtn.translatesAutoresizingMaskIntoConstraints = false
|
|
324
|
+
confirmBtn.addTarget(self, action: #selector(self.handleConfirmTap), for: .touchUpInside)
|
|
325
|
+
|
|
326
|
+
headerView.addSubview(cancelBtn)
|
|
327
|
+
headerView.addSubview(titleLabel)
|
|
328
|
+
headerView.addSubview(confirmBtn)
|
|
329
|
+
|
|
330
|
+
sheetView.addSubview(headerView)
|
|
331
|
+
sheetView.addSubview(picker)
|
|
332
|
+
|
|
333
|
+
modalVC.view.addSubview(overlayView)
|
|
334
|
+
modalVC.view.addSubview(sheetView)
|
|
335
|
+
|
|
336
|
+
// Backdrop tap gesture
|
|
337
|
+
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleBackdropTap))
|
|
338
|
+
overlayView.addGestureRecognizer(tapGesture)
|
|
339
|
+
|
|
340
|
+
NSLayoutConstraint.activate([
|
|
341
|
+
overlayView.leadingAnchor.constraint(equalTo: modalVC.view.leadingAnchor),
|
|
342
|
+
overlayView.trailingAnchor.constraint(equalTo: modalVC.view.trailingAnchor),
|
|
343
|
+
overlayView.topAnchor.constraint(equalTo: modalVC.view.topAnchor),
|
|
344
|
+
overlayView.bottomAnchor.constraint(equalTo: modalVC.view.bottomAnchor),
|
|
345
|
+
|
|
346
|
+
sheetView.leadingAnchor.constraint(equalTo: modalVC.view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
|
|
347
|
+
sheetView.trailingAnchor.constraint(equalTo: modalVC.view.safeAreaLayoutGuide.trailingAnchor, constant: -16),
|
|
348
|
+
sheetView.bottomAnchor.constraint(equalTo: modalVC.view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
|
|
349
|
+
|
|
350
|
+
headerView.leadingAnchor.constraint(equalTo: sheetView.leadingAnchor, constant: 16),
|
|
351
|
+
headerView.trailingAnchor.constraint(equalTo: sheetView.trailingAnchor, constant: -16),
|
|
352
|
+
headerView.topAnchor.constraint(equalTo: sheetView.topAnchor, constant: 12),
|
|
353
|
+
headerView.heightAnchor.constraint(equalToConstant: 44),
|
|
354
|
+
|
|
355
|
+
cancelBtn.leadingAnchor.constraint(equalTo: headerView.leadingAnchor),
|
|
356
|
+
cancelBtn.centerYAnchor.constraint(equalTo: headerView.centerYAnchor),
|
|
357
|
+
|
|
358
|
+
titleLabel.centerXAnchor.constraint(equalTo: headerView.centerXAnchor),
|
|
359
|
+
titleLabel.centerYAnchor.constraint(equalTo: headerView.centerYAnchor),
|
|
360
|
+
titleLabel.leadingAnchor.constraint(greaterThanOrEqualTo: cancelBtn.trailingAnchor, constant: 8),
|
|
361
|
+
titleLabel.trailingAnchor.constraint(lessThanOrEqualTo: confirmBtn.leadingAnchor, constant: -8),
|
|
362
|
+
|
|
363
|
+
confirmBtn.trailingAnchor.constraint(equalTo: headerView.trailingAnchor),
|
|
364
|
+
confirmBtn.centerYAnchor.constraint(equalTo: headerView.centerYAnchor),
|
|
365
|
+
|
|
366
|
+
picker.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: 12),
|
|
367
|
+
picker.leadingAnchor.constraint(equalTo: sheetView.leadingAnchor, constant: 16),
|
|
368
|
+
picker.trailingAnchor.constraint(equalTo: sheetView.trailingAnchor, constant: -16),
|
|
369
|
+
picker.bottomAnchor.constraint(equalTo: sheetView.bottomAnchor, constant: -16),
|
|
370
|
+
])
|
|
371
|
+
|
|
372
|
+
self.activeViewController = modalVC
|
|
373
|
+
topVC.present(modalVC, animated: true, completion: nil)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@objc private func handleConfirmTap() {
|
|
378
|
+
guard let picker = activePicker else { return }
|
|
379
|
+
let timestamp = picker.date.timeIntervalSince1970 * 1000
|
|
380
|
+
storedTimestamp = timestamp
|
|
381
|
+
let resolve = activeResolve
|
|
382
|
+
cleanupAndDismiss(action: "confirmed") {
|
|
383
|
+
resolve?([
|
|
384
|
+
"action": "confirmed",
|
|
385
|
+
"timestamp": timestamp
|
|
386
|
+
])
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@objc private func handleCancelTap() {
|
|
391
|
+
let resolve = activeResolve
|
|
392
|
+
let ts = storedTimestamp
|
|
393
|
+
cleanupAndDismiss(action: "cancelled") {
|
|
394
|
+
resolve?([
|
|
395
|
+
"action": "cancelled",
|
|
396
|
+
"timestamp": ts
|
|
397
|
+
])
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
@objc private func handleBackdropTap() {
|
|
402
|
+
let resolve = activeResolve
|
|
403
|
+
let ts = storedTimestamp
|
|
404
|
+
cleanupAndDismiss(action: "dismissed") {
|
|
405
|
+
resolve?([
|
|
406
|
+
"action": "dismissed",
|
|
407
|
+
"timestamp": ts
|
|
408
|
+
])
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private func cleanupAndDismiss(action: String, completion: (() -> Void)? = nil) {
|
|
413
|
+
let vc = activeViewController
|
|
414
|
+
activeViewController = nil
|
|
415
|
+
activePicker = nil
|
|
416
|
+
isPickerOpen = false
|
|
417
|
+
activeResolve = nil
|
|
418
|
+
activeReject = nil
|
|
419
|
+
|
|
420
|
+
if let presenting = vc?.presentingViewController {
|
|
421
|
+
presenting.dismiss(animated: true, completion: completion)
|
|
422
|
+
} else {
|
|
423
|
+
vc?.dismiss(animated: true, completion: completion)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private func getTopViewController(base: UIViewController? = nil) -> UIViewController? {
|
|
428
|
+
let currentBase = base ?? UIApplication.shared.connectedScenes
|
|
429
|
+
.compactMap { $0 as? UIWindowScene }
|
|
430
|
+
.flatMap { $0.windows }
|
|
431
|
+
.first { $0.isKeyWindow }?
|
|
432
|
+
.rootViewController
|
|
433
|
+
|
|
434
|
+
if let nav = currentBase as? UINavigationController {
|
|
435
|
+
return getTopViewController(base: nav.visibleViewController)
|
|
436
|
+
}
|
|
437
|
+
if let tab = currentBase as? UITabBarController {
|
|
438
|
+
if let selected = tab.selectedViewController {
|
|
439
|
+
return getTopViewController(base: selected)
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if let presented = currentBase?.presentedViewController {
|
|
443
|
+
return getTopViewController(base: presented)
|
|
444
|
+
}
|
|
445
|
+
return currentBase
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private func colorFromHex(_ hex: String) -> UIColor? {
|
|
449
|
+
var cString = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
|
|
450
|
+
if cString.hasPrefix("#") {
|
|
451
|
+
cString.remove(at: cString.startIndex)
|
|
452
|
+
}
|
|
453
|
+
guard cString.count == 6 || cString.count == 8 else { return nil }
|
|
454
|
+
|
|
455
|
+
var rgbValue: UInt64 = 0
|
|
456
|
+
Scanner(string: cString).scanHexInt64(&rgbValue)
|
|
457
|
+
|
|
458
|
+
if cString.count == 8 {
|
|
459
|
+
return UIColor(
|
|
460
|
+
red: CGFloat((rgbValue & 0xFF000000) >> 24) / 255.0,
|
|
461
|
+
green: CGFloat((rgbValue & 0x00FF0000) >> 16) / 255.0,
|
|
462
|
+
blue: CGFloat((rgbValue & 0x0000FF00) >> 8) / 255.0,
|
|
463
|
+
alpha: CGFloat(rgbValue & 0x000000FF) / 255.0
|
|
464
|
+
)
|
|
465
|
+
} else {
|
|
466
|
+
return UIColor(
|
|
467
|
+
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
|
|
468
|
+
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
|
|
469
|
+
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
|
|
470
|
+
alpha: 1.0
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeDateTimePickerKit.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAiBlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
|