Permalink
Browse files

Fixed some bugs relating to reorder-on-rotation and animating cells o…

…n and off-screen.
  • Loading branch information...
1 parent 1ab2696 commit d73c58c41e81cda76a63119b283b3212eb59dc8e @AlanQuatermain committed Apr 18, 2010
@@ -25,6 +25,8 @@
389782C8117A311B00D5CC8F /* AQGridViewUpdateItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 389782B6117A311B00D5CC8F /* AQGridViewUpdateItem.m */; };
389782C9117A311B00D5CC8F /* UIColor+AQGridView.h in Headers */ = {isa = PBXBuildFile; fileRef = 389782B7117A311B00D5CC8F /* UIColor+AQGridView.h */; };
389782CA117A311B00D5CC8F /* UIColor+AQGridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 389782B8117A311B00D5CC8F /* UIColor+AQGridView.m */; };
+ 389785BF117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.h in Headers */ = {isa = PBXBuildFile; fileRef = 389785BD117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.h */; };
+ 389785C0117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.m in Sources */ = {isa = PBXBuildFile; fileRef = 389785BE117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.m */; };
AA747D9F0F9514B9006C5449 /* AQGridView_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* AQGridView_Prefix.pch */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
/* End PBXBuildFile section */
@@ -53,6 +55,8 @@
389782CE117A314A00D5CC8F /* AQGridSelectionGrayBlue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AQGridSelectionGrayBlue.png; sourceTree = "<group>"; };
389782CF117A314A00D5CC8F /* AQGridSelectionGreen.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AQGridSelectionGreen.png; sourceTree = "<group>"; };
389782D0117A314A00D5CC8F /* AQGridSelectionRed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AQGridSelectionRed.png; sourceTree = "<group>"; };
+ 389785BD117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSIndexSet+AQIsSetContiguous.h"; sourceTree = "<group>"; };
+ 389785BE117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSIndexSet+AQIsSetContiguous.m"; sourceTree = "<group>"; };
AA747D9E0F9514B9006C5449 /* AQGridView_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AQGridView_Prefix.pch; sourceTree = SOURCE_ROOT; };
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
D2AAC07E0554694100DB518D /* libAQGridView.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAQGridView.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -128,6 +132,8 @@
389782B6117A311B00D5CC8F /* AQGridViewUpdateItem.m */,
389782B7117A311B00D5CC8F /* UIColor+AQGridView.h */,
389782B8117A311B00D5CC8F /* UIColor+AQGridView.m */,
+ 389785BD117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.h */,
+ 389785BE117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -162,6 +168,7 @@
389782C5117A311B00D5CC8F /* AQGridViewUpdateInfo.h in Headers */,
389782C7117A311B00D5CC8F /* AQGridViewUpdateItem.h in Headers */,
389782C9117A311B00D5CC8F /* UIColor+AQGridView.h in Headers */,
+ 389785BF117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -215,6 +222,7 @@
389782C6117A311B00D5CC8F /* AQGridViewUpdateInfo.m in Sources */,
389782C8117A311B00D5CC8F /* AQGridViewUpdateItem.m in Sources */,
389782CA117A311B00D5CC8F /* UIColor+AQGridView.m in Sources */,
+ 389785C0117AB2E600D5CC8F /* NSIndexSet+AQIsSetContiguous.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -40,6 +40,7 @@
#import "AQGridViewUpdateInfo.h"
#import "AQGridViewCell+AQGridViewCellPrivate.h"
#import "AQGridView+CellLocationDelegation.h"
+#import "NSIndexSet+AQIsSetContiguous.h"
// see _basicHitTest:withEvent: below
#import <objc/objc.h>
@@ -697,7 +698,16 @@ - (void) endUpdateAnimations
}
[_updateInfo cleanupUpdateItems];
+
+ [UIView beginAnimations: @"CellUpdates" context: nil];
+ [UIView setAnimationDelegate: self];
+ [UIView setAnimationDidStopSelector: @selector(cellUpdateAnimationStopped:finished:context:)];
+ [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
+ [UIView setAnimationDuration: 0.3];
+
self.animatingCells = [_updateInfo animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];
+
+ [UIView commitAnimations];
_flags.updating = 0;
[_gridData release];
@@ -706,10 +716,6 @@ - (void) endUpdateAnimations
_selectedIndex = [_updateInfo newIndexForOldIndex: _selectedIndex];
[_updateInfo release];
_updateInfo = nil;
-
- // if no animation occurred, this has already been done
- if ( _reloadingSuspendedCount == 0 )
- [self fixCellsFromAnimation];
}
- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context
@@ -1157,38 +1163,18 @@ - (void) updateVisibleGridCellsNow
// do we need to remove anything?
if ( [newVisibleIndices countOfIndexesInRange: _visibleIndices] < _visibleIndices.length )
{
- // remove the last few items
- NSUInteger numToRemove = 0;
- BOOL removeFromFront = NO;
- NSUInteger idx = (_visibleIndices.location + _visibleIndices.length) - 1;
- do
- {
- if ( [newVisibleIndices containsIndex: idx] )
- break;
-
- numToRemove++;
- idx--;
-
- } while ( idx != NSUIntegerMax );
-
- if ( numToRemove == 0 )
- {
- removeFromFront = YES;
- idx = _visibleIndices.location;
- while ( NSLocationInRange(idx, _visibleIndices) )
- {
- if ( [newVisibleIndices containsIndex: idx] )
- break;
-
- numToRemove++;
- idx++;
- }
- }
-
- if ( numToRemove == [_gridData numberOfItemsPerRow] )
- {
- // optimized version is possible
- NSRange arrayRange = {0, 0};
+ NSMutableIndexSet * indicesToRemove = [[NSMutableIndexSet alloc] initWithIndexesInRange: _visibleIndices];
+ [indicesToRemove removeIndexes: newVisibleIndices];
+ if ( [indicesToRemove aq_isSetContiguous] )
+ {
+ // nice simple optimized version
+ // front or back?
+ BOOL removeFromFront = NO;
+ if ( [indicesToRemove containsIndex: _visibleIndices.location] )
+ removeFromFront = YES;
+
+ NSUInteger numToRemove = [indicesToRemove count];
+ NSRange arrayRange = {0, 0};
if ( removeFromFront )
arrayRange = NSMakeRange(0, numToRemove);
else
@@ -1223,7 +1209,7 @@ - (void) updateVisibleGridCellsNow
[self enqueueReusableCells: removedCells];
// done removing cells
- }
+ }
else
{
// we need to be much more thorough-- a large number of items have been removed from all over
@@ -592,12 +592,6 @@ - (void) animateReloadForCell: (AQGridViewCell *) newCell originalCell: (AQGridV
- (NSArray *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
{
- [UIView beginAnimations: @"CellUpdates" context: nil];
- [UIView setAnimationDelegate: _gridView];
- [UIView setAnimationDidStopSelector: @selector(cellUpdateAnimationStopped:finished:context:)];
- [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
- [UIView setAnimationDuration: 0.3];
-
// we might need to change the new visible indices and content rect, if we're looking at the last row and it's going to disappear
CGFloat maxY = CGRectGetMaxY(contentRect);
if ( maxY > [_newGridData heightForEntireGrid] )
@@ -629,9 +623,13 @@ - (NSArray *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
if ( oldIndex != NSNotFound )
[oldIndicesOfAllVisibleCells addIndex: oldIndex];
}
+
+ NSMutableIndexSet * movingSet = [[NSMutableIndexSet alloc] initWithIndexSet: oldVisibleIndices];
+ [movingSet addIndexes: oldIndicesOfAllVisibleCells];
+ [oldIndicesOfAllVisibleCells release];
// most items were just moved from one location to another
- for ( NSUInteger oldIndex = [oldIndicesOfAllVisibleCells firstIndex]; oldIndex != NSNotFound; oldIndex = [oldIndicesOfAllVisibleCells indexGreaterThanIndex: oldIndex] )
+ for ( NSUInteger oldIndex = [movingSet firstIndex]; oldIndex != NSNotFound; oldIndex = [movingSet indexGreaterThanIndex: oldIndex] )
{
NSUInteger newIndex = _oldToNewIndexMap[oldIndex];
AQGridViewCell * cell = [_gridView cellForItemAtIndex: oldIndex];
@@ -643,7 +641,10 @@ - (NSArray *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
}
if ( newIndex == NSNotFound )
+ {
+ NSLog( @"index %u is going away" );
continue;
+ }
if ( cell == nil )
{
@@ -666,7 +667,7 @@ - (NSArray *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
[_gridView delegateWillDisplayCell: cell atIndex: newIndex];
}
- [oldIndicesOfAllVisibleCells release];
+ [movingSet release];
// delete old items first
if ( _deleteItems.count != 0 )
@@ -717,7 +718,6 @@ - (NSArray *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
[newVisibleCells addObject: newCell];
}
- [UIView commitAnimations];
return ( [newVisibleCells autorelease] );
}
@@ -0,0 +1,14 @@
+//
+// NSIndexSet+AQIsSetContiguous.h
+// AQGridView
+//
+// Created by Jim Dovey on 10-04-17.
+// Copyright 2010 Kobo Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSIndexSet (AQIsSetContiguous)
+- (BOOL) aq_isSetContiguous;
+@end
@@ -0,0 +1,18 @@
+//
+// NSIndexSet+AQIsSetContiguous.m
+// AQGridView
+//
+// Created by Jim Dovey on 10-04-17.
+// Copyright 2010 Kobo Inc. All rights reserved.
+//
+
+#import "NSIndexSet+AQIsSetContiguous.h"
+
+@implementation NSIndexSet (AQIsSetContiguous)
+
+- (BOOL) aq_isSetContiguous
+{
+ return ( (([self lastIndex] - [self firstIndex]) + 1) == [self count] );
+}
+
+@end

0 comments on commit d73c58c

Please sign in to comment.