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

Delegate called twice: dayView(dayView: DayView, didUpdate event: EventDescriptor) #356

Open MadalinSava opened 1 year ago

MadalinSava commented 1 year ago

When I drag an event after long-pressing it (without releasing!), after dropping it I'm seeing the delegate function always called twice. This is caused by the snap animation in commitEditing. What happens on mouse release:

  1. handlePanGesture is called and since the state is ended, it calls commitEditing
  2. the snap animation starts
  3. immediately, before the animation ends, timelineDidLongPress is called
  4. since editedEventView is still there (animation did not finish and completionHandler was not called to set it to nil), the animation starts again
  5. the completion handler is called for both animations
richardtop commented 1 year ago

Are you having any issues because of this?

MadalinSava commented 1 year ago

Kind of, when the event is updated the app is reacting to changes. Right now there's no visible issue but I will add some more functionalities around this. A simple solution would be to use a weak reference to editedEventView in TimelinePagerView:370 (for the completionHandler in the commitEditing function, and add a guard to unwrap it. The second time the completion handler is called is should be nil since after the first call to dayView(dayView:didUpdate) I'm calling endEventEditing().

richardtop commented 1 year ago

Would you be able to implement this change? To clarify, you experience this issue in the scenario of long pressing an event, editing it and then long pressing the timeline?

MadalinSava commented 1 year ago

Long press into drag and drop (without releasing the touch in between). I'll add this to my todo list, should be a simple fix but need to test it thoroughly.

richardtop commented 1 year ago

Feel free to propose the PR at this stage, so that I could test it as well. I also recommend testing with https://github.com/richardtop/CalendarApp since it's an end-to-end implementation of the calendar instead of the one embedded into this application.