From c0ae9c8c4cb79e00bbaa71f119c1b245845a849c Mon Sep 17 00:00:00 2001 From: fmodf Date: Mon, 1 Jul 2024 12:05:39 +0200 Subject: [PATCH] wip --- .../Middlewares/DatabaseMiddleware.swift | 2 +- .../Conversation/ConversationScreen.swift | 20 +++++-------------- .../Conversation/ConversationTextInput.swift | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift index 5ee476a..3ab5f47 100644 --- a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift @@ -278,7 +278,7 @@ private extension DatabaseMiddleware { Column("to") == chat.account || (Column("from") == chat.account && Column("to") == chat.participant) ) - .order(Column("date").asc) + .order(Column("date").desc) .fetchAll ) .publisher(in: database._db, scheduling: .immediate) diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift b/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift index b691d13..3c0bb18 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift @@ -28,40 +28,30 @@ struct ConversationScreen: View { ConversationMessageRow(message: message) .id(message.id) .onAppear { - if message.id == messages.last?.id { + if message.id == messages.first?.id { autoScroll = true } } .onDisappear { - if message.id == messages.last?.id { + if message.id == messages.first?.id { autoScroll = false } } } + .rotationEffect(.degrees(180)) } + .rotationEffect(.degrees(180)) .listStyle(.plain) .background(Color.Main.backgroundLight) .scrollDismissesKeyboard(.immediately) .scrollIndicators(.hidden) - .onChange(of: messages) { _ in - if autoScroll { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - withAnimation { - proxy.scrollTo(messages.last?.id, anchor: .bottom) - } - } - } - } .onChange(of: autoScroll) { new in if new { withAnimation { - proxy.scrollTo(messages.last?.id, anchor: .bottom) + proxy.scrollTo(messages.first?.id, anchor: .top) } } } - .onAppear { - proxy.scrollTo(messages.last?.id, anchor: .bottom) - } } } else { Spacer() diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift index 9e970a3..1fcc953 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift @@ -73,7 +73,7 @@ struct ConversationTextInput: View { body: composedMessage ))) messageStr = "" - UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) + // UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) store.dispatch(.conversationAction(.setReplyText(""))) } }