rechsteiner / Parchment

A paging view with a highly customizable menu ✨
MIT License
3.39k stars 419 forks source link

Make Calender finite #640

Closed imJithin777 closed 2 years ago

imJithin777 commented 2 years ago

Can the calendar become finite which starts from today's date to future dates and remove the past days

ageevvalentin commented 2 years ago

Try to return nil for the "after" and "before" items if the new date is out your date range.

extension ViewController: PagingViewControllerInfiniteDataSource {
  func pagingViewController(_: PagingViewController, itemAfter pagingItem: PagingItem) -> PagingItem? {
    let calendarItem = pagingItem as! CalendarItem
    let endDate  = // Your end date
    let afterDate = calendarItem.date.addingTimeInterval(86400)
    guard afterDate <= endDate else { return nil }
    return CalendarItem(date: afterDate)
  }

  func pagingViewController(_: PagingViewController, itemBefore pagingItem: PagingItem) -> PagingItem? {
    let calendarItem = pagingItem as! CalendarItem
    let startDate = // Your start date
    let beforeDate = calendarItem.date.addingTimeInterval(-86400)
    guard beforeDate => startDate else { return nil }
    return CalendarItem(date: beforeDate)
  }

  func pagingViewController(_: PagingViewController, viewControllerFor pagingItem: PagingItem) -> UIViewController {
    let calendarItem = pagingItem as! CalendarItem
    return CalendarViewController(date: calendarItem.date)
  }
}