diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index f35a73a0c..ad1cdae23 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -267,7 +267,7 @@ class AppCoordinator: AppCoordinatorProtocol { navigationRootCoordinator.setRootCoordinator(navigationSplitCoordinator) if let storedAppRoute { - userSessionFlowCoordinator.handleAppRoute(storedAppRoute) + userSessionFlowCoordinator.handleAppRoute(storedAppRoute, animated: false) } } @@ -441,7 +441,7 @@ class AppCoordinator: AppCoordinatorProtocol { private func handleAppRoute(_ appRoute: AppRoute) { if let userSessionFlowCoordinator { - userSessionFlowCoordinator.handleAppRoute(appRoute) + userSessionFlowCoordinator.handleAppRoute(appRoute, animated: UIApplication.shared.applicationState == .active) } else { storedAppRoute = appRoute } diff --git a/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinator.swift b/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinator.swift index 8cf08686b..95a242a40 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinator.swift @@ -64,16 +64,16 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { stateMachine.isDisplayingRoomScreen(withRoomId: roomId) } - func handleAppRoute(_ appRoute: AppRoute) { + func handleAppRoute(_ appRoute: AppRoute, animated: Bool) { switch stateMachine.state { case .feedbackScreen, .sessionVerificationScreen, .settingsScreen, .startChatScreen, .invitesScreen: - navigationSplitCoordinator.setSheetCoordinator(nil) + navigationSplitCoordinator.setSheetCoordinator(nil, animated: animated) case .roomList, .initial: break } switch appRoute { case .room(let roomID): - stateMachine.processEvent(.selectRoom(roomId: roomID)) + stateMachine.processEvent(.selectRoom(roomId: roomID), userInfo: .init(animated: animated)) } } @@ -83,7 +83,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { private func setupStateMachine() { stateMachine.addTransitionHandler { [weak self] context in guard let self else { return } - + let animated = (context.userInfo as? EventUserInfo)?.animated ?? true switch (context.fromState, context.event, context.toState) { case (.initial, .start, .roomList): self.presentHomeScreen() @@ -94,31 +94,31 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { return } - self.presentRoomWithIdentifier(selectedRoomId) + self.presentRoomWithIdentifier(selectedRoomId, animated: animated) case(.roomList, .deselectRoom, .roomList): break case (.roomList, .showSessionVerificationScreen, .sessionVerificationScreen): - self.presentSessionVerification() + self.presentSessionVerification(animated: animated) case (.sessionVerificationScreen, .dismissedSessionVerificationScreen, .roomList): break case (.roomList, .showSettingsScreen, .settingsScreen): - self.presentSettingsScreen() + self.presentSettingsScreen(animated: animated) case (.settingsScreen, .dismissedSettingsScreen, .roomList): break case (.roomList, .feedbackScreen, .feedbackScreen): - self.presentFeedbackScreen() + self.presentFeedbackScreen(animated: animated) case (.feedbackScreen, .dismissedFeedbackScreen, .roomList): break case (.roomList, .showStartChatScreen, .startChatScreen): - self.presentStartChat() + self.presentStartChat(animated: animated) case (.startChatScreen, .dismissedStartChatScreen, .roomList): break case (.roomList, .showInvitesScreen, .invitesScreen): - self.presentInvitesList() + self.presentInvitesList(animated: animated) case (.invitesScreen, .closedInvitesScreen, .roomList): break default: @@ -166,7 +166,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { // MARK: Rooms - private func presentRoomWithIdentifier(_ roomIdentifier: String) { + private func presentRoomWithIdentifier(_ roomIdentifier: String, animated: Bool = true) { Task { @MainActor in guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomIdentifier) else { MXLog.error("Invalid room identifier: \(roomIdentifier)") @@ -197,7 +197,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { } } - detailNavigationStackCoordinator.setRootCoordinator(coordinator) { [weak self, roomIdentifier] in + detailNavigationStackCoordinator.setRootCoordinator(coordinator, animated: animated) { [weak self, roomIdentifier] in guard let self else { return } // Move the state machine to no room selected if the room currently being dimissed @@ -210,7 +210,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { } if navigationSplitCoordinator.detailCoordinator == nil { - navigationSplitCoordinator.setDetailCoordinator(detailNavigationStackCoordinator) + navigationSplitCoordinator.setDetailCoordinator(detailNavigationStackCoordinator, animated: animated) } } } @@ -222,7 +222,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { // MARK: Settings - private func presentSettingsScreen() { + private func presentSettingsScreen(animated: Bool) { let settingsNavigationStackCoordinator = NavigationStackCoordinator() let userIndicatorController = UserIndicatorController(rootCoordinator: settingsNavigationStackCoordinator) @@ -243,7 +243,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { } } - settingsNavigationStackCoordinator.setRootCoordinator(settingsScreenCoordinator) + settingsNavigationStackCoordinator.setRootCoordinator(settingsScreenCoordinator, animated: animated) navigationSplitCoordinator.setSheetCoordinator(userIndicatorController) { [weak self] in self?.stateMachine.processEvent(.dismissedSettingsScreen) @@ -252,7 +252,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { // MARK: Session verification - private func presentSessionVerification() { + private func presentSessionVerification(animated: Bool) { guard let sessionVerificationController = userSession.sessionVerificationController else { fatalError("The sessionVerificationController should aways be valid at this point") } @@ -265,14 +265,14 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { self?.navigationSplitCoordinator.setSheetCoordinator(nil) } - navigationSplitCoordinator.setSheetCoordinator(coordinator) { [weak self] in + navigationSplitCoordinator.setSheetCoordinator(coordinator, animated: animated) { [weak self] in self?.stateMachine.processEvent(.dismissedSessionVerificationScreen) } } // MARK: Start Chat - private func presentStartChat() { + private func presentStartChat(animated: Bool) { let startChatNavigationStackCoordinator = NavigationStackCoordinator() let userIndicatorController = UserIndicatorController(rootCoordinator: startChatNavigationStackCoordinator) @@ -293,14 +293,14 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { startChatNavigationStackCoordinator.setRootCoordinator(coordinator) - navigationSplitCoordinator.setSheetCoordinator(userIndicatorController) { [weak self] in + navigationSplitCoordinator.setSheetCoordinator(userIndicatorController, animated: animated) { [weak self] in self?.stateMachine.processEvent(.dismissedStartChatScreen) } } // MARK: Bug reporting - private func presentFeedbackScreen(for image: UIImage? = nil) { + private func presentFeedbackScreen(animated: Bool, for image: UIImage? = nil) { let feedbackNavigationStackCoordinator = NavigationStackCoordinator() let userIndicatorController = UserIndicatorController(rootCoordinator: feedbackNavigationStackCoordinator) @@ -318,14 +318,14 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { feedbackNavigationStackCoordinator.setRootCoordinator(coordinator) - navigationSplitCoordinator.setSheetCoordinator(userIndicatorController) { [weak self] in + navigationSplitCoordinator.setSheetCoordinator(userIndicatorController, animated: animated) { [weak self] in self?.stateMachine.processEvent(.dismissedFeedbackScreen) } } // MARK: Invites list - private func presentInvitesList() { + private func presentInvitesList(animated: Bool) { let parameters = InvitesCoordinatorParameters(userSession: userSession) let coordinator = InvitesCoordinator(parameters: parameters) @@ -333,7 +333,7 @@ class UserSessionFlowCoordinator: CoordinatorProtocol { .sink { _ in } .store(in: &cancellables) - navigationSplitCoordinator.setDetailCoordinator(coordinator) { [weak self] in + navigationSplitCoordinator.setDetailCoordinator(coordinator, animated: animated) { [weak self] in self?.stateMachine.processEvent(.closedInvitesScreen) } } diff --git a/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinatorStateMachine.swift b/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinatorStateMachine.swift index 9fe2dbc57..36b564ba9 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinatorStateMachine.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionFlowCoordinatorStateMachine.swift @@ -142,8 +142,8 @@ class UserSessionFlowCoordinatorStateMachine { /// Attempt to move the state machine to another state through an event /// It will either invoke the `transitionHandler` or the `errorHandler` depending on its current state - func processEvent(_ event: Event) { - stateMachine.tryEvent(event) + func processEvent(_ event: Event, userInfo: EventUserInfo? = nil) { + stateMachine.tryEvent(event, userInfo: userInfo) } /// Registers a callback for processing state machine transitions @@ -166,3 +166,7 @@ class UserSessionFlowCoordinatorStateMachine { } } } + +struct EventUserInfo { + let animated: Bool +} diff --git a/changelog.d/776.change b/changelog.d/776.change new file mode 100644 index 000000000..4c71c6bdf --- /dev/null +++ b/changelog.d/776.change @@ -0,0 +1 @@ +Animations are disabled when tapping on an animations when the app is in background. \ No newline at end of file