CalendarKit
CalendarKit copied to clipboard
Enhancement Request: Min Date and Max Date
It would be good to add support for a minimum and maximum date so that the pager wouldn't scroll past these values?
I may delve into the source code myself if I get the time. I envisage this as a single additional function added to the DayViewDelegate
for open func dayView(dayView: DayView, canMoveTo date: Date)
. Are there any pitfalls I should be aware of if I was to approach it like this, please?
Hi @jameswwwebster, thank you for the feature request!
I'd suggest adding it to an additional protocol, separate from the delegate
and the datasource
.
Otherwise, it looks good.
As for detailed ideas on the implementation, I see these steps are needed to make a change:
- Make
PagingScrollView
support locking in directions (add support for similar function as you described) - nowPagingScrollView
scrolls infinitely in both directions. - Add support of the following function to the
DayView
- Add support for the function to the
DayHeaderView
- Link all the components together, so they could be controlled from the single delegate.
Has this been implemented yet? If not, is there sometime we can expect it to be ready, and is there any workaround? I specifically have a DayView
in a horizontal UICollectionView
, so the superfluous swiping between days is interfering with the UICollectionView
.
Hi @danielVebman, For your solution to work you need to embed TimelineContainer with Timeline, not DayView in the CollectionView. I.e. Recreate the DayView on your own. Why would you want to put the DayView inside of the CollectionView?
As per your questions:
- Not implemented
- Not planned, there are no workaround
- Issue is open and it may be implemented some day.
Thanks for your response @richardtop.
If I embed a Timeline
in a TimelineContainer
, how can I set the timeline's data or frame? This doesn't seem to work:
timelineView = TimelineView()
timelineView?.frame = bounds
timelineContainer = TimelineContainer(timelineView!)
timelineContainer?.frame = bounds
timelineContainer?.scrollToFirstEvent()
// set dataSource or directly assign Events??
addSubview(timelineContainer!)
I am trying to put the timeline in a collection view because I have a horizontal set of panels, and one of the panels has the user's schedule for the day in it.
@danielVebman could you post a mockup of the result you're trying to achieve?
@richardtop, Iām trying to get it to look like this, where that drawn part is the timeline view showing the events for just the current day:
https://drive.google.com/file/d/1SpS9wb7kARwrUlld7VLIEuXlthks3luY/view?usp=drivesdk
@danielVebman then you'll absolutely need to re-create your own Calendar from available elements. Take a look at how "DayView" manages its child views and configures events taken from the DataSource.
@richardtop, ok I got it working perfectly except for one thing: on the iPhone X/XS/XS max, I can't get rid of the inset at the bottom of the TimelineContainer
. I tried going into TimelineContainer
's layoutSubviews
and changed it to this:
override public func layoutSubviews() {
timeline.frame = CGRect(x: 0, y: 0, width: width, height: timeline.fullHeight)
timeline.offsetAllDayView(by: contentOffset.y)
//adjust the scroll insets
let allDayViewHeight = timeline.allDayViewHeight
let bottomSafeInset: CGFloat
if #available(iOS 11.0, *) {
// I thought this was the line causing the problems, so I commented it out:
// bottomSafeInset = window?.safeAreaInsets.bottom ?? 0
bottomSafeInset = 0
} else {
bottomSafeInset = 0
}
scrollIndicatorInsets = UIEdgeInsets(top: allDayViewHeight, left: 0, bottom: bottomSafeInset, right: 0)
contentInset = UIEdgeInsets(top: allDayViewHeight, left: 0, bottom: bottomSafeInset, right: 0)
}
However, that has no effect. I searched through the framework, and there is no other place besides the above function where contentInset
appears. What am I missing?
@danielVebman please, post both the screenshots of the results working correctly and incorrectly.

The image above shows what it looks like now and how it should be. As the scrollIndicator indicates, the container scroll area ends too high up whereas it should extend to the bottom of the panel.
@danielVebman also could you post the view hierarchy debugger screenshot with the clipping disabled.
Let me know if you prefer a different angle:


Did you do clean build after replacing the code? That might be the cause too. On the surface, everything looks right.
Wow, that actually did it. In retrospect command-K is always a good thing to try. Thanks for your help!
@danielVebman that's the common cause when working with CocoaPods. I recommend you create your custom subclass of TimelineContainer and override layoutSubviews
method to the one you need.
I see your app using CK in the way I envisioned - to build your own custom calendar UI based on these components. I'd like to try it when it's ready / in beta.
Thank you. I would be happy to have you as a beta tester when the time comes. Unfortunately, God only knows when that'll be!
@danielVebman send me an invite on LinkedIn or an email. Both are listed on my Github page.
I think this is what you need. let style = CalendarStyle() let timeline = style.timeline timeline.verticalDiff = 90 //play here dayView.updateStyle(style)