Permalink
Browse files

Tweaks to reloading a very small view to prevent infinite loops

  • Loading branch information...
1 parent 53753d5 commit 42359d6851801e51c2fb754756cacefedbc7c9ee @pieteromvlee pieteromvlee committed Aug 19, 2011
Showing with 14 additions and 3 deletions.
  1. +8 −0 BCCollectionView.m
  2. +5 −2 BCCollectionViewLayoutManager.m
  3. +1 −1 BCCollectionViewLayoutOperation.m
View
@@ -488,6 +488,10 @@ - (void)reloadDataWithItems:(NSArray *)newContent groups:(NSArray *)newGroups em
if (!delegate)
return;
+ NSSize cellSize = [delegate cellSizeForCollectionView:self];
+ if (NSWidth([self frame]) < cellSize.width || NSHeight([self frame]) < cellSize.height)
+ return;
+
for (BCCollectionViewGroup *group in groups)
[group removeObserver:self forKeyPath:@"isCollapsed"];
for (BCCollectionViewGroup *group in newGroups)
@@ -553,6 +557,10 @@ - (void)viewDidResize
- (void)softReloadDataWithCompletionBlock:(dispatch_block_t)block
{
+ NSSize cellSize = [delegate cellSizeForCollectionView:self];
+ if (NSWidth([self visibleRect]) < cellSize.width || NSHeight([self visibleRect]) < cellSize.height)
+ return;
+
NSRange range = [self rangeOfVisibleItemsWithOverflow];
[layoutManager enumerateItems:^(BCCollectionViewLayoutItem *layoutItem) {
if (NSLocationInRange([layoutItem itemIndex], range)) {
@@ -62,8 +62,11 @@ - (NSSize)cellSize
- (NSPoint)rowAndColumnPositionOfItemAtIndex:(NSUInteger)anIndex
{
- BCCollectionViewLayoutItem *itemLayout = [itemLayouts objectAtIndex:anIndex];
- return NSMakePoint(itemLayout.columnIndex, itemLayout.rowIndex);
+ if ([itemLayouts count] > anIndex) {
+ BCCollectionViewLayoutItem *itemLayout = [itemLayouts objectAtIndex:anIndex];
+ return NSMakePoint(itemLayout.columnIndex, itemLayout.rowIndex);
+ } else
+ return NSZeroPoint;
}
- (NSUInteger)indexOfItemAtRow:(NSUInteger)rowIndex column:(NSUInteger)colIndex
@@ -25,7 +25,7 @@ - (void)main
NSSize inset = NSZeroSize;
NSInteger maxColumns = [[collectionView layoutManager] maximumNumberOfItemsPerRow];
NSUInteger gap = (NSWidth([collectionView frame]) - maxColumns*cellSize.width)/(maxColumns-1);
- if (maxColumns < 4) {
+ if (maxColumns < 4 && maxColumns > 1) {
gap = (NSWidth([collectionView frame]) - maxColumns*cellSize.width)/(maxColumns+1);
startingX = gap;
x = gap;

0 comments on commit 42359d6

Please sign in to comment.