Better scope transition behavior
1. Better scope transition behavior 2. Remove redundant lines 3. Improve example
This commit is contained in:
parent
dc83a35a18
commit
cd44c39f4b
|
|
@ -94,7 +94,7 @@
|
|||
|
||||
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
|
||||
{
|
||||
return [calendar dateWithYear:2016 month:5 day:31];
|
||||
return [calendar dateWithYear:2039 month:5 day:31];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -303,9 +303,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_collectionView.frame = _daysContainer.bounds;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
|
@ -372,8 +370,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
if (self.collectionViewLayout.state == FSCalendarTransitionStateInProgress) {
|
||||
return [self sizeThatFits:size scope:FSCalendarScopeMonth];
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return [self sizeThatFits:size scope:FSCalendarScopeWeek];
|
||||
}
|
||||
|
|
@ -395,9 +391,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
CGFloat height = weekdayHeight + headerHeight + rowHeight + paddings;
|
||||
return CGSizeMake(size.width, height);
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return CGSizeMake(size.width, self.fs_height);
|
||||
|
|
@ -411,22 +404,13 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
{
|
||||
if (self.collectionViewLayout.transition == FSCalendarTransitionWeekToMonth) {
|
||||
return [self monthsFromDate:[self beginingOfMonthOfDate:_minimumDate] toDate:_maximumDate] + 1;
|
||||
} else {
|
||||
NSInteger sections;
|
||||
switch (_scope) {
|
||||
case FSCalendarScopeMonth:
|
||||
sections = [self monthsFromDate:[self beginingOfMonthOfDate:_minimumDate] toDate:_maximumDate] + 1;
|
||||
break;
|
||||
case FSCalendarScopeWeek:
|
||||
sections = [self weeksFromDate:[self beginingOfWeekOfDate:_minimumDate] toDate:_maximumDate] + 1;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
|
||||
switch (_scope) {
|
||||
case FSCalendarScopeMonth:
|
||||
return [self monthsFromDate:[self beginingOfMonthOfDate:_minimumDate] toDate:_maximumDate] + 1;
|
||||
case FSCalendarScopeWeek:
|
||||
return [self weeksFromDate:[self beginingOfWeekOfDate:_minimumDate] toDate:_maximumDate] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
|
|
@ -442,8 +426,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
case FSCalendarScopeWeek: {
|
||||
return 7;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
NSDate *currentPage = [self dateByAddingMonths:section toDate:[self beginingOfMonthOfDate:_minimumDate]];
|
||||
|
|
@ -623,9 +605,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
scrollOffset = scrollView.contentOffset.y/scrollView.fs_height;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_header.scrollOffset = scrollOffset;
|
||||
}
|
||||
|
|
@ -652,9 +631,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
contentSize = scrollView.fs_height;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
BOOL shouldTriggerPageChange = ((pannedOffset < 0 && targetOffset > currentOffset) ||
|
||||
(pannedOffset > 0 && targetOffset < currentOffset)) && _minimumDate;
|
||||
|
|
@ -671,9 +647,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_currentPage = [self dateByAddingWeeks:targetOffset/contentSize toDate:minimumPage];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
[self currentPageDidChange];
|
||||
[self didChangeValueForKey:@"currentPage"];
|
||||
|
|
@ -731,9 +704,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
case FSCalendarScopeWeek: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -771,9 +741,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_currentPage = [self beginingOfWeekOfDate:today];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_needsAdjustingMonthPosition = YES;
|
||||
[self setNeedsLayout];
|
||||
|
|
@ -986,9 +953,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_preferedRowHeight = contentHeight-padding*2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_preferedRowHeight = FSCalendarStandardRowHeight*MAX(1, FSCalendarDeviceIsIPad*1.5);
|
||||
|
|
@ -1194,9 +1158,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
scrollOffset = [self weeksFromDate:[self beginingOfWeekOfDate:_minimumDate] toDate:targetDate];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!self.floatingMode) {
|
||||
|
|
@ -1210,9 +1171,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
[_collectionView setContentOffset:CGPointMake(scrollOffset * _collectionView.fs_width, 0) animated:animated];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -1254,9 +1212,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_currentPage = [self beginingOfWeekOfDate:date];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!_supressEvent && self.hasValidateVisibleLayout) {
|
||||
_supressEvent = YES;
|
||||
|
|
@ -1291,8 +1246,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
NSUInteger daysOffset = indexPath.item;
|
||||
return [self dateByAddingDays:daysOffset toDate:firstDateOfPage];
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1300,9 +1253,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
NSDate *currentPage = [self dateByAddingWeeks:indexPath.section toDate:[self beginingOfWeekOfDate:_minimumDate]];
|
||||
return [self dateByAddingDays:indexPath.item toDate:currentPage];
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
|
@ -1338,8 +1288,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
item = [self daysFromDate:firstDateOfPage toDate:date];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1348,9 +1296,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
item = (([self weekdayOfDate:date] - _firstWeekday) + 7) % 7;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [NSIndexPath indexPathForItem:item inSection:section];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,37 +215,28 @@
|
|||
|
||||
case FSCalendarTransitionWeekToMonth: {
|
||||
|
||||
NSInteger focusedRowNumber = -1;
|
||||
NSInteger focusedRowNumber = 0;
|
||||
NSDate *currentPage = self.calendar.currentPage;
|
||||
if (focusedRowNumber == -1) {
|
||||
NSDate *firstDayOfMonth = [self.calendar beginingOfMonthOfDate:[self.calendar dateByAddingMonths:1 toDate:currentPage]];
|
||||
NSInteger weekdayOfFirstDay = [self.calendar weekdayOfDate:firstDayOfMonth];
|
||||
NSInteger numberOfPlaceholdersForPrev = ((weekdayOfFirstDay - self.calendar.firstWeekday) + 7) % 7 ?: 7;
|
||||
NSDate *firstDateOfPage = [self.calendar dateBySubstractingDays:numberOfPlaceholdersForPrev fromDate:firstDayOfMonth];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
NSDate *currentRow = [self.calendar dateByAddingWeeks:i toDate:firstDateOfPage];
|
||||
if ([self.calendar date:currentRow sharesSameDayWithDate:currentPage]) {
|
||||
focusedRowNumber = i;
|
||||
currentPage = firstDayOfMonth;
|
||||
break;
|
||||
}
|
||||
NSDate *firstDayOfMonth = nil;
|
||||
if (self.calendar.focusOnSingleSelectedDate && self.calendar.selectedDate) {
|
||||
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:[self.calendar indexPathForDate:self.calendar.selectedDate scope:FSCalendarScopeWeek]];
|
||||
CGPoint selectedCenter = attributes.center;
|
||||
if (CGRectContainsPoint(self.collectionView.bounds, selectedCenter)) {
|
||||
firstDayOfMonth = [self.calendar beginingOfMonthOfDate:self.calendar.selectedDate];
|
||||
}
|
||||
}
|
||||
if (focusedRowNumber == -1) {
|
||||
NSDate *firstDayOfMonth = [self.calendar beginingOfMonthOfDate:currentPage];
|
||||
NSInteger weekdayOfFirstDay = [self.calendar weekdayOfDate:firstDayOfMonth];
|
||||
NSInteger numberOfPlaceholdersForPrev = ((weekdayOfFirstDay - self.calendar.firstWeekday) + 7) % 7 ?: 7;
|
||||
NSDate *firstDateOfPage = [self.calendar dateBySubstractingDays:numberOfPlaceholdersForPrev fromDate:firstDayOfMonth];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
NSDate *currentRow = [self.calendar dateByAddingWeeks:i toDate:firstDateOfPage];
|
||||
if ([self.calendar date:currentRow sharesSameDayWithDate:currentPage]) {
|
||||
focusedRowNumber = i;
|
||||
currentPage = firstDayOfMonth;
|
||||
break;
|
||||
}
|
||||
firstDayOfMonth = firstDayOfMonth ?: [self.calendar beginingOfMonthOfDate:currentPage];
|
||||
NSInteger weekdayOfFirstDay = [self.calendar weekdayOfDate:firstDayOfMonth];
|
||||
NSInteger numberOfPlaceholdersForPrev = ((weekdayOfFirstDay - self.calendar.firstWeekday) + 7) % 7 ?: 7;
|
||||
NSDate *firstDateOfPage = [self.calendar dateBySubstractingDays:numberOfPlaceholdersForPrev fromDate:firstDayOfMonth];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
NSDate *currentRow = [self.calendar dateByAddingWeeks:i toDate:firstDateOfPage];
|
||||
if ([self.calendar date:currentRow sharesSameDayWithDate:currentPage]) {
|
||||
focusedRowNumber = i;
|
||||
currentPage = firstDayOfMonth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
focusedRowNumber = MAX(0, focusedRowNumber);
|
||||
|
||||
[self.calendar _setCurrentPage:currentPage];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue