Skip to content

Commit

Permalink
[RSDFDatePickerView] [scrollViewWillBeginDragging] Fix shifting dates…
Browse files Browse the repository at this point in the history
… when pagination is enabled.

Fixes #141.
  • Loading branch information
ruslanskorb committed Sep 8, 2018
1 parent 13bfbcb commit ef2c069
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions RSDayFlow/RSDFDatePickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
}
});
Expand Down

0 comments on commit ef2c069

Please sign in to comment.