Permalink
Browse files

Fixes paging issues, updated images and caching improvements

  • Loading branch information...
1 parent cd43601 commit e94ce75b825f117ce76b3215953612b06b3c8830 @pieteromvlee pieteromvlee committed Mar 4, 2011
View
@@ -77,4 +77,6 @@
- (NSIndexSet *)indexesOfViewControllers;
- (NSIndexSet *)indexesOfInvisibleViewControllers;
- (NSViewController *)viewControllerForItemAtIndex:(NSUInteger)index;
+
+- (void)softReloadData;
@end
View
@@ -44,7 +44,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
if ([self respondsToSelector:@selector(zoomValueDidChange)])
[self performSelector:@selector(zoomValueDidChange)];
} else if ([keyPath isEqualToString:@"isCollapsed"]) {
- [self performSelector:@selector(viewDidResize)];
+ [self softReloadData];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
[self performSelector:@selector(scrollViewDidScroll:)];
});
@@ -476,8 +476,10 @@ - (void)resizeFrameToFitContents
{
NSRect frame = [self frame];
frame.size.height = [self visibleRect].size.height;
- if ([contentArray count] > 0)
- frame.size.height = MAX(frame.size.height, NSMaxY([layoutManager rectOfItemAtIndex:[contentArray count]-1]));
+ if ([contentArray count] > 0) {
+ BCCollectionViewLayoutItem *layoutItem = [[layoutManager itemLayouts] lastObject];
+ frame.size.height = MAX(frame.size.height, NSMaxY([layoutItem itemRect]));
+ }
[self setFrame:frame];
}
@@ -501,30 +503,29 @@ - (void)reloadDataWithItems:(NSArray *)newContent groups:(NSArray *)newGroups em
self.groups = newGroups;
self.contentArray = newContent;
- [layoutManager enumerateItems:NULL completionBlock:^{
- [self resizeFrameToFitContents];
-
- if (shouldEmptyCaches) {
- for (NSViewController *viewController in [visibleViewControllers allValues]) {
- [[viewController view] removeFromSuperview];
- if ([delegate respondsToSelector:@selector(collectionView:viewControllerBecameInvisible:)])
- [delegate collectionView:self viewControllerBecameInvisible:viewController];
- }
-
- for (NSViewController *viewController in [visibleGroupViewControllers allValues])
- [[viewController view] removeFromSuperview];
-
- [reusableViewControllers removeAllObjects];
- [visibleViewControllers removeAllObjects];
- [visibleGroupViewControllers removeAllObjects];
- } else
- [self softReloadVisibleViewControllers];
+ if (shouldEmptyCaches) {
+ for (NSViewController *viewController in [visibleViewControllers allValues]) {
+ [[viewController view] removeFromSuperview];
+ if ([delegate respondsToSelector:@selector(collectionView:viewControllerBecameInvisible:)])
+ [delegate collectionView:self viewControllerBecameInvisible:viewController];
+ }
- [selectionIndexes removeAllIndexes];
+ for (NSViewController *viewController in [visibleGroupViewControllers allValues])
+ [[viewController view] removeFromSuperview];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self addMissingViewControllersToView];
- });
+ [reusableViewControllers removeAllObjects];
+ [visibleViewControllers removeAllObjects];
+ [visibleGroupViewControllers removeAllObjects];
+ } else
+ [self softReloadVisibleViewControllers];
+
+ [selectionIndexes removeAllIndexes];
+
+ [layoutManager enumerateItems:^(BCCollectionViewLayoutItem *layoutItem) {
+ [self addMissingViewControllerForItemAtIndex:[layoutItem itemIndex] withFrame:[layoutItem itemRect]];
+ } completionBlock:^{
+ NSLog(@"reload done (content count: %i)", (int)[contentArray count]);
+ [self resizeFrameToFitContents];
}];
}
@@ -546,13 +547,17 @@ - (void)scrollViewDidScroll:(NSNotification *)note
- (void)viewDidResize
{
+ if ([contentArray count] > 0)
+ [self softReloadData];
+}
+
+- (void)softReloadData
+{
NSRect visibleRect = [self visibleRect];
[layoutManager enumerateItems:^(BCCollectionViewLayoutItem *layoutItem) {
BOOL shouldBeVisible = NSIntersectsRect([layoutItem itemRect], visibleRect);
if (shouldBeVisible) {
NSViewController *controller = [self viewControllerForItemAtIndex:[layoutItem itemIndex]];
-// if (controller && ![[controller view] superview])
-// NSLog(@"nooooo");
if (controller)
[[controller view] setFrame:[layoutItem itemRect]];
else
@@ -27,7 +27,7 @@ - (void)enumerateItems:(BCCollectionViewLayoutOperationIterator)itemIterator com
BCCollectionViewLayoutOperation *operation = [[BCCollectionViewLayoutOperation alloc] init];
[operation setCollectionView:collectionView];
[operation setLayoutCallBack:itemIterator];
- [operation setCompletionBlock:completionBlock];
+ [operation setLayoutCompletionBlock:completionBlock];
[queue addOperation:[operation autorelease]];
}
@@ -10,9 +10,11 @@ typedef void(^BCCollectionViewLayoutOperationIterator)(BCCollectionViewLayoutIte
@interface BCCollectionViewLayoutOperation : NSOperation
{
BCCollectionViewLayoutOperationIterator layoutCallBack;
+ dispatch_block_t layoutCompletionBlock;
BCCollectionView *collectionView;
}
@property (copy) BCCollectionViewLayoutOperationIterator layoutCallBack;
+@property (copy) dispatch_block_t layoutCompletionBlock;
@property (assign) BCCollectionView *collectionView;
@end
@@ -8,7 +8,7 @@
#import "BCCollectionViewLayoutManager.h"
@implementation BCCollectionViewLayoutOperation
-@synthesize layoutCallBack, collectionView;
+@synthesize layoutCallBack, collectionView, layoutCompletionBlock;
- (void)main
{
@@ -17,7 +17,7 @@ - (void)main
NSInteger x = 0;
NSInteger y = 0;
NSUInteger colIndex = 0;
-
+ NSRect visibleRect = [collectionView visibleRect];
NSSize cellSize = [collectionView cellSize];
NSSize inset = NSZeroSize;
if ([[collectionView delegate] respondsToSelector:@selector(insetMarginForSelectingItemsInCollectionView:)])
@@ -44,7 +44,7 @@ - (void)main
BCCollectionViewLayoutItem *item = [BCCollectionViewLayoutItem layoutItem];
[item setItemIndex:i];
if (![group isCollapsed]) {
- if (x + cellSize.width > NSMaxX([collectionView visibleRect])) {
+ if (x + cellSize.width > NSMaxX(visibleRect)) {
numberOfRows++;
colIndex = 0;
y += cellSize.height;
@@ -79,13 +79,15 @@ - (void)main
if (![self isCancelled]) {
dispatch_async(dispatch_get_main_queue(), ^{
[[collectionView layoutManager] setItemLayouts:newLayouts];
+ layoutCompletionBlock();
});
}
}
- (void)dealloc
{
[layoutCallBack release];
+ [layoutCompletionBlock release];
[super dealloc];
}

0 comments on commit e94ce75

Please sign in to comment.