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