From 5f2ba5a63f109747802255fa0d98ecfcf4bbf086 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Wed, 14 Jun 2017 09:41:15 +0200 Subject: [PATCH] UX Rework - Rooms tab: Tap on the current tab's icon jumps to next unread. --- Riot/ViewController/MasterTabBarController.m | 11 ++++++ Riot/ViewController/RoomsViewController.h | 6 ++++ Riot/ViewController/RoomsViewController.m | 36 ++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/Riot/ViewController/MasterTabBarController.m b/Riot/ViewController/MasterTabBarController.m index fdf9b8882..680e01dd6 100644 --- a/Riot/ViewController/MasterTabBarController.m +++ b/Riot/ViewController/MasterTabBarController.m @@ -674,4 +674,15 @@ [currentAlert showInViewController:self]; } +#pragma mark - UITabBarDelegate + +- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item +{ + if (item.tag == TABBAR_ROOMS_INDEX && self.selectedIndex == TABBAR_ROOMS_INDEX) + { + // Scroll to the next room with missed notifications. + [self.roomsViewController scrollToNextRoomWithMissedNotifications]; + } +} + @end diff --git a/Riot/ViewController/RoomsViewController.h b/Riot/ViewController/RoomsViewController.h index 65e9da3e8..3a05fa351 100644 --- a/Riot/ViewController/RoomsViewController.h +++ b/Riot/ViewController/RoomsViewController.h @@ -21,4 +21,10 @@ */ @interface RoomsViewController : RecentsViewController +/** + Scroll to the potential room with missed notifications which is not visible yet. + */ +- (void)scrollToNextRoomWithMissedNotifications; + + @end diff --git a/Riot/ViewController/RoomsViewController.m b/Riot/ViewController/RoomsViewController.m index cc0b27f0c..c8f20bd77 100644 --- a/Riot/ViewController/RoomsViewController.m +++ b/Riot/ViewController/RoomsViewController.m @@ -125,6 +125,42 @@ } } +#pragma mark - + +- (void)scrollToNextRoomWithMissedNotifications +{ + // Check whether the recents data source is correctly configured. + if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModeRooms) + { + return; + } + + NSIndexPath *lastVisibleIndexPath = self.recentsTableView.indexPathsForVisibleRows.lastObject; + if (lastVisibleIndexPath.section == recentsDataSource.conversationSection) + { + // Look for the next room with missed notifications. + NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:lastVisibleIndexPath.row + 1 inSection:recentsDataSource.conversationSection]; + id cellData = [recentsDataSource cellDataAtIndexPath:nextIndexPath]; + + while (cellData) + { + if (cellData.notificationCount) + { + [self.recentsTableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; + break; + } + nextIndexPath = [NSIndexPath indexPathForRow:nextIndexPath.row + 1 inSection:recentsDataSource.conversationSection]; + cellData = [recentsDataSource cellDataAtIndexPath:nextIndexPath]; + } + + if (!cellData) + { + // Scroll back to the top. + [self.recentsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:recentsDataSource.conversationSection] atScrollPosition:UITableViewScrollPositionTop animated:YES]; + } + } +} + #pragma mark - Navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender