Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Calender finite #640

Closed
imJithin777 opened this issue May 19, 2022 · 1 comment
Closed

Make Calender finite #640

imJithin777 opened this issue May 19, 2022 · 1 comment

Comments

@imJithin777
Copy link

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

@ageevvalentin
Copy link
Contributor

ageevvalentin commented Jun 6, 2022

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)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants