CalendarKit icon indicating copy to clipboard operation
CalendarKit copied to clipboard

Enhancement Request: Min Date and Max Date

Open jameswwwebster opened this issue 7 years ago ā€¢ 18 comments

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?

jameswwwebster avatar May 12 '17 09:05 jameswwwebster

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:

  1. Make PagingScrollView support locking in directions (add support for similar function as you described) - now PagingScrollView scrolls infinitely in both directions.
  2. Add support of the following function to the DayView
  3. Add support for the function to the DayHeaderView
  4. Link all the components together, so they could be controlled from the single delegate.

richardtop avatar May 13 '17 17:05 richardtop

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.

danielVebman avatar Nov 02 '18 22:11 danielVebman

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:

  1. Not implemented
  2. Not planned, there are no workaround
  3. Issue is open and it may be implemented some day.

richardtop avatar Nov 03 '18 05:11 richardtop

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 avatar Nov 03 '18 13:11 danielVebman

@danielVebman could you post a mockup of the result you're trying to achieve?

richardtop avatar Nov 03 '18 23:11 richardtop

@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 avatar Nov 04 '18 01:11 danielVebman

@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 avatar Nov 04 '18 13:11 richardtop

@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 avatar Nov 04 '18 19:11 danielVebman

@danielVebman please, post both the screenshots of the results working correctly and incorrectly.

richardtop avatar Nov 05 '18 01:11 richardtop

screenshot

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 avatar Nov 05 '18 02:11 danielVebman

@danielVebman also could you post the view hierarchy debugger screenshot with the clipping disabled.

richardtop avatar Nov 05 '18 02:11 richardtop

Let me know if you prefer a different angle:

screen shot 2018-11-04 at 9 33 47 pm screen shot 2018-11-04 at 9 34 10 pm

danielVebman avatar Nov 05 '18 02:11 danielVebman

Did you do clean build after replacing the code? That might be the cause too. On the surface, everything looks right.

richardtop avatar Nov 05 '18 03:11 richardtop

Wow, that actually did it. In retrospect command-K is always a good thing to try. Thanks for your help!

danielVebman avatar Nov 05 '18 03:11 danielVebman

@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.

richardtop avatar Nov 05 '18 03:11 richardtop

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 avatar Nov 05 '18 03:11 danielVebman

@danielVebman send me an invite on LinkedIn or an email. Both are listed on my Github page.

richardtop avatar Nov 05 '18 03:11 richardtop

I think this is what you need. let style = CalendarStyle() let timeline = style.timeline timeline.verticalDiff = 90 //play here dayView.updateStyle(style)

ouberghouz avatar Oct 15 '19 13:10 ouberghouz