Skip to content

Commit

Permalink
Refractions
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Jan 21, 2017
1 parent d5363b9 commit 56bb990
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 45 deletions.
6 changes: 6 additions & 0 deletions Example-Objc/DIYCalendarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ - (void)layoutSubviews
}
}

- (void)configureAppearance
{
[super configureAppearance];
self.eventIndicator.hidden = self.placeholder; // Hide the event indicator for placeholder cells
}

- (void)setSelectionType:(SelectionType)selectionType
{
if (_selectionType != selectionType) {
Expand Down
3 changes: 0 additions & 3 deletions Example-Objc/DIYExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ - (void)configureCell:(FSCalendarCell *)cell forDate:(NSDate *)date atMonthPosit
// Configure selection layer
if (monthPosition == FSCalendarMonthPositionCurrent || self.calendar.scope == FSCalendarScopeWeek) {

diyCell.eventIndicator.hidden = NO;

SelectionType selectionType = SelectionTypeNone;
if ([self.calendar.selectedDates containsObject:date]) {
NSDate *previousDate = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:-1 toDate:date options:0];
Expand Down Expand Up @@ -223,7 +221,6 @@ - (void)configureCell:(FSCalendarCell *)cell forDate:(NSDate *)date atMonthPosit

diyCell.circleImageView.hidden = YES;
diyCell.selectionLayer.hidden = YES;
diyCell.eventIndicator.hidden = YES; // Hide default event indicator
if ([self.calendar.selectedDates containsObject:date]) {
diyCell.titleLabel.textColor = self.calendar.appearance.titlePlaceholderColor; // Prevent placeholders from changing text color
}
Expand Down
2 changes: 1 addition & 1 deletion FSCalendar.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "FSCalendar"
s.version = "2.7.0"
s.version = "2.7.1"
s.summary = "A superiorly awesome iOS7+ calendar control, compatible with Objective-C and Swift."

s.homepage = "https://github.com/WenchaoD/FSCalendar"
Expand Down
35 changes: 8 additions & 27 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ @interface FSCalendar ()<UICollectionViewDataSource, UICollectionViewDelegate, U
@property (assign, nonatomic) BOOL needsConfigureAppearance;
@property (assign, nonatomic) BOOL needsLayoutForWeekMode;
@property (assign, nonatomic) BOOL needsRequestingBoundingDates;
@property (assign, nonatomic) BOOL supressEvent;
@property (assign, nonatomic) CGFloat preferredHeaderHeight;
@property (assign, nonatomic) CGFloat preferredWeekdayHeight;
@property (assign, nonatomic) CGFloat preferredRowHeight;
Expand Down Expand Up @@ -130,7 +129,6 @@ - (void)requestBoundingDatesIfNecessary;
@implementation FSCalendar

@dynamic selectedDate;
@synthesize scrollDirection = _scrollDirection, firstWeekday = _firstWeekday, appearance = _appearance;
@synthesize scopeGesture = _scopeGesture, swipeToChooseGesture = _swipeToChooseGesture;

#pragma mark - Life Cycle && Initialize
Expand Down Expand Up @@ -189,6 +187,7 @@ - (void)initialize
_pagingEnabled = YES;
_scrollEnabled = YES;
_needsAdjustingViewFrame = YES;
_needsConfigureAppearance = YES;
_orientation = self.currentCalendarOrientation;
_placeholderType = FSCalendarPlaceholderTypeFillSixRows;

Expand Down Expand Up @@ -304,8 +303,6 @@ - (void)layoutSubviews
{
[super layoutSubviews];

_supressEvent = YES;

if (_needsAdjustingViewFrame) {
_needsAdjustingViewFrame = NO;

Expand Down Expand Up @@ -379,7 +376,6 @@ - (void)layoutSubviews
_needsLayoutForWeekMode = NO;
[self.transitionCoordinator performScopeTransitionFromScope:FSCalendarScopeMonth toScope:FSCalendarScopeWeek animated:NO];
}
_supressEvent = NO;

}

Expand Down Expand Up @@ -527,10 +523,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
[cell performSelecting];
}
[self enqueueSelectedDate:selectedDate];
if (!_supressEvent) {
FSCalendarMonthPosition monthPosition = [self.calculator monthPositionForIndexPath:indexPath];
[self.delegateProxy calendar:self didSelectDate:selectedDate atMonthPosition:monthPosition];
}
[self.delegateProxy calendar:self didSelectDate:selectedDate atMonthPosition:monthPosition];
[self selectCounterpartDate:selectedDate];
}

Expand Down Expand Up @@ -562,9 +555,7 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex
[cell configureAppearance];

[_selectedDates removeObject:selectedDate];
if (!_supressEvent) {
[self.delegateProxy calendar:self didDeselectDate:selectedDate atMonthPosition:monthPosition];
}
[self.delegateProxy calendar:self didDeselectDate:selectedDate atMonthPosition:monthPosition];
[self deselectCounterpartDate:selectedDate];

}
Expand All @@ -587,7 +578,7 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementa

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (_supressEvent || !self.window) return;
if (!self.window) return;
if (self.floatingMode && _collectionView.indexPathsForVisibleItems.count) {
// Do nothing on bouncing
if (_collectionView.contentOffset.y < 0 || _collectionView.contentOffset.y > _collectionView.contentSize.height-_collectionView.fs_height) {
Expand Down Expand Up @@ -719,8 +710,6 @@ - (void)setScrollDirection:(FSCalendarScrollDirection)scrollDirection

switch (_scope) {
case FSCalendarScopeMonth: {
_supressEvent = YES;

_collectionViewLayout.scrollDirection = (UICollectionViewScrollDirection)scrollDirection;
_calendarHeaderView.scrollDirection = _collectionViewLayout.scrollDirection;
if (self.hasValidateVisibleLayout) {
Expand All @@ -729,7 +718,6 @@ - (void)setScrollDirection:(FSCalendarScrollDirection)scrollDirection
}
_needsAdjustingViewFrame = YES;
[self setNeedsLayout];
_supressEvent = NO;
break;
}
case FSCalendarScopeWeek: {
Expand Down Expand Up @@ -1151,7 +1139,7 @@ - (void)selectDate:(NSDate *)date scrollToDate:(BOOL)scrollToDate atMonthPositio
NSDate *targetDate = [self.gregorian dateBySettingHour:0 minute:0 second:0 ofDate:date options:0];
NSIndexPath *targetIndexPath = [self.calculator indexPathForDate:targetDate];

BOOL shouldSelect = !_supressEvent;
BOOL shouldSelect = YES;
// 跨月份点击
if (monthPosition==FSCalendarMonthPositionPrevious||monthPosition==FSCalendarMonthPositionNext) {
if (self.allowsMultipleSelection) {
Expand Down Expand Up @@ -1226,7 +1214,6 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated
return;
}
animated &= _scrollEnabled; // No animation if _scrollEnabled == NO;
_supressEvent = !animated;

date = [self.calculator safeDateForDate:date];
NSInteger scrollOffset = [self.calculator indexPathForDate:date atMonthPosition:FSCalendarMonthPositionCurrent].section;
Expand Down Expand Up @@ -1259,7 +1246,6 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated
if (!animated) {
self.calendarHeaderView.scrollOffset = scrollOffset;
}
_supressEvent = NO;
}

- (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated
Expand All @@ -1284,13 +1270,11 @@ - (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated
break;
}
}
if (!_supressEvent && self.hasValidateVisibleLayout) {
_supressEvent = YES;
if (self.hasValidateVisibleLayout) {
[self.delegateProxy calendarCurrentPageDidChange:self];
if (_placeholderType != FSCalendarPlaceholderTypeFillSixRows && self.transitionCoordinator.state == FSCalendarTransitionStateIdle) {
[self.transitionCoordinator performBoundingRectTransitionFromMonth:lastPage toMonth:_currentPage duration:0.33];
}
_supressEvent = NO;
}
[self didChangeValueForKey:@"currentPage"];
}
Expand Down Expand Up @@ -1385,8 +1369,8 @@ - (void)registerMainRunloopObserver

void FSCalendarRunLoopCallback(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
FSCalendar *calendar = (__bridge FSCalendar *)(info);
if ([calendar fs_boolVariableForKey:@"_needsConfigureAppearance"]) {
[calendar fs_setBoolVariable:NO forKey:@"_needsConfigureAppearance"];
if (calendar.needsConfigureAppearance) {
calendar.needsConfigureAppearance = NO;
[calendar.visibleCells makeObjectsPerformSelector:@selector(configureAppearance)];
[calendar.visibleStickyHeaders makeObjectsPerformSelector:@selector(configureAppearance)];
[calendar.calendarHeaderView configureAppearance];
Expand Down Expand Up @@ -1670,8 +1654,6 @@ - (void)invalidateViewFrames
_preferredWeekdayHeight = FSCalendarAutomaticDimension;
_preferredRowHeight = FSCalendarAutomaticDimension;

[self.collectionViewLayout invalidateLayout];
[self.collectionViewLayout layoutAttributesForElementsInRect:CGRectZero];
[self.calendarHeaderView setNeedsAdjustingViewFrame:YES];
[self setNeedsLayout];

Expand All @@ -1691,7 +1673,6 @@ - (FSCalendarOrientation)currentCalendarOrientation
- (void)adjustMonthPosition
{
[self requestBoundingDatesIfNecessary];
_supressEvent = NO;
NSDate *targetPage = self.pagingEnabled?self.currentPage:(self.currentPage?:self.selectedDate);
[self scrollToPageForDate:targetPage animated:NO];
self.calendarHeaderView.needsAdjustingMonthPosition = YES;
Expand Down
8 changes: 2 additions & 6 deletions FSCalendar/FSCalendarCollectionViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,15 @@ - (void)prepareLayout
CGFloat *heights = malloc(rowSize);
if (!self.calendar.floatingMode) {
CGFloat contentHeight = self.collectionView.fs_height - self.sectionInsets.top - self.sectionInsets.bottom;
for (int i = 0; i < rowCount; i++) {
NSInteger currentCount = rowCount-i;
CGFloat actualHeight = FSCalendarRound(contentHeight/currentCount*2)*0.5;
contentHeight -= actualHeight;
heights[i] = actualHeight;
}
FSCalendarSliceCake(contentHeight, rowCount, heights);
} else {
for (int i = 0; i < rowCount; i++) {
heights[i] = self.estimatedItemSize.height;
}
}
heights;
});

free(self.tops);
self.tops = ({
NSInteger rowCount = self.calendar.transitionCoordinator.representingScope == FSCalendarScopeWeek ? 1 : 6;
Expand Down
5 changes: 4 additions & 1 deletion FSCalendar/FSCalendarHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ - (void)setScrollOffset:(CGFloat)scrollOffset animated:(BOOL)animated

- (void)scrollToOffset:(CGFloat)scrollOffset animated:(BOOL)animated
{
[self layoutIfNeeded];
if (CGSizeEqualToSize(self.collectionView.contentSize, CGSizeZero)) {
_needsAdjustingMonthPosition = YES;
return;
}
if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) {
CGFloat step = self.collectionView.fs_width*((self.scrollDirection==UICollectionViewScrollDirectionHorizontal)?0.5:1);
[_collectionView setContentOffset:CGPointMake((scrollOffset+0.5)*step, 0) animated:animated];
Expand Down
6 changes: 0 additions & 6 deletions FSCalendar/FSCalendarWeekdayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ - (void)layoutSubviews

}

- (void)setCalendar:(FSCalendar *)calendar
{
_calendar = calendar;
[self configureAppearance];
}

- (void)configureAppearance
{
BOOL useVeryShortWeekdaySymbols = (self.calendar.appearance.caseOptions & (15<<4) ) == FSCalendarCaseOptionsWeekdayUsesSingleUpperCase;
Expand Down
2 changes: 1 addition & 1 deletion FSCalendar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.7.0</string>
<string>2.7.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit 56bb990

Please sign in to comment.