Skip to content

Commit f244390

Browse files
Merge pull request #15 from Yalantis/feature/fix_menu_crash_when_scroll_on_appear
Fix menu crash when user scroll menu before it complete appear
2 parents c887257 + 021b1f9 commit f244390

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

YALContextMenu/YALContextMenuTableView.m

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,34 @@ - (void)updateAlongsideRotation {
151151
#pragma mark - Private
152152

153153
- (void)show:(BOOL)show visibleCellsAnimated:(BOOL)animated {
154-
NSArray *visibleCells = [self visibleCells];
154+
NSArray *visibleCellsIndexPahts = [self indexPathsForVisibleRows];
155+
NSInteger firstVisibleRowIndex = [(NSIndexPath *)visibleCellsIndexPahts.firstObject row];
156+
NSInteger lastVisibleRowIndex = [(NSIndexPath *)visibleCellsIndexPahts.lastObject row];
155157

156-
if (visibleCells.count == 0 || self.animatingIndex == visibleCells.count) {
158+
if (visibleCellsIndexPahts.count == 0 || self.animatingIndex > lastVisibleRowIndex) {
157159
self.animatingIndex = 0;
158160
[self setUserInteractionEnabled:YES];
159161
[self reloadData];
160162
self.animatingState = Stable;
161163
return;
162164
}
163165

164-
UITableViewCell<YALContextMenuCell> *visibleCell = [visibleCells objectAtIndex:self.animatingIndex];
166+
NSIndexPath *animatingIndexPath = [NSIndexPath indexPathForRow:self.animatingIndex inSection:0];
167+
UITableViewCell<YALContextMenuCell> *visibleCell = (UITableViewCell<YALContextMenuCell> *)[self cellForRowAtIndexPath:animatingIndexPath];
165168
if (visibleCell) {
166169
[self prepareCellForShowAnimation:visibleCell];
167170
[visibleCell contentView].hidden = NO;
168-
Direction direction = ([visibleCells indexOfObject:visibleCell] == 0) ? right : top;
171+
Direction direction = (self.animatingIndex == firstVisibleRowIndex) ? right : top;
169172

170173
[self show:show cell:visibleCell animated:animated direction:direction clockwise:NO completion:^(BOOL completed) {
171-
if (completed) {
172-
self.animatingIndex++;
173-
[self show:show visibleCellsAnimated:animated];
174-
}
174+
// ignore flag 'completed', cause if user scroll out animating cell, it will be false and menu will be empty(
175+
self.animatingIndex++;
176+
[self show:show visibleCellsAnimated:animated];
175177
}];
178+
} else {
179+
// user scroolled animatingCell, so animate from first visible again
180+
self.animatingIndex = firstVisibleRowIndex;
181+
[self show:show visibleCellsAnimated:animated];
176182
}
177183
}
178184

0 commit comments

Comments
 (0)