From f1c22ea9e09150f4794a79e7626d6d9500b57570 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 21 Nov 2022 15:02:28 +0200 Subject: [PATCH] Revert "Force the timeline to stay at the bottom when first loading" This reverts commit 71bcbf488d16158e3d95ecd425c3d0e0eabaf1f6. --- .../RoomScreen/View/TimelineItemList.swift | 41 ++++++++----------- changelog.d/pr-327.bugfix | 1 - 2 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 changelog.d/pr-327.bugfix diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift index 8ce2d45c9..df7ddaacd 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift @@ -82,12 +82,20 @@ struct TimelineItemList: View { } } } - .onChange(of: timelineItems) { _ in - // Run this multiple times on first appearance to fix offset issues - updatePinnedOffset(scrollViewProxy: proxy) - } - .onChange(of: pinnedItem) { _ in - updatePinnedOffset(scrollViewProxy: proxy) + .onChange(of: pinnedItem) { item in + guard let item else { + return + } + + if item.animated { + withAnimation(Animation.elementDefault) { + proxy.scrollTo(item.id, anchor: item.anchor) + } + } else { + proxy.scrollTo(item.id, anchor: item.anchor) + } + + pinnedItem = nil } } .scrollDismissesKeyboard(.immediately) @@ -140,6 +148,8 @@ struct TimelineItemList: View { let pinnedItem = PinnedItem(id: currentFirstItem.id, anchor: .top, animated: false) timelineItems = context.viewState.items self.pinnedItem = pinnedItem + + return } // Otherwise just update the items @@ -188,25 +198,6 @@ struct TimelineItemList: View { return selectedItemId == item.id ? 1.0 : 0.5 } - private func updatePinnedOffset(scrollViewProxy proxy: ScrollViewProxy) { - guard let item = pinnedItem else { - return - } - - if item.animated { - withAnimation(.elementDefault) { - proxy.scrollTo(item.id, anchor: item.anchor) - } - } else { - proxy.scrollTo(item.id, anchor: item.anchor) - } - - // Need to delay this for a bit to fix offset problems when loading the initial page - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - pinnedItem = nil - } - } - private var isRunningPreviews: Bool { #if DEBUG return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" diff --git a/changelog.d/pr-327.bugfix b/changelog.d/pr-327.bugfix deleted file mode 100644 index cbcf2d97e..000000000 --- a/changelog.d/pr-327.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fixed timelines not sticking to the bottom on first appearance and when message heights change \ No newline at end of file