diff --git a/Riot/Modules/Room/RoomCoordinator.swift b/Riot/Modules/Room/RoomCoordinator.swift index d5c029106..a87a752e9 100644 --- a/Riot/Modules/Room/RoomCoordinator.swift +++ b/Riot/Modules/Room/RoomCoordinator.swift @@ -79,18 +79,23 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol { } // MARK: - Public - + func start() { - + self.start(withCompletion: nil) + } + + // NOTE: Completion closure has been added for legacy architecture purpose. + // Remove this completion after LegacyAppDelegate refactor. + func start(withCompletion completion: (() -> Void)?) { self.roomViewController.delegate = self // Detect when view controller has been dismissed by gesture when presented modally (not in full screen). self.roomViewController.presentationController?.delegate = self if let eventId = self.selectedEventId { - self.start(with: self.parameters.roomId, and: eventId) + self.start(with: self.parameters.roomId, and: eventId, completion: completion) } else { - self.start(with: self.parameters.roomId) + self.start(with: self.parameters.roomId, completion: completion) } // Add `roomViewController` to the NavigationRouter, only if it has been explicity set as parameter @@ -102,17 +107,15 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol { } } } - - /// Use this method when the room screen is already shown and you want to go to a specific event. - /// i.e User tap on push notification message for the current displayed room - func start(withEventId eventId: String) { + + func start(withEventId eventId: String, completion: (() -> Void)?) { self.selectedEventId = eventId if self.hasStartedOnce { - self.start(with: self.parameters.roomId, and: eventId) + self.start(with: self.parameters.roomId, and: eventId, completion: completion) } else { - self.start() + self.start(withCompletion: completion) } } @@ -122,7 +125,7 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol { // MARK: - Private - private func start(with roomId: String) { + private func start(with roomId: String, completion: (() -> Void)?) { // Present activity indicator when retrieving roomDataSource for given room ID self.activityIndicatorPresenter.presentActivityIndicator(on: roomViewController.view, animated: false) @@ -141,10 +144,12 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol { if let roomDataSource = roomDataSource { self.roomViewController.displayRoom(roomDataSource) } + + completion?() }) } - private func start(with roomId: String, and eventId: String) { + private func start(with roomId: String, and eventId: String, completion: (() -> Void)?) { // Present activity indicator when retrieving roomDataSource for given room ID self.activityIndicatorPresenter.presentActivityIndicator(on: roomViewController.view, animated: false) @@ -169,6 +174,8 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol { // Give the data source ownership to the room view controller. self.roomViewController.hasRoomDataSourceOwnership = true + + completion?() } } } diff --git a/Riot/Modules/Room/RoomCoordinatorProtocol.swift b/Riot/Modules/Room/RoomCoordinatorProtocol.swift index 856323167..afb7d6d31 100644 --- a/Riot/Modules/Room/RoomCoordinatorProtocol.swift +++ b/Riot/Modules/Room/RoomCoordinatorProtocol.swift @@ -29,5 +29,20 @@ protocol RoomCoordinatorDelegate: AnyObject { protocol RoomCoordinatorProtocol: Coordinator, Presentable, RoomIdentifiable { var delegate: RoomCoordinatorDelegate? { get } + // Indicate if the underlying RoomDataSource can be released var canReleaseRoomDataSource: Bool { get } + + /// Start the Coordinator with a setup completion. + /// NOTE: Completion closure has been added for legacy architecture purpose. + /// Remove this completion after LegacyAppDelegate refactor. + /// - Parameters: + /// - completion: called when the RoomDataSource has finish to load. + func start(withCompletion completion: (() -> Void)?) + + /// Use this method when the room screen is already shown and you want to go to a specific event. + /// i.e User tap on push notification message for the current displayed room + /// - Parameters: + /// - eventId: The id of the event to display. + /// - completion: called when the RoomDataSource has finish to load. + func start(withEventId eventId: String, completion: (() -> Void)?) } diff --git a/Riot/Modules/TabBar/MasterTabBarController.h b/Riot/Modules/TabBar/MasterTabBarController.h index 8a0addf1c..92d064685 100644 --- a/Riot/Modules/TabBar/MasterTabBarController.h +++ b/Riot/Modules/TabBar/MasterTabBarController.h @@ -202,7 +202,7 @@ typedef NS_ENUM(NSUInteger, MasterTabBarIndex) { - (void)masterTabBarControllerDidCompleteAuthentication:(MasterTabBarController *)masterTabBarController; - (void)masterTabBarController:(MasterTabBarController*)masterTabBarController needsSideMenuIconWithNotification:(BOOL)displayNotification; -- (void)masterTabBarController:(MasterTabBarController *)masterTabBarController didSelectRoomWithId:(NSString*)roomId andEventId:(NSString*)eventId inMatrixSession:(MXSession*)matrixSession; +- (void)masterTabBarController:(MasterTabBarController *)masterTabBarController didSelectRoomWithId:(NSString*)roomId andEventId:(NSString*)eventId inMatrixSession:(MXSession*)matrixSession completion:(void (^)(void))completion; - (void)masterTabBarController:(MasterTabBarController *)masterTabBarController didSelectRoomPreviewWithData:(RoomPreviewData*)roomPreviewData; - (void)masterTabBarController:(MasterTabBarController *)masterTabBarController didSelectContact:(MXKContact*)contact; - (void)masterTabBarController:(MasterTabBarController *)masterTabBarController didSelectGroup:(MXGroup*)group inMatrixSession:(MXSession*)matrixSession; diff --git a/Riot/Modules/TabBar/MasterTabBarController.m b/Riot/Modules/TabBar/MasterTabBarController.m index 95ce63432..84c3098b6 100644 --- a/Riot/Modules/TabBar/MasterTabBarController.m +++ b/Riot/Modules/TabBar/MasterTabBarController.m @@ -587,15 +587,9 @@ _selectedRoomId = roomId; _selectedEventId = eventId; - _selectedRoomSession = matrixSession; + _selectedRoomSession = matrixSession; - [self.masterTabBarDelegate masterTabBarController:self didSelectRoomWithId:roomId andEventId:eventId inMatrixSession:matrixSession]; - - // TODO: Add completion to delegate - if (completion) - { - completion(); - } + [self.masterTabBarDelegate masterTabBarController:self didSelectRoomWithId:roomId andEventId:eventId inMatrixSession:matrixSession completion:completion]; [self refreshSelectedControllerIfNeeded]; } diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index 547e96eb4..667afc744 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -388,14 +388,14 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { self.showRoom(with: roomId, eventId: nil, matrixSession: matrixSession) } - private func showRoom(with roomId: String, eventId: String?, matrixSession: MXSession) { + private func showRoom(with roomId: String, eventId: String?, matrixSession: MXSession, completion: (() -> Void)? = nil) { // RoomCoordinator will be presented by the split view // We don't which navigation controller instance will be used // Give the NavigationRouterStore instance and let it find the associated navigation controller if needed let roomCoordinatorParameters = RoomCoordinatorParameters(navigationRouterStore: NavigationRouterStore.shared, session: matrixSession, roomId: roomId, eventId: eventId) - self.showRoom(with: roomCoordinatorParameters) + self.showRoom(with: roomCoordinatorParameters, completion: completion) } private func showRoomPreview(with previewData: RoomPreviewData) { @@ -408,11 +408,11 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { self.showRoom(with: roomCoordinatorParameters) } - private func showRoom(with parameters: RoomCoordinatorParameters) { + private func showRoom(with parameters: RoomCoordinatorParameters, completion: (() -> Void)? = nil) { let coordinator = RoomCoordinator(parameters: parameters) coordinator.delegate = self - coordinator.start() + coordinator.start(withCompletion: completion) self.add(childCoordinator: coordinator) self.replaceSplitViewDetails(with: coordinator) { @@ -497,7 +497,7 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { // MARK: - MasterTabBarControllerDelegate extension TabBarCoordinator: MasterTabBarControllerDelegate { - + func masterTabBarController(_ masterTabBarController: MasterTabBarController!, didSelectRoomPreviewWith roomPreviewData: RoomPreviewData!) { self.showRoomPreview(with: roomPreviewData) } @@ -510,8 +510,8 @@ extension TabBarCoordinator: MasterTabBarControllerDelegate { self.delegate?.tabBarCoordinatorDidCompleteAuthentication(self) } - func masterTabBarController(_ masterTabBarController: MasterTabBarController!, didSelectRoomWithId roomId: String!, andEventId eventId: String!, inMatrixSession matrixSession: MXSession!) { - self.showRoom(with: roomId, eventId: eventId, matrixSession: matrixSession) + func masterTabBarController(_ masterTabBarController: MasterTabBarController!, didSelectRoomWithId roomId: String!, andEventId eventId: String!, inMatrixSession matrixSession: MXSession!, completion: (() -> Void)!) { + self.showRoom(with: roomId, eventId: eventId, matrixSession: matrixSession, completion: completion) } func masterTabBarController(_ masterTabBarController: MasterTabBarController!, didSelect group: MXGroup!, inMatrixSession matrixSession: MXSession!) {