Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd4ea23

Browse files
Peter Steinbergergmoledina
authored andcommitted
Cherry-pick changes from steipete
1 parent 0e851c7 commit cd4ea23

1 file changed

Lines changed: 39 additions & 39 deletions

File tree

GMGridView/API/GMGridView.m

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ - (BOOL)isInTransformingState;
104104

105105
// Helpers & more
106106
- (void)recomputeSize;
107-
- (void)relayoutItems;
107+
- (void)relayoutItemsAnimated:(BOOL)animated;
108108
- (NSArray *)itemSubviews;
109109
- (GMGridViewCell *)itemSubViewForPosition:(NSInteger)position;
110110
- (GMGridViewCell *)newItemSubViewForPosition:(NSInteger)position;
@@ -263,7 +263,7 @@ - (void)layoutSubviews
263263
[super layoutSubviews];
264264

265265
[self recomputeSize];
266-
[self relayoutItems];
266+
[self relayoutItemsAnimated:NO];
267267
[self loadRequiredItems];
268268

269269
[_scrollView flashScrollIndicators];
@@ -687,7 +687,7 @@ - (void)sortingMoveDidContinueToPoint:(CGPoint)point
687687
}
688688

689689
[self.sortingDelegate GMGridView:self moveItemAtIndex:_sortFuturePosition toIndex:position];
690-
[self relayoutItems];
690+
[self relayoutItemsAnimated:YES];
691691

692692
break;
693693
}
@@ -1029,24 +1029,17 @@ - (GMGridViewCell *)newItemSubViewForPosition:(NSInteger)position
10291029
CGPoint origin = [self.layoutStrategy originForItemAtPosition:position];
10301030
CGRect frame = CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height);
10311031

1032-
// To make sure the frame is not animated
1033-
[UIView animateWithDuration:0
1034-
delay:0
1035-
options:kDefaultAnimationOptions | UIViewAnimationOptionOverrideInheritedDuration
1036-
animations:^{
1037-
cell.frame = frame;
1038-
cell.contentView.frame = cell.bounds;
1039-
}
1040-
completion:nil];
1032+
cell.frame = frame;
1033+
cell.contentView.frame = cell.bounds;
10411034

10421035
cell.tag = position + kTagOffset;
10431036
cell.editing = self.editing;
10441037

10451038
__gm_weak GMGridView *weakSelf = self;
1046-
1047-
cell.deleteBlock = ^(GMGridViewCell *cell)
1039+
1040+
cell.deleteBlock = ^(GMGridViewCell *aCell)
10481041
{
1049-
NSInteger index = [weakSelf positionForItemSubview:cell];
1042+
NSInteger index = [weakSelf positionForItemSubview:aCell];
10501043
if (index != GMGV_INVALID_POSITION)
10511044
{
10521045
[weakSelf.dataSource GMGridView:self deleteItemAtIndex:index];
@@ -1133,31 +1126,38 @@ - (void)recomputeSize
11331126
completion:nil];
11341127
}
11351128

1136-
- (void)relayoutItems
1129+
- (void)relayoutItemsAnimated:(BOOL)animated
11371130
{
1138-
[UIView animateWithDuration:kDefaultAnimationDuration
1139-
delay:0
1140-
options:kDefaultAnimationOptions
1141-
animations:^{
1142-
1143-
for (UIView *view in [self itemSubviews])
1144-
{
1145-
if (view != _sortMovingItem && view != _transformingItem)
1146-
{
1147-
NSInteger index = view.tag - kTagOffset;
1148-
CGPoint origin = [self.layoutStrategy originForItemAtPosition:index];
1149-
CGRect newFrame = CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height);
1150-
1151-
// IF statement added for performance reasons (Time Profiling in instruments)
1152-
if (!CGRectEqualToRect(newFrame, view.frame))
1153-
{
1154-
view.frame = newFrame;
1155-
}
1156-
}
1131+
void (^layoutBlock)(void) = ^{
1132+
for (UIView *view in [self itemSubviews])
1133+
{
1134+
if (view != _sortMovingItem && view != _transformingItem)
1135+
{
1136+
NSInteger index = view.tag - kTagOffset;
1137+
CGPoint origin = [self.layoutStrategy originForItemAtPosition:index];
1138+
CGRect newFrame = CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height);
1139+
1140+
// IF statement added for performance reasons (Time Profiling in instruments)
1141+
if (!CGRectEqualToRect(newFrame, view.frame))
1142+
{
1143+
view.frame = newFrame;
1144+
}
1145+
}
1146+
}
1147+
};
1148+
1149+
if (animated) {
1150+
[UIView animateWithDuration:kDefaultAnimationDuration
1151+
delay:0
1152+
options:kDefaultAnimationOptions
1153+
animations:^{
1154+
layoutBlock();
11571155
}
1158-
}
1159-
completion:nil
1160-
];
1156+
completion:nil
1157+
];
1158+
}else {
1159+
layoutBlock();
1160+
}
11611161
}
11621162

11631163

@@ -1439,7 +1439,7 @@ - (void)removeObjectAtIndex:(NSInteger)index
14391439

14401440
self.firstPositionLoaded = self.lastPositionLoaded = GMGV_INVALID_POSITION;
14411441
[self loadRequiredItems];
1442-
[self relayoutItems];
1442+
[self relayoutItemsAnimated:YES];
14431443
}
14441444
];
14451445

0 commit comments

Comments
 (0)