From 95bf2870852079ed69c36498104e54ef336749a1 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Thu, 11 Dec 2025 20:13:42 +0300 Subject: [PATCH] fix chat --- yobble/Views/Chat/PrivateChatView.swift | 37 ++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/yobble/Views/Chat/PrivateChatView.swift b/yobble/Views/Chat/PrivateChatView.swift index 29de696..b5c7ecc 100644 --- a/yobble/Views/Chat/PrivateChatView.swift +++ b/yobble/Views/Chat/PrivateChatView.swift @@ -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) } } }