From e9d690450e29be124b9865f835b498da09b8db7f Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 3 May 2024 14:58:06 +0100 Subject: [PATCH] Fix permalink crash. (#2777) --- .../Screens/RoomScreen/RoomScreenViewModel.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 0e62c2924..049d65bba 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -190,10 +190,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol case .focusLive: focusLive() case .scrolledToFocussedItem: - Task { // Use a Task to mutate view state after the current view update. - state.timelineViewState.focussedEvent?.appearance = .hasAppeared - hideFocusLoadingIndicator() - } + // Use a Task to mutate view state after the current view update. + Task { didScrollToFocussedItem() } case .hasSwitchedTimeline: Task { state.timelineViewState.isSwitchingTimelines = false } } @@ -258,6 +256,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol timelineController.focusLive() } + private func didScrollToFocussedItem() { + if var focussedEvent = state.timelineViewState.focussedEvent { + focussedEvent.appearance = .hasAppeared + state.timelineViewState.focussedEvent = focussedEvent + hideFocusLoadingIndicator() + } + } + private func attach(_ attachment: ComposerAttachmentType) { switch attachment { case .camera: