Scroll to content when keyboard is presented

This commit is contained in:
Brian Floersch 2025-02-06 20:01:26 -05:00
parent 41a252649a
commit b6a881f008
2 changed files with 12 additions and 4 deletions

View file

@ -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)

View file

@ -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)