Skip to content
Permalink
Browse files

[RSDFDatePickerView] [scrollViewWillBeginDragging] Fix shifting dates…

… when pagination is enabled.

Fixes #141.
  • Loading branch information...
ruslanskorb committed Sep 8, 2018
1 parent 13bfbcb commit ef2c06959ffcea84696c4a228fa697e17d14986f
Showing with 38 additions and 5 deletions.
  1. +38 −5 RSDayFlow/RSDFDatePickerView.m
@@ -910,12 +910,45 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.isPagingEnabled) {
if (!self.startDate && scrollView.contentOffset.y < CGRectGetHeight(scrollView.bounds) * 2) {
[self appendPastDates];
NSArray *sortedIndexPathsForVisibleItems = nil;

if (!self.startDate) {
sortedIndexPathsForVisibleItems = [self.collectionView.indexPathsForVisibleItems sortedArrayUsingSelector:@selector(compare:)];

NSIndexPath *firstVisibleItemIndexPath = sortedIndexPathsForVisibleItems.firstObject;
if (firstVisibleItemIndexPath != nil) {
NSDate *dateForFirstDayInSection = [self dateForFirstDayInSection:firstVisibleItemIndexPath.section];

NSDateComponents *dateComponents = [self.calendar components:NSCalendarUnitMonth
fromDate:self.fromDate
toDate:dateForFirstDayInSection
options:0];

if (dateComponents.month < 2) {

[self appendPastDates];
}
}
}

if (!self.endDate && scrollView.contentOffset.y + CGRectGetHeight(scrollView.bounds) * 2 > scrollView.contentSize.height) {
[self appendFutureDates];

if (!self.endDate) {
if (sortedIndexPathsForVisibleItems == nil) {
sortedIndexPathsForVisibleItems = [self.collectionView.indexPathsForVisibleItems sortedArrayUsingSelector:@selector(compare:)];
}

NSIndexPath *lastVisibleItemIndexPath = sortedIndexPathsForVisibleItems.lastObject;
if (lastVisibleItemIndexPath != nil) {
NSDate *dateForFirstDayInSection = [self dateForFirstDayInSection:lastVisibleItemIndexPath.section];

NSDateComponents *dateComponents = [self.calendar components:NSCalendarUnitMonth
fromDate:dateForFirstDayInSection
toDate:self.toDate
options:0];
if (dateComponents.month < 2) {

[self appendFutureDates];
}
}
}
}
});

0 comments on commit ef2c069

Please sign in to comment.
You can’t perform that action at this time.