From b6a881f008fc188e6177328fc7edad5f964189be Mon Sep 17 00:00:00 2001 From: Brian Floersch Date: Thu, 6 Feb 2025 20:01:26 -0500 Subject: [PATCH] Scroll to content when keyboard is presented --- Meshtastic/Views/Messages/ChannelMessageList.swift | 8 ++++++-- Meshtastic/Views/Messages/UserMessageList.swift | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index 1b783427..573a7dc8 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -127,13 +127,17 @@ struct ChannelMessageList: View { } } } - .padding([.top]) - .scrollDismissesKeyboard(.immediately) + .scrollDismissesKeyboard(.interactively) .onFirstAppear { withAnimation { scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom) } } + .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in + withAnimation { + scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom) + } + } .onChange(of: channel.allPrivateMessages) { withAnimation { scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom) diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 7ce190fc..68db6280 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -115,13 +115,17 @@ struct UserMessageList: View { } } } - .padding([.top]) - .scrollDismissesKeyboard(.immediately) + .scrollDismissesKeyboard(.interactively) .onFirstAppear { withAnimation { scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom) } } + .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in + withAnimation { + scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom) + } + } .onChange(of: user.messageList) { withAnimation { scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)