fix chat
This commit is contained in:
parent
2396a707ec
commit
95bf287085
@ -124,35 +124,40 @@ struct PrivateChatView: View {
|
||||
private var messagesList: some View {
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading, spacing: 12) {
|
||||
if viewModel.isLoadingMore {
|
||||
loadingMoreView
|
||||
} else if viewModel.messages.isEmpty {
|
||||
emptyState
|
||||
Color.clear
|
||||
.frame(height: 1)
|
||||
.id(bottomAnchorId)
|
||||
.onAppear { isBottomAnchorVisible = true }
|
||||
.onDisappear { isBottomAnchorVisible = false }
|
||||
|
||||
if let message = viewModel.errorMessage,
|
||||
!message.isEmpty,
|
||||
!viewModel.messages.isEmpty {
|
||||
errorBanner(message: message)
|
||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||
}
|
||||
|
||||
ForEach(viewModel.messages) { message in
|
||||
ForEach(viewModel.messages.reversed()) { message in
|
||||
messageRow(for: message)
|
||||
.id(message.id)
|
||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||
.onAppear {
|
||||
guard hasPositionedToBottom else { return }
|
||||
viewModel.loadMoreIfNeeded(for: message)
|
||||
}
|
||||
}
|
||||
|
||||
if let message = viewModel.errorMessage,
|
||||
!message.isEmpty,
|
||||
!viewModel.messages.isEmpty {
|
||||
errorBanner(message: message)
|
||||
if viewModel.isLoadingMore {
|
||||
loadingMoreView
|
||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||
} else if viewModel.messages.isEmpty {
|
||||
emptyState
|
||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||
}
|
||||
|
||||
Color.clear
|
||||
.frame(height: 1)
|
||||
.id(bottomAnchorId)
|
||||
.onAppear { isBottomAnchorVisible = true }
|
||||
.onDisappear { isBottomAnchorVisible = false }
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
}
|
||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||
.simultaneousGesture(
|
||||
DragGesture().onChanged { value in
|
||||
guard value.translation.height > 0 else { return }
|
||||
@ -441,7 +446,7 @@ struct PrivateChatView: View {
|
||||
|
||||
DispatchQueue.main.async {
|
||||
withAnimation(.easeInOut(duration: 0.2)) {
|
||||
proxy.scrollTo(targetId, anchor: .bottom)
|
||||
proxy.scrollTo(targetId, anchor: .top)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user