Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

sortingDelegate additions: allow/disallow movement and insertion of items at certain index #47

Open
wants to merge 3 commits into from

7 participants

Tim Trautmann Gulam Moledina ghrom Chad Podoski Roberto dvkch kushal bindra
Tim Trautmann

Extended the sortingDelegate with two more optional delegate methods:

- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view atIndex:(NSInteger)index; is called when a move is about to start. If this method returns NO, the move won't take place.

- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view toIndex:(NSInteger)index; is called when an item is moved to a new position in the grid. If this method returns NO, the insertion won't take place.

Tim Trautmann Bringo Added two new delegate methods to sortingDelegate that ask for
permission to move an item and to insert an item at a position.
23c4698
Tim Trautmann

Extended the sortingDelegate with two more optional delegate methods:

- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view atIndex:(NSInteger)index; is called when a move is about to start. If this method returns NO, the move won't take place.

- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowMovingCell:(GMGridViewCell *)view toIndex:(NSInteger)index; is called when an item is moved to a new position in the grid. If this method returns NO, the insertion won't take place.

Gulam Moledina
Owner

Thanks @Bringo. I'll review this with the new code base and merge.

ghrom

Will it be merged, please?

Chad Podoski

Also wondering if this will be merged soon. Thanks.

Chad Podoski chadpod referenced this pull request from a commit in shacked/GMGridView
Chad Podoski chadpod Manually merger pull request #47, "sortingDelegate additions: allow/d…
…isallow movement and insertion of items at certain index"
96581cd
Roberto

This feature is very interesting, when will it be merged?

dvkch

Still no news on when it'll be merged?

kushal bindra

ummmmmmm why not keep a simple bool for allowing dragging of cell and based on that flag add or remove the longtapgesture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 11, 2012
  1. Tim Trautmann

    Added two new delegate methods to sortingDelegate that ask for

    Bringo authored
    permission to move an item and to insert an item at a position.
Commits on Feb 12, 2012
  1. Tim Trautmann
Commits on Feb 29, 2012
  1. Tim Trautmann
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 4 deletions.
  1. +5 −1 GMGridView/API/GMGridView.h
  2. +32 −3 GMGridView/API/GMGridView.m
6 GMGridView/API/GMGridView.h
View
@@ -112,7 +112,7 @@ typedef enum
@optional
// Required to enable editing mode
- (void)GMGridView:(GMGridView *)gridView deleteItemAtIndex:(NSInteger)index;
-
+- (BOOL)GMGridView:(GMGridView *)gridView shouldEditItemAtIndex:(NSInteger)index;
@end
@@ -145,6 +145,10 @@ typedef enum
- (void)GMGridView:(GMGridView *)gridView didEndMovingCell:(GMGridViewCell *)cell;
// 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
35 GMGridView/API/GMGridView.m
View
@@ -353,9 +353,22 @@ - (void)setEditing:(BOOL)editing
&&![self isInTransformingState]
&& ((self.isEditing && !editing) || (!self.isEditing && editing)))
{
+ NSInteger index = 0;
for (GMGridViewCell *cell in [self itemSubviews])
{
- [cell setEditing:editing];
+ if (editing && [self.dataSource respondsToSelector:@selector(GMGridView:shouldEditItemAtIndex:)])
+ {
+ if ([self.dataSource GMGridView:self shouldEditItemAtIndex:index])
+ {
+ [cell setEditing:editing];
+ }
+ }
+ else
+ {
+ [cell setEditing:editing];
+ }
+
+ index++;
}
_editing = editing;
@@ -456,6 +469,14 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
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];
@@ -671,6 +692,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;
@@ -1389,12 +1418,12 @@ - (void)scrollToObjectAtIndex:(NSInteger)index animated:(BOOL)animated
CGSize pageSize = CGSizeMake(_scrollView.bounds.size.width - _scrollView.contentInset.left - _scrollView.contentInset.right,
_scrollView.bounds.size.height - _scrollView.contentInset.top - _scrollView.contentInset.bottom);
- while (originScroll.x + pageSize.width < origin.x)
+ while (originScroll.x + pageSize.width <= origin.x)
{
originScroll.x += pageSize.width;
}
- while (originScroll.y + pageSize.height < origin.y)
+ while (originScroll.y + pageSize.height <= origin.y)
{
originScroll.y += pageSize.height;
}
Something went wrong with that request. Please try again.