Merge pull request #894 from meshtastic/messages-scroll

New scroll methods
This commit is contained in:
Garth Vander Houwen 2024-08-23 20:11:41 -07:00 committed by GitHub
commit 411f13c96c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 10 deletions

View file

@ -128,14 +128,14 @@ struct ChannelMessageList: View {
}
.padding([.top])
.scrollDismissesKeyboard(.immediately)
.onAppear {
if channel.allPrivateMessages.count > 0 {
scrollView.scrollTo(channel.allPrivateMessages.last!.messageId)
.onFirstAppear {
withAnimation {
scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom)
}
}
.onChange(of: channel.allPrivateMessages, perform: { _ in
if channel.allPrivateMessages.count > 0 {
scrollView.scrollTo(channel.allPrivateMessages.last!.messageId)
withAnimation {
scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom)
}
})
}

View file

@ -116,14 +116,14 @@ struct UserMessageList: View {
}
.padding([.top])
.scrollDismissesKeyboard(.immediately)
.onAppear {
if user.messageList.count > 0 {
scrollView.scrollTo(user.messageList.last!.messageId)
.onFirstAppear {
withAnimation {
scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)
}
}
.onChange(of: user.messageList, perform: { _ in
if user.messageList.count > 0 {
scrollView.scrollTo(user.messageList.last!.messageId)
withAnimation {
scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)
}
})
}