JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

triggerScrollToDateDelegate does not trigger willScrollToDateSegmentWith

Open kushsolitary opened this issue 5 years ago • 4 comments

Hi, I am on version 8.0.3.

While performing calendar.scrollToDate, I noticed that the delegate function willScrollToDateSegmentWith is not triggered but didScrollToDateSegmentWith is triggered perfectly.

I currently load my data in willScrollToDateSegmentWith for the visible dates so is there any way to force the delegate function to trigger before the calendar.scrollToDate is triggered?

I also noticed that the completion handler of calendar.scrollToDate triggers before the animation ends so if I try to select a date in the completion handler, it doesn't work.

Thank you!

kushsolitary avatar May 07 '20 06:05 kushsolitary

I just checked the code which deals with scrolling and I can see that it only calls the didScrollToDateSegmentWith method.

    func scrollTo(point: CGPoint, triggerScrollToDateDelegate: Bool? = nil, isAnimationEnabled: Bool, extraAddedOffset: CGFloat, completionHandler: (() -> Void)?) {
        isScrollInProgress = true
        if let validCompletionHandler = completionHandler { scrollDelayedExecutionClosure.append(validCompletionHandler) }
        self.triggerScrollToDateDelegate = triggerScrollToDateDelegate
        var point = point
        if scrollDirection == .horizontal { point.x += extraAddedOffset } else { point.y += extraAddedOffset }
        DispatchQueue.main.async() {
            self.setContentOffset(point, animated: isAnimationEnabled)
            if (isAnimationEnabled && self.calendarOffsetIsAlreadyAtScrollPosition(forOffset: point)) ||
                !isAnimationEnabled {
                self.scrollViewDidEndScrollingAnimation(self)
            }
        }
    }

I would like to know why you decided to not include willScrollToDateSegmentWith here because I am very tempted to do so myself but I am worried it might break something else.

kushsolitary avatar May 07 '20 14:05 kushsolitary

Do it. Let me know how it goes. I will take a look as well, its just that given this current time, I am a little tied up.

Help on this project is always welcomed.

patchthecode avatar May 07 '20 17:05 patchthecode

Thanks, I fixed it in the PR #1264

kushsolitary avatar May 08 '20 12:05 kushsolitary

@patchthecode please, look this 2 PRs :)

bystritskiy avatar Dec 01 '22 15:12 bystritskiy