Permalink
Browse files

Manually merger pull request #47, "sortingDelegate additions: allow/d…

…isallow movement and insertion of items at certain index"
  • Loading branch information...
chadpod committed Aug 2, 2012
1 parent 1d9ad9d commit 96581cdce2d8781694a6564669679b882157a12f
Showing with 21 additions and 0 deletions.
  1. +5 −0 GMGridView/GMGridView.h
  2. +16 −0 GMGridView/GMGridView.m
View
@@ -172,6 +172,11 @@ typedef enum
// Enable/Disable the shaking behavior of an item being moved
- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowShakingBehaviorWhenMovingCell:(GMGridViewCell *)view atIndex:(NSInteger)index;
+// Allow/Disallow moving of an item
+- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view atIndex:(NSInteger)index;
+// Allow/Disallow placing item at index
+- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view toIndex:(NSInteger)index;
+
@end
//////////////////////////////////////////////////////////////
View
@@ -556,6 +556,14 @@ - (void)longPressGestureUpdated:(UILongPressGestureRecognizer *)longPressGesture
NSInteger position = [self.layoutStrategy itemPositionFromLocation:location];
+ // Ask the delegate if moving is permitted
+ if ([self.sortingDelegate respondsToSelector:@selector(GMGridView:shouldAllowMovingCell:atIndex:)])
+ {
+ GMGridViewCell *item = [self cellForItemAtIndex:position];
+ if (![self.sortingDelegate GMGridView:self shouldAllowMovingCell:item atIndex:position])
+ position = GMGV_INVALID_POSITION;
+ }
+
if (position != GMGV_INVALID_POSITION)
{
[self sortingMoveDidStartAtPoint:location];
@@ -775,6 +783,14 @@ - (void)sortingMoveDidContinueToPoint:(CGPoint)point
int position = [self.layoutStrategy itemPositionFromLocation:point];
int tag = position + kTagOffset;
+ // Ask the delegate if inserting item is permitted
+ if ([self.sortingDelegate respondsToSelector:@selector(GMGridView:shouldAllowMovingCell:toIndex:)])
+ {
+ GMGridViewCell *item = [self cellForItemAtIndex:position];
+ if (![self.sortingDelegate GMGridView:self shouldAllowMovingCell:item toIndex:position])
+ position = GMGV_INVALID_POSITION;
+ }
+
if (position != GMGV_INVALID_POSITION && position != _sortFuturePosition && position < _numberTotalItems)
{
BOOL positionTaken = NO;

0 comments on commit 96581cd

Please sign in to comment.