CalendarKit
CalendarKit copied to clipboard
Context menu for events ?
Hello,
Could CalendarKit be able to present a context menu at the event by e.g. using dayViewDidLongPressEventView or some other hook ? ( I tried, but when I was selecting the event the y position changed and it looked weird since the frame seemed detached from the scrollview. I.e. the event that I was selecting for context menu was not anymore returned back into the scroll panel. )
Basically I would need to open a context menu for each and every separate event by long tapping the event. Thanks for any help
Please, provide a mockup of the design you're trying to achieve and a code sample you've used.
In particular, I'm interested in the code you've put in the dayViewDidLongPressEventView
hook.
Here is the mockup of what I try to achieve:
while adding something like this into the dayViewDidLongPressEventView
nothing happens when I add the similar to the dayView the mentioned event displacement happens.
I used your ExampleController
as base to extend it with UIContextMenuInteractionDelegate
, further I modified the below:
override func dayView(dayView: DayView, didLongPressTimelineAt date: Date) {
print("Did long press timeline at date dayView\(date)").
...
event.endDate = datePeriod.end!
// new code:
view.addSubview(dayView)
let interaction = UIContextMenuInteraction(delegate: self)
dayView.addInteraction(interaction)
}
After all a step-by-step view of what happens with the current code.
- starts up fine, everything is good here

- long press one of the events (red) in attempt to open the context menu. At this point the event "jumps" off to another layer where it can't be scrolled, it's stuck at the bottom of the screen. (if I were to press an event closer to the bottom of the timeline, it completely disappears, and cannot be interacted with anymore.)

- a preview of how the red event doesn't move in spite of scrolling.


- After the event bugging out to the bottom of the screen it is possible to open a context menu from this particular event. None of the other events can open a context menu at this point, unless long pressing them, to which they also either "jump" off the canvas. (movement in only Y-axis)

Thank you for the detailed report. This is clearly a bug. I'll try to fix it asap.
Btw, what is this line for:
// new code:
view.addSubview(dayView)
I think, it's wrong. As a CalendarKit user when working with the default CalendarViewController
, you shouldn't add DayView
to any of the view hierarchy.
Hello,
I have run into a similar issue once again, while trying to open a completely new view from
dayViewDidSelectEventView
override func dayViewDidSelectEventView(_ eventView: EventView) {
guard let descriptor = eventView.descriptor as? Event else {
return
}
let SwifUIview = ViewToBeOpenedByTappingOnEvent()
let vc = UIHostingController(rootView: SwifUIview)
guard let vcview = vc.view else { debugPrint("guard failed"); return }
view.addSubview(vcview)
}
}
This is my code, I am aware there has been another problem with opening a new view from this function, which to my knowledge was in UIKit. However i'm trying to open a SwiftUI view from this, and it doesn't seem to be working. it does enter the view struct, and runs the code, but doesn't present it. (although i'm hosting it as a UIKit ViewController in the UIHostingController
method.
Appreciate any help you can provide.
PS.
If i might ask. i'd like to inquire about the progress on how to open a context menu as conversed previously. i still haven't found any plausible way of implementing it.
Many thanks.
Hi,
- I guess, you need to present the controller itself, not the view. Otherwise, the view controller lifecycle is interrupted, which prevents the view from showing up correctly.
- No progress on this issue. Feel free to fix it yourself and submit a pull request, I'd be very happy to accept your contribution.