expo-calendar-kit 2.1.9 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/ExpoCalendarKitView.swift +121 -41
- package/package.json +1 -1
|
@@ -3,6 +3,23 @@ import UIKit
|
|
|
3
3
|
import CalendarKit
|
|
4
4
|
import EventKit
|
|
5
5
|
|
|
6
|
+
// MARK: - UIColor Hex Extension
|
|
7
|
+
extension UIColor {
|
|
8
|
+
convenience init?(hex: String) {
|
|
9
|
+
let hexColor = hex.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
10
|
+
let scanner = Scanner(string: hexColor.hasPrefix("#") ? String(hexColor.dropFirst()) : hexColor)
|
|
11
|
+
var hexNumber: UInt64 = 0
|
|
12
|
+
|
|
13
|
+
guard scanner.scanHexInt64(&hexNumber) else { return nil }
|
|
14
|
+
|
|
15
|
+
let r = CGFloat((hexNumber & 0xff0000) >> 16) / 255
|
|
16
|
+
let g = CGFloat((hexNumber & 0x00ff00) >> 8) / 255
|
|
17
|
+
let b = CGFloat(hexNumber & 0x0000ff) / 255
|
|
18
|
+
|
|
19
|
+
self.init(red: r, green: g, blue: b, alpha: 1.0)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
// MARK: - MyEKWrapper (copied from CalendarApp, renamed to avoid conflicts)
|
|
7
24
|
final class MyEKWrapper: EventDescriptor {
|
|
8
25
|
public var dateInterval: DateInterval {
|
|
@@ -136,57 +153,95 @@ final class MyEKWrapper: EventDescriptor {
|
|
|
136
153
|
// MARK: - Calendar View Controller (following CalendarApp pattern)
|
|
137
154
|
final class CalendarViewController: DayViewController {
|
|
138
155
|
private var eventStore = EKEventStore() // Not used but needed for EKEvent creation
|
|
156
|
+
private var dynamicEvents: [[String: Any]] = [] // Store events from React Native
|
|
139
157
|
|
|
140
158
|
override func viewDidLoad() {
|
|
141
159
|
super.viewDidLoad()
|
|
142
|
-
print("
|
|
143
|
-
|
|
160
|
+
print("🔥🔥🔥 CalendarViewController viewDidLoad called")
|
|
161
|
+
print("🔥🔥🔥 dynamicEvents count: \(dynamicEvents.count)")
|
|
162
|
+
// Don't request calendar access - we'll use events from React Native
|
|
163
|
+
print("🔥🔥🔥 CalendarViewController viewDidLoad complete")
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Function to update events from React Native
|
|
167
|
+
func updateEvents(_ events: [[String: Any]]) {
|
|
168
|
+
print("🔥🔥🔥 CalendarViewController updateEvents called with \(events.count) events")
|
|
169
|
+
for (index, event) in events.enumerated() {
|
|
170
|
+
print("🔥🔥🔥 Received Event \(index): \(event)")
|
|
171
|
+
}
|
|
172
|
+
print("🔥🔥🔥 About to update dynamicEvents array")
|
|
173
|
+
self.dynamicEvents = events
|
|
174
|
+
print("🔥🔥🔥 dynamicEvents updated, new count: \(self.dynamicEvents.count)")
|
|
175
|
+
print("🔥🔥🔥 About to call reloadData")
|
|
176
|
+
self.reloadData() // Refresh the calendar view
|
|
177
|
+
print("🔥🔥🔥 CalendarViewController reloadData called after updateEvents")
|
|
144
178
|
}
|
|
145
179
|
|
|
146
180
|
// MARK: - DayViewDataSource
|
|
147
181
|
|
|
148
182
|
// This is the main method - following CalendarApp pattern exactly
|
|
149
183
|
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
|
|
150
|
-
|
|
184
|
+
let formatter = DateFormatter()
|
|
185
|
+
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
|
186
|
+
print("🔥🔥🔥🔥🔥 ===== eventsForDate CALLED =====")
|
|
187
|
+
print("🔥🔥🔥🔥🔥 Requested date: \(formatter.string(from: date))")
|
|
188
|
+
print("🔥🔥🔥🔥🔥 dynamicEvents count: \(dynamicEvents.count)")
|
|
151
189
|
|
|
152
190
|
let calendar = Calendar.current
|
|
191
|
+
var events: [MyEKWrapper] = []
|
|
153
192
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
print("🔥 Not today, returning empty events")
|
|
193
|
+
if dynamicEvents.isEmpty {
|
|
194
|
+
print("🔥🔥🔥🔥🔥 NO DYNAMIC EVENTS TO PROCESS!")
|
|
157
195
|
return []
|
|
158
196
|
}
|
|
159
197
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
// Process dynamic events from React Native
|
|
199
|
+
for (index, eventDict) in dynamicEvents.enumerated() {
|
|
200
|
+
print("🔥🔥🔥🔥🔥 Processing event \(index): \(eventDict)")
|
|
201
|
+
|
|
202
|
+
guard let title = eventDict["title"] as? String,
|
|
203
|
+
let startTimestamp = eventDict["startDate"] as? Double,
|
|
204
|
+
let endTimestamp = eventDict["endDate"] as? Double else {
|
|
205
|
+
print("🔥🔥🔥🔥🔥 SKIPPING event \(index) with missing data: \(eventDict)")
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let startDate = Date(timeIntervalSince1970: startTimestamp / 1000)
|
|
210
|
+
let endDate = Date(timeIntervalSince1970: endTimestamp / 1000)
|
|
211
|
+
|
|
212
|
+
print("🔥🔥🔥🔥🔥 Event \(index) '\(title)':")
|
|
213
|
+
print("🔥🔥🔥🔥🔥 Start: \(formatter.string(from: startDate))")
|
|
214
|
+
print("🔥🔥🔥🔥🔥 End: \(formatter.string(from: endDate))")
|
|
215
|
+
print("🔥🔥🔥🔥🔥 Requested: \(formatter.string(from: date))")
|
|
216
|
+
|
|
217
|
+
let isSameDay = calendar.isDate(startDate, inSameDayAs: date)
|
|
218
|
+
print("🔥🔥🔥🔥🔥 Same day check: \(isSameDay)")
|
|
219
|
+
|
|
220
|
+
// Check if this event is on the requested date
|
|
221
|
+
guard isSameDay else {
|
|
222
|
+
print("🔥🔥🔥🔥🔥 NOT on requested date, skipping")
|
|
223
|
+
continue
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
print("🔥🔥🔥🔥🔥 Creating EKEvent for this event")
|
|
227
|
+
// Create EKEvent
|
|
228
|
+
let ekEvent = EKEvent(eventStore: eventStore)
|
|
229
|
+
ekEvent.title = title
|
|
230
|
+
ekEvent.startDate = startDate
|
|
231
|
+
ekEvent.endDate = endDate
|
|
232
|
+
|
|
233
|
+
// Set color from React Native or default
|
|
234
|
+
let colorString = eventDict["backgroundColor"] as? String ?? "#007AFF"
|
|
235
|
+
let color = UIColor(hex: colorString) ?? UIColor.blue
|
|
236
|
+
ekEvent.calendar = createMockCalendar(color: color)
|
|
237
|
+
|
|
238
|
+
events.append(MyEKWrapper(eventKitEvent: ekEvent))
|
|
239
|
+
print("🔥🔥🔥🔥🔥 SUCCESSFULLY ADDED event: \(title)")
|
|
240
|
+
}
|
|
188
241
|
|
|
189
|
-
print("
|
|
242
|
+
print("🔥🔥🔥🔥🔥 ===== FINAL RESULT =====")
|
|
243
|
+
print("🔥🔥🔥🔥🔥 Returning \(events.count) events for \(formatter.string(from: date))")
|
|
244
|
+
print("🔥🔥🔥🔥🔥 ========================")
|
|
190
245
|
return events
|
|
191
246
|
}
|
|
192
247
|
|
|
@@ -211,22 +266,33 @@ public class ExpoCalendarKitView: UIView {
|
|
|
211
266
|
private var calendarViewController: CalendarViewController!
|
|
212
267
|
|
|
213
268
|
public override init(frame: CGRect) {
|
|
214
|
-
print("
|
|
269
|
+
print("🔥🔥🔥 ExpoCalendarKitView init called with frame: \(frame)")
|
|
215
270
|
super.init(frame: frame)
|
|
271
|
+
print("🔥🔥🔥 About to call setupCalendarViewController")
|
|
216
272
|
setupCalendarViewController()
|
|
273
|
+
print("🔥🔥🔥 ExpoCalendarKitView init complete")
|
|
217
274
|
}
|
|
218
275
|
|
|
219
276
|
required public init?(coder: NSCoder) {
|
|
277
|
+
print("🔥🔥🔥 ExpoCalendarKitView init(coder) called")
|
|
220
278
|
super.init(coder: coder)
|
|
279
|
+
print("🔥🔥🔥 About to call setupCalendarViewController from coder init")
|
|
221
280
|
setupCalendarViewController()
|
|
281
|
+
print("🔥🔥🔥 ExpoCalendarKitView init(coder) complete")
|
|
222
282
|
}
|
|
223
283
|
|
|
224
284
|
private func setupCalendarViewController() {
|
|
225
|
-
print("
|
|
285
|
+
print("🔥🔥🔥 setupCalendarViewController called")
|
|
226
286
|
|
|
287
|
+
print("🔥🔥🔥 Creating CalendarViewController")
|
|
227
288
|
calendarViewController = CalendarViewController()
|
|
289
|
+
print("🔥🔥🔥 CalendarViewController created: \(calendarViewController != nil)")
|
|
290
|
+
|
|
291
|
+
print("🔥🔥🔥 Adding calendarViewController.view as subview")
|
|
228
292
|
addSubview(calendarViewController.view)
|
|
293
|
+
print("🔥🔥🔥 Subview added")
|
|
229
294
|
|
|
295
|
+
print("🔥🔥🔥 Setting up constraints")
|
|
230
296
|
calendarViewController.view.translatesAutoresizingMaskIntoConstraints = false
|
|
231
297
|
NSLayoutConstraint.activate([
|
|
232
298
|
calendarViewController.view.topAnchor.constraint(equalTo: topAnchor),
|
|
@@ -234,15 +300,29 @@ public class ExpoCalendarKitView: UIView {
|
|
|
234
300
|
calendarViewController.view.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
235
301
|
calendarViewController.view.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
236
302
|
])
|
|
303
|
+
print("🔥🔥🔥 Constraints activated")
|
|
304
|
+
|
|
305
|
+
print("🔥🔥🔥 CalendarViewController setup complete")
|
|
237
306
|
|
|
238
|
-
|
|
307
|
+
// Force initial load
|
|
308
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
309
|
+
print("🔥🔥🔥 About to call initial reloadData")
|
|
310
|
+
self.calendarViewController.reloadData()
|
|
311
|
+
print("🔥🔥🔥 Initial reloadData called")
|
|
312
|
+
}
|
|
239
313
|
}
|
|
240
314
|
|
|
241
315
|
// MARK: - Public Methods (for React Native bridge)
|
|
242
316
|
public func setEvents(_ eventDicts: [[String: Any]]) {
|
|
243
|
-
print("
|
|
244
|
-
|
|
245
|
-
|
|
317
|
+
print("🔥🔥🔥 setEvents called with \(eventDicts.count) events")
|
|
318
|
+
print("🔥🔥🔥 calendarViewController exists: \(calendarViewController != nil)")
|
|
319
|
+
for (index, event) in eventDicts.enumerated() {
|
|
320
|
+
print("🔥🔥🔥 Input Event \(index): \(event)")
|
|
321
|
+
}
|
|
322
|
+
print("🔥🔥🔥 About to call calendarViewController.updateEvents")
|
|
323
|
+
// Pass events to the calendar controller
|
|
324
|
+
calendarViewController.updateEvents(eventDicts)
|
|
325
|
+
print("🔥🔥🔥 setEvents complete")
|
|
246
326
|
}
|
|
247
327
|
|
|
248
328
|
public func setDate(_ timestamp: Double) {
|