Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix initial chat scroll

Prateek Sunal436cb59777d3
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
index adc3d9f753..3dd8f22689 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
@@ -25,6 +25,7 @@ struct MessageListView: View {
@State private var isUserDragging = false
@State private var lastContentHeight: CGFloat = 0
@State private var lastScrollChange = ScrollChange()
+ @State private var didInitialScroll = false
#if os(iOS)
@State private var haptic: UIImpactFeedbackGenerator?
#endif
@@ -77,7 +78,8 @@ struct MessageListView: View {
#if os(iOS)
prepareHaptic()
#endif
- scrollToBottom(scrollProxy, force: true, animated: false)
+ didInitialScroll = false
+ scheduleInitialScroll(scrollProxy)
}
}
}
@@ -103,12 +105,17 @@ struct MessageListView: View {
lastScrollChange = newValue
if newValue.messagesCount != previous.messagesCount {
- scrollToBottom(scrollProxy, animated: newValue.isGenerating)
+ if !didInitialScroll {
+ scheduleInitialScroll(scrollProxy)
+ } else {
+ scrollToBottom(scrollProxy, animated: newValue.isGenerating)
+ }
}
if newValue.sessionId != previous.sessionId {
autoScrollEnabled = true
- scrollToBottom(scrollProxy, force: true, animated: false)
+ didInitialScroll = false
+ scheduleInitialScroll(scrollProxy)
}
if newValue.streamingLength != previous.streamingLength {
@@ -271,6 +278,14 @@ struct MessageListView: View {
return basePadding
}
+ private func scheduleInitialScroll(_ proxy: ScrollViewProxy) {
+ guard !didInitialScroll else { return }
+ DispatchQueue.main.async {
+ scrollToBottom(proxy, force: true, animated: false)
+ didInitialScroll = true
+ }
+ }
+
private func scrollToBottom(_ proxy: ScrollViewProxy, force: Bool = false, animated: Bool = true) {
guard force || (autoScrollEnabled && isAtBottom) else { return }
if animated {