Skip to content

Commit

Permalink
day planner view: better handling of timed-events layout invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
jumartin committed Nov 8, 2016
1 parent 3a5efd5 commit cbf7a49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions CalendarLib/MGCDayPlannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ - (void)reloadDimmedTimeRanges

MGCTimedEventsViewLayoutInvalidationContext *context = [MGCTimedEventsViewLayoutInvalidationContext new];
context.invalidatedSections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfLoadedDays)];
context.invalidateEventCells = NO;
context.invalidateDimmingViews = YES;
[self.timedEventsView.collectionViewLayout invalidateLayoutWithContext:context];
}
Expand Down
3 changes: 2 additions & 1 deletion CalendarLib/MGCTimedEventsViewLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static NSString* const DimmingViewKind = @"DimmingViewKind";
@interface MGCTimedEventsViewLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext

@property (nonatomic) BOOL invalidateDimmingViews; // set to true if layout attributes of dimming views must be recomputed
@property (nonatomic) NSMutableIndexSet *invalidatedSections; // sections whose layout attributes must be recomputed
@property (nonatomic) BOOL invalidateEventCells; // set to true if layout attributes of event cells must be recomputed
@property (nonatomic) NSMutableIndexSet *invalidatedSections; // sections whose layout attributes (dimming views or event cells) must be recomputed - if nil, recompute everything

@end

Expand Down
15 changes: 6 additions & 9 deletions CalendarLib/MGCTimedEventsViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ @implementation MGCTimedEventsViewLayoutInvalidationContext
- (instancetype)init {
if (self = [super init]) {
self.invalidateDimmingViews = NO;
self.invalidateEventCells = YES;
}
return self;
}
Expand Down Expand Up @@ -273,15 +274,15 @@ - (void)invalidateLayoutWithContext:(MGCTimedEventsViewLayoutInvalidationContext

}

if (context.invalidateEverything) {
if (context.invalidateEverything || context.invalidatedSections == nil) {
self.layoutInfo = nil;
}
else {
[context.invalidatedSections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
if (context.invalidateDimmingViews) {
[self.layoutInfo removeObjectForKey:@(idx)];
[[self.layoutInfo objectForKey:@(idx)]removeObjectForKey:DimmingViewsKey];
}
else {
if (context.invalidateEventCells) {
[[self.layoutInfo objectForKey:@(idx)]removeObjectForKey:EventCellsKey];
}
}];
Expand All @@ -291,12 +292,8 @@ - (void)invalidateLayoutWithContext:(MGCTimedEventsViewLayoutInvalidationContext
- (void)invalidateLayout
{
//NSLog(@"invalidateLayout");

if (!self.ignoreNextInvalidation) {
self.layoutInfo = nil;
}

[super invalidateLayout];
[super invalidateLayout];
}

- (CGSize)collectionViewContentSize
Expand Down Expand Up @@ -325,7 +322,7 @@ - (NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
NSDictionary *layoutDic = [self layoutAttributesForSection:day];
NSArray *attribs = [[layoutDic objectForKey:DimmingViewsKey]arrayByAddingObjectsFromArray:[layoutDic objectForKey:EventCellsKey]];

for (MGCEventCellLayoutAttributes *a in attribs) {
for (UICollectionViewLayoutAttributes *a in attribs) {
if (CGRectIntersectsRect(rect, a.frame)) {
#ifdef BUG_FIX
CGRect frame = a.frame;
Expand Down

0 comments on commit cbf7a49

Please sign in to comment.