mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #1257 from RCGV1/fix-scroll-to-bottom
If no unread messages go straight to bottom
This commit is contained in:
commit
dc892a9543
2 changed files with 20 additions and 20 deletions
|
|
@ -180,24 +180,24 @@ struct ChannelMessageList: View {
|
|||
}
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
.onFirstAppear {
|
||||
// Find first unread message
|
||||
if let firstUnreadMessageId = channel.allPrivateMessages.first(where: { !$0.read })?.messageId {
|
||||
if channel.unreadMessages == 0 {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(firstUnreadMessageId, anchor: .top)
|
||||
showScrollToBottomButton = true
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
}
|
||||
} else {
|
||||
// If no unread messages, scroll to bottom
|
||||
withAnimation {
|
||||
scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
if let firstUnreadMessageId = channel.allPrivateMessages.first(where: { !$0.read })?.messageId {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(firstUnreadMessageId, anchor: .top)
|
||||
showScrollToBottomButton = true
|
||||
}
|
||||
}
|
||||
}
|
||||
gotFirstUnreadMessage = true
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in
|
||||
withAnimation {
|
||||
scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom)
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
showScrollToBottomButton = false
|
||||
}
|
||||
|
|
@ -205,7 +205,7 @@ struct ChannelMessageList: View {
|
|||
.onChange(of: channel.allPrivateMessages) {
|
||||
if hasReachedBottom {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(channel.allPrivateMessages.last?.messageId ?? 0, anchor: .bottom)
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
}
|
||||
} else {
|
||||
showScrollToBottomButton = true
|
||||
|
|
|
|||
|
|
@ -167,24 +167,24 @@ struct UserMessageList: View {
|
|||
}
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
.onFirstAppear {
|
||||
// Find first unread message
|
||||
if let firstUnreadMessageId = user.messageList.first(where: { !$0.read })?.messageId {
|
||||
if user.unreadMessages == 0 {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(firstUnreadMessageId, anchor: .top)
|
||||
showScrollToBottomButton = true
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
}
|
||||
} else {
|
||||
// If no unread messages, scroll to bottom
|
||||
withAnimation {
|
||||
scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
if let firstUnreadMessageId = user.messageList.first(where: { !$0.read })?.messageId {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(firstUnreadMessageId, anchor: .top)
|
||||
showScrollToBottomButton = true
|
||||
}
|
||||
}
|
||||
}
|
||||
gotFirstUnreadMessage = true
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in
|
||||
withAnimation {
|
||||
scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
hasReachedBottom = true
|
||||
showScrollToBottomButton = false
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ struct UserMessageList: View {
|
|||
.onChange(of: user.messageList) {
|
||||
if hasReachedBottom {
|
||||
withAnimation {
|
||||
scrollView.scrollTo(user.messageList.last?.messageId ?? 0, anchor: .bottom)
|
||||
scrollView.scrollTo("bottomAnchor", anchor: .bottom)
|
||||
}
|
||||
} else {
|
||||
showScrollToBottomButton = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue