CalendarKit icon indicating copy to clipboard operation
CalendarKit copied to clipboard

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

Open MadalinSava opened this issue 2 years ago • 5 comments
trafficstars

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

MadalinSava avatar Apr 06 '23 07:04 MadalinSava

Are you having any issues because of this?

richardtop avatar Apr 07 '23 01:04 richardtop

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().

MadalinSava avatar Apr 07 '23 08:04 MadalinSava

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?

richardtop avatar Apr 07 '23 18:04 richardtop

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.

MadalinSava avatar Apr 08 '23 12:04 MadalinSava

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.

richardtop avatar Apr 08 '23 13:04 richardtop