patchthecode / JTAppleCalendar

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
https://patchthecode.com
MIT License
7.57k stars 812 forks source link

collectionView(didEndDisplayingSupplementaryView:) not called for JTACMonthView #1257

Open rayx opened 4 years ago

rayx commented 4 years ago

(Required) Version Number:

Master branch (pulled from main repo about 1 month ago)

Description

I'm using inside month header with JTACMonthView. For some reason (see background below) I'd like to get notification when the current month header is scrolled out of screen. So I add the following code:

extension JTACMonthView {
    func collectionView(_ collectionView: UICollectionView, didEndDisplayingSupplementaryView view: UICollectionReusableView, forElementOfKind elementKind: String, at indexPath: IndexPath) {
        print("Header was moved out of the screen.")
    }
}

But the function isn't called when I scroll month view. For test purpose, I add similar code for collecitonView(didEndDisplaying:) func and it isn't called either.

I wonder why? Am I miss something, or are cells and supplementary views in JTACMonthView not recycled for some reason? (I'm actually not 100% sure when the two funcs are supposed to be called but they are never called in my experiments.)

Background

I add a tappable UILabel to my calendar's month header. When user taps it, it shows a UIPickerView for user to switch year. However, there is nothing to prevent use scrolling the calendar when the picker is shown. So I want to get notification when user scrolls the calendar to dismiss the picker if it's shown The typical way to do it nowadays is to set viewcontroller's keyboarddismissmode property, but I find it dismiss custom input view only, not input accessory view. That's the reason why I'd like to implement collectionView(didEndDisplayingSupplementaryView:) in my app so I can call view.endEditing(true) to dismiss both input view and input accessory view.

rayx commented 4 years ago

I just realized that even if collectionView(didEndDisplayingSupplementaryView:) worked as what I expected, it wouldn't solve my issue because I need to differentiate calendar scrolling caused by user input from input view and by user manually. The function can't do that.

That said, I'll leave the issue open because I'm still curious why the func didn't get called.

devMoxie commented 4 years ago

Like the OP, I too may need to get a hook as to when a cell will end displaying similar to collectionView(_:didEndDisplaying:forItemAt:). Is this possible?

patchthecode commented 4 years ago

will take a look this weekend didEndDisplayingSupplementaryView

devMoxie commented 4 years ago

Just curious if anyone has a workaround for how I can implement collectionView(_:didEndDisplaying:forItemAt:) and collectionView(_:didEndDisplayingSupplementaryView:forElementOfKind:at:) for JTACMonthView cells?

patchthecode commented 4 years ago

Sorry for being late on this. But With the current situation. I am caught up.

devMoxie commented 4 years ago

No need to apologize! Here's what I've tried so far to no avail:

extension JTACMonthViewDelegate {
    func calendar(_ calendar: JTACMonthView, didEndDisplaying cell: JTACDayCell?, indexPath: IndexPath) {
        print(#function)
    }
}

extension JTACMonthView {
    public func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {

        guard let delegate = calendarDelegate else { return }
        let cell = collectionView.cellForItem(at: indexPath) as? JTACDayCell
        delegate.calendar(self, didEndDisplaying: cell, indexPath: indexPath)
    }
}