BugFix: Sliding animation on recents entries can be quite stuttery #162

Recents refresh is now blocked when a recent cell is in editing mode.
This commit is contained in:
giomfo
2016-03-17 23:31:30 +01:00
parent 9673e14af3
commit 7da31788d6
2 changed files with 63 additions and 18 deletions
+61 -16
View File
@@ -35,6 +35,12 @@
// The "parent" segmented view controller
HomeViewController *homeViewController;
// The room identifier related to the cell which is in editing mode (if any).
NSString *swipedCellRoomId;
// Tell whether a recents refresh is pending (suspended during editing mode).
BOOL isRefreshPending;
// recents drag and drop management
UIImageView *cellSnapshot;
NSIndexPath* movingCellPath;
@@ -153,6 +159,43 @@
#pragma mark - Internal methods
- (void)refreshRecentsTable
{
if (swipedCellRoomId)
{
// Check whether the user didn't leave the room
MXRoom *room = [self.mainSession roomWithRoomId:swipedCellRoomId];
if (room)
{
isRefreshPending = YES;
return;
}
else
{
// Cancel the editing mode
swipedCellRoomId = nil;
}
}
isRefreshPending = NO;
[self.recentsTableView reloadData];
if (_shouldScrollToTopOnRefresh)
{
[self scrollToTop];
_shouldScrollToTopOnRefresh = NO;
}
// In case of split view controller where the primary and secondary view controllers are displayed side-by-side on screen,
// the selected room (if any) is updated and kept visible.
// Note: 'isCollapsed' property is available in UISplitViewController for iOS 8 and later.
if (self.splitViewController && (![self.splitViewController respondsToSelector:@selector(isCollapsed)] || !self.splitViewController.isCollapsed))
{
[self refreshCurrentSelectedCell:YES];
}
}
- (void)scrollToTop
{
// Stop any scrolling effect before scrolling to the tableview top
@@ -255,26 +298,28 @@
};
}
[self.recentsTableView reloadData];
if (_shouldScrollToTopOnRefresh)
{
[self scrollToTop];
_shouldScrollToTopOnRefresh = NO;
}
// In case of split view controller where the primary and secondary view controllers are displayed side-by-side on screen,
// the selected room (if any) is updated and kept visible.
// Note: 'isCollapsed' property is available in UISplitViewController for iOS 8 and later.
if (self.splitViewController && (![self.splitViewController respondsToSelector:@selector(isCollapsed)] || !self.splitViewController.isCollapsed))
{
[self refreshCurrentSelectedCell:YES];
}
[self refreshRecentsTable];
}
#pragma mark - swipe actions
// for IOS >= 8 devices
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
// Report the room identifier of the edited cell.
id<MXKRecentCellDataStoring> cellData = [self.dataSource cellDataAtIndexPath:indexPath];
swipedCellRoomId = cellData.roomDataSource.roomId;
}
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
swipedCellRoomId = nil;
if (isRefreshPending)
{
[self refreshRecentsTable];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray* actions = [[NSMutableArray alloc] init];