richardtop / CalendarKit

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

API: moveTo(event:) or Select Event programmatically, similar to moveTo(date:) #289

Open boominadhapm opened 3 years ago

boominadhapm commented 3 years ago

Hi,

Thanks for the nice library. I just want to clarify my doubt which is required for my project implementation.

Currently I am using this library in my project to load the calendar events. But now I am having requirement like, I need to load the events on particular date and move/select to the particular event automatically while loading the events.

Let me know, Is it possible?

Thanks, Boominadha Prakash

richardtop commented 3 years ago

Hi, this is not available. Please take a look here: https://github.com/richardtop/CalendarKit/blob/7908671216d3bbe52a540172dc57f8edb890c972/Source/Timeline/TimelineContainer.swift#L42

I suggest you implement this feature and suggest a pull request. For example, you could start by defining an API on the DayViewController and all the way up to the Timeline:

func scrollToEvent(event: EventDescriptor, animated: Bool)

Or even

func scrollToEvent(event: EventDescriptor, at:ScrollPosition (top/middle/bottom/auto) animated: Bool)

Then, in the Timeline calculate the y(coordinate) of the event and scroll to it in the method I've shown.

You could add a method similar to this: https://github.com/richardtop/CalendarKit/blob/7908671216d3bbe52a540172dc57f8edb890c972/Source/Timeline/TimelineView.swift#L57

to the Timeline and return the y value of any event:

frameForEvent(event: EventDescriptor)

Another approach to finding just a y value without knowing the whole frame would be just using this function: https://github.com/richardtop/CalendarKit/blob/7908671216d3bbe52a540172dc57f8edb890c972/Source/Timeline/TimelineView.swift#L467

If you're interested, I'm looking forward to your pull request.

boominadhapm commented 3 years ago

Hi @richardtop

Thanks for the detailed explanation. I will check it and if possible, I will implement and create a pull request.