Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jwilling/JNWCollectionView
Browse files Browse the repository at this point in the history
…into cell-binding
  • Loading branch information
Deadpikle committed Sep 19, 2016
2 parents 9ced2b4 + 6724b19 commit e5d4c38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 7 additions & 5 deletions JNWCollectionView/JNWCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ - (void)updateLayer {

@interface JNWCollectionViewCell()
@property (nonatomic, strong) JNWCollectionViewCellBackgroundView *backgroundView;
@property (nonatomic, strong) NSTrackingArea *trackingArea;
@end

@implementation JNWCollectionViewCell
Expand Down Expand Up @@ -120,13 +121,14 @@ - (void)didLayoutWithFrame:(CGRect)frame {

- (void)updateTrackingAreas {
[super updateTrackingAreas];
[[self.trackingAreas copy] enumerateObjectsUsingBlock:^(NSTrackingArea * _Nonnull trackingArea, NSUInteger idx, BOOL * _Nonnull stop) {
[self removeTrackingArea:trackingArea];
}];
if (self.trackingArea) {
[self removeTrackingArea:self.trackingArea];
self.trackingArea = nil;
}

NSTrackingAreaOptions options = (NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil];
[self addTrackingArea:area];
self.trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil];
[self addTrackingArea:self.trackingArea];
}

- (NSView *)contentView {
Expand Down
15 changes: 15 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#import "JNWCollectionViewLayout.h"
#import "JNWCollectionViewLayout+Private.h"

#ifndef NSAppKitVersionNumber10_11
#define NSAppKitVersionNumber10_11 1404
#endif

typedef NS_ENUM(NSInteger, JNWCollectionViewSelectionType) {
JNWCollectionViewSelectionTypeSingle,
JNWCollectionViewSelectionTypeExtending,
Expand Down Expand Up @@ -654,6 +658,17 @@ - (void)layout {
}
}

- (void)reflectScrolledClipView:(NSClipView*)clipView {
[super reflectScrolledClipView:clipView];

// 10.12 started optimizing the layout pass and reducing the number of calls to layout(). As
// such, invalidate our layout when the scroll changes on 10.12 and above.
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_11) {
// Invalidate our layout when we our scrolled. This is required for 10.12 and above.
self.needsLayout = YES;
}
}

- (void)collectionViewLayoutWasInvalidated:(JNWCollectionViewLayout *)layout {
// First we prepare the layout. In the future it would possibly be a good idea to coalesce
// this call to reduce unnecessary layout preparation calls.
Expand Down
3 changes: 2 additions & 1 deletion JNWCollectionView/JNWCollectionViewGridLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ - (NSRange)rowsInRect:(CGRect)rect fromSection:(JNWCollectionViewGridLayoutSecti
CGFloat relativeRectTop = MAX(0, CGRectGetMinY(rect) - section.offset);
CGFloat relativeRectBottom = CGRectGetMaxY(rect) - section.offset;
NSInteger rowBegin = relativeRectTop / (self.itemSize.height + self.verticalSpacing);
NSInteger rowEnd = floorf(relativeRectBottom / self.itemSize.height);
NSInteger rowsInRect = ceil(rect.size.height / (self.itemSize.height + self.verticalSpacing));
NSInteger rowEnd = floorf(rowBegin+rowsInRect);
return NSMakeRange(rowBegin, 1 + rowEnd - rowBegin);
}

Expand Down

0 comments on commit e5d4c38

Please sign in to comment.