CalendarKit icon indicating copy to clipboard operation
CalendarKit copied to clipboard

Context menu for events ?

Open al314 opened this issue 4 years ago • 5 comments

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

al314 avatar Mar 20 '20 18:03 al314

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.

richardtop avatar Mar 21 '20 03:03 richardtop

Here is the mockup of what I try to achieve: Screenshot 2020-03-21 at 11 27 19

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.

  1. starts up fine, everything is good here
Screenshot 2020-03-21 at 12 05 41
  1. 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.)
Screenshot 2020-03-21 at 12 06 02
  1. a preview of how the red event doesn't move in spite of scrolling.
Screenshot 2020-03-21 at 12 06 16 Screenshot 2020-03-21 at 12 06 22
  1. 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)
Screenshot 2020-03-21 at 12 06 43

al314 avatar Mar 21 '20 10:03 al314

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.

richardtop avatar Mar 21 '20 13:03 richardtop

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 UIHostingControllermethod. 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.

al314 avatar May 18 '20 17:05 al314

Hi,

  1. 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.
  2. 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.

richardtop avatar May 24 '20 23:05 richardtop