richardtop / CalendarKit

📅 Calendar for Apple platforms in Swift
https://www.youtube.com/watch?v=cJ63-_z1qg8
MIT License
2.48k stars 333 forks source link

How can I get specific eventView without any gesture? #329

Open qubyedev opened 2 years ago

qubyedev commented 2 years ago

Hi,

I'd like to know is there anyway to get specific eventview without any gesture such as tap or longpress?

The scerino will be I get a data from server, then i want to find the event match the data, and show a popover with the eventview's source rect. So the whole workaround will not have any user interaction.

richardtop commented 2 years ago

No, there is no currently support for such a functionality. I've marked it as an enhancement.

If you wish to implement it yourself, please add the following API to the DayView:

func eventViewFor(eventDescriptor: EventDescriptor) -> EventView {
/// Ask a lower layer for the EventView:
/// DayView -> TimelinePager -> Timeline -> Implement the algorithm on the Timeline class
}
qubyedev commented 2 years ago

Hi @richardtop , after checking it, i dont really get it.

After implement the func in TimelineView.shift, how can I use it from viewcontroller?

richardtop commented 2 years ago

Hi, yes, you'll need to propagate the the call from the DayViewController to the TimelineView.

So, add this functionality to the DayViewController first, then it should call the DayView (you can even use the same method signature). The DayView should call TimelinePagerView and it in turn should call the TimelineView thru the TimelineContainer.

Then you just return the result back up the chain.

Please, submit a pull request to the library, I'm interested in having this functionality integrated.

qubyedev commented 2 years ago

Hi @richardtop , thanks a lot!! It did work 🥳🥳🥳

I'd like to submit a pull request, but I fork this project from last Octobor and I have modified a lot. So I will find time to fork again and add just this func then submit.

Thank you again, you save my day!

richardtop commented 2 years ago

I've looked at your implementation, I see a few issues:

This might not always work.

I suggest you changing the code to the following:

Why the 1st way is preferred? Because the EventDescriptor is meant to have a direct relationship to the EventView. i.e. a single descriptor is attached to a single view. I think, it's even possible to add a view property onto a descriptor, to be set by the library when a view has been attached.

So, the descriptor is not a value type but actually a direct reference used & edited by the library.

qubyedev commented 2 years ago

I just tried to modify the code like in below and it always return nil, did I get it wrong?

func eventViewFor(eventDescriptor: EventDescriptor) -> EventView?{
//        for eventView in eventViews{
//            if eventView.descriptor?.startDate == eventDescriptor.startDate &&
//                eventView.descriptor?.endDate == eventDescriptor.endDate &&
//                eventView.descriptor?.titleText === eventDescriptor.titleText &&
//                eventView.descriptor?.timeText == eventDescriptor.timeText {
//                    return eventView
//            }
//        }

        for eventView in eventViews{
            if eventView.descriptor === eventDescriptor{
                return eventView
            }
        }
        return nil
    }
richardtop commented 2 years ago

No, the code is OK. but are you returning the same descriptor as you've used in the eventsForDate method? It not only has to be the same model, but actually the same instance you've passed in that method.