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

Add method for checking date visibility. Improve scrolling method to consider if header is pinned. #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions TimesSquare/TSQCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
*/
@property (nonatomic, strong) Class rowCellClass;

/** Returns whether the date's month is currently visible.

Call this to check whether a given date is in the section currently scrolled to.

@param date the date to be checked.
@return whether the date is the currently active section.
*/
- (BOOL)isDateVisible:(NSDate *)date;

/** Scrolls the receiver until the specified date month is completely visible.

@param date A date that identifies the month that will be visible.
Expand Down
18 changes: 16 additions & 2 deletions TimesSquare/TSQCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,24 @@ - (void)setSelectedDate:(NSDate *)newSelectedDate;
}
}

- (BOOL)isDateVisible:(NSDate *)date
{
NSIndexPath *dateIndexPath = [self indexPathForRowAtDate:date];
NSArray *visibleRows = self.tableView.indexPathsForVisibleRows;
if ([visibleRows containsObject:dateIndexPath]) return YES;
return NO;
}

- (void)scrollToDate:(NSDate *)date animated:(BOOL)animated
{
NSInteger section = [self sectionForDate:date];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:animated];
NSIndexPath *dateIndexPath;
if (self.pinsHeaderToTop) {
NSInteger section = [self sectionForDate:date];
dateIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
} else {
dateIndexPath = [self indexPathForRowAtDate:date];
}
[self.tableView scrollToRowAtIndexPath:dateIndexPath atScrollPosition:UITableViewScrollPositionTop animated:animated];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about this particular change, as it represents a break from backwards compatibility. Are you using a calendar view that's not big enough to display the whole month at once?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am, yes. I think deferring to "pinsHeaderToTop" makes consistent and expected behavior. Otherwise "scrollToDate" is just "scrollToMonth". I can see how it wouldn't matter so much if you display the whole month.

}

- (TSQCalendarMonthHeaderCell *)makeHeaderCellWithIdentifier:(NSString *)identifier;
Expand Down