patch view
This commit is contained in:
parent
cc9cc3149f
commit
5c0c24cff2
@ -4,7 +4,6 @@ import Combine
|
|||||||
final class IncomingMessageCenter: ObservableObject {
|
final class IncomingMessageCenter: ObservableObject {
|
||||||
@Published private(set) var banner: IncomingMessageBanner?
|
@Published private(set) var banner: IncomingMessageBanner?
|
||||||
@Published var presentedChat: PrivateChatListItem?
|
@Published var presentedChat: PrivateChatListItem?
|
||||||
@Published var pendingNavigation: ChatNavigationTarget?
|
|
||||||
var currentUserId: String?
|
var currentUserId: String?
|
||||||
var activeChatId: String?
|
var activeChatId: String?
|
||||||
|
|
||||||
@ -33,13 +32,7 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
guard let banner else { return }
|
guard let banner else { return }
|
||||||
activeChatId = banner.message.chatId
|
activeChatId = banner.message.chatId
|
||||||
let chatItem = makeChatItem(from: banner.message)
|
let chatItem = makeChatItem(from: banner.message)
|
||||||
if AppConfig.PRESENT_CHAT_AS_SHEET {
|
|
||||||
presentedChat = chatItem
|
presentedChat = chatItem
|
||||||
pendingNavigation = nil
|
|
||||||
} else {
|
|
||||||
pendingNavigation = ChatNavigationTarget(chat: chatItem)
|
|
||||||
presentedChat = nil
|
|
||||||
}
|
|
||||||
dismissBanner()
|
dismissBanner()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +45,7 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if AppConfig.PRESENT_CHAT_AS_SHEET,
|
if let presentedChat,
|
||||||
let presentedChat,
|
|
||||||
presentedChat.chatId == message.chatId {
|
presentedChat.chatId == message.chatId {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -122,9 +114,4 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
dismissWorkItem = workItem
|
dismissWorkItem = workItem
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: workItem)
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: workItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ChatNavigationTarget: Identifiable {
|
|
||||||
let id = UUID()
|
|
||||||
let chat: PrivateChatListItem
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import UIKit
|
|||||||
|
|
||||||
struct ChatsTab: View {
|
struct ChatsTab: View {
|
||||||
@ObservedObject private var loginViewModel: LoginViewModel
|
@ObservedObject private var loginViewModel: LoginViewModel
|
||||||
@Binding private var pendingNavigation: IncomingMessageCenter.ChatNavigationTarget?
|
|
||||||
@Binding var searchRevealProgress: CGFloat
|
@Binding var searchRevealProgress: CGFloat
|
||||||
@Binding var searchText: String
|
@Binding var searchText: String
|
||||||
private let searchService = SearchService()
|
private let searchService = SearchService()
|
||||||
@ -41,12 +40,10 @@ struct ChatsTab: View {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
loginViewModel: LoginViewModel,
|
loginViewModel: LoginViewModel,
|
||||||
pendingNavigation: Binding<IncomingMessageCenter.ChatNavigationTarget?>,
|
|
||||||
searchRevealProgress: Binding<CGFloat>,
|
searchRevealProgress: Binding<CGFloat>,
|
||||||
searchText: Binding<String>
|
searchText: Binding<String>
|
||||||
) {
|
) {
|
||||||
self._loginViewModel = ObservedObject(wrappedValue: loginViewModel)
|
self._loginViewModel = ObservedObject(wrappedValue: loginViewModel)
|
||||||
self._pendingNavigation = pendingNavigation
|
|
||||||
self._searchRevealProgress = searchRevealProgress
|
self._searchRevealProgress = searchRevealProgress
|
||||||
self._searchText = searchText
|
self._searchText = searchText
|
||||||
}
|
}
|
||||||
@ -100,13 +97,6 @@ struct ChatsTab: View {
|
|||||||
globalSearchTask?.cancel()
|
globalSearchTask?.cancel()
|
||||||
globalSearchTask = nil
|
globalSearchTask = nil
|
||||||
}
|
}
|
||||||
.onChange(of: pendingNavigation?.id) { _ in
|
|
||||||
guard let target = pendingNavigation else { return }
|
|
||||||
handleNavigationTarget(target.chat)
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
pendingNavigation = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@ -552,30 +542,6 @@ private extension ChatsTab {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleNavigationTarget(_ chatItem: PrivateChatListItem) {
|
|
||||||
dismissKeyboard()
|
|
||||||
if !searchText.isEmpty {
|
|
||||||
searchText = ""
|
|
||||||
}
|
|
||||||
if searchRevealProgress > 0 {
|
|
||||||
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
|
|
||||||
searchRevealProgress = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let existingChat = viewModel.chats.first(where: { $0.chatId == chatItem.chatId })
|
|
||||||
pendingChatItem = existingChat ?? chatItem
|
|
||||||
selectedChatId = chatItem.chatId
|
|
||||||
isPendingChatActive = true
|
|
||||||
|
|
||||||
if existingChat == nil {
|
|
||||||
if loginViewModel.chatLoadingState != .loading {
|
|
||||||
loginViewModel.chatLoadingState = .loading
|
|
||||||
}
|
|
||||||
viewModel.refresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleSearchQueryChange(_ query: String) {
|
func handleSearchQueryChange(_ query: String) {
|
||||||
let trimmed = query.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmed = query.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
|
||||||
@ -1195,12 +1161,10 @@ struct ChatsTab_Previews: PreviewProvider {
|
|||||||
@State private var progress: CGFloat = 1
|
@State private var progress: CGFloat = 1
|
||||||
@State private var searchText: String = ""
|
@State private var searchText: String = ""
|
||||||
@StateObject private var loginViewModel = LoginViewModel()
|
@StateObject private var loginViewModel = LoginViewModel()
|
||||||
@State private var pendingNavigation: IncomingMessageCenter.ChatNavigationTarget?
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ChatsTab(
|
ChatsTab(
|
||||||
loginViewModel: loginViewModel,
|
loginViewModel: loginViewModel,
|
||||||
pendingNavigation: $pendingNavigation,
|
|
||||||
searchRevealProgress: $progress,
|
searchRevealProgress: $progress,
|
||||||
searchText: $searchText
|
searchText: $searchText
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct MainView: View {
|
struct MainView: View {
|
||||||
@ObservedObject var viewModel: LoginViewModel
|
@ObservedObject var viewModel: LoginViewModel
|
||||||
@EnvironmentObject private var messageCenter: IncomingMessageCenter
|
|
||||||
@State private var selectedTab: Int = 0
|
@State private var selectedTab: Int = 0
|
||||||
// @StateObject private var newHomeTabViewModel = NewHomeTabViewModel()
|
// @StateObject private var newHomeTabViewModel = NewHomeTabViewModel()
|
||||||
|
|
||||||
@ -34,12 +33,6 @@ struct MainView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
let pendingNavigationBinding: Binding<IncomingMessageCenter.ChatNavigationTarget?> = AppConfig.PRESENT_CHAT_AS_SHEET
|
|
||||||
? .constant(nil)
|
|
||||||
: Binding(
|
|
||||||
get: { messageCenter.pendingNavigation },
|
|
||||||
set: { messageCenter.pendingNavigation = $0 }
|
|
||||||
)
|
|
||||||
ZStack(alignment: .top) {
|
ZStack(alignment: .top) {
|
||||||
ZStack(alignment: .leading) { // Выравниваем ZStack по левому краю
|
ZStack(alignment: .leading) { // Выравниваем ZStack по левому краю
|
||||||
// Основной контент
|
// Основной контент
|
||||||
@ -64,7 +57,6 @@ struct MainView: View {
|
|||||||
|
|
||||||
ChatsTab(
|
ChatsTab(
|
||||||
loginViewModel: viewModel,
|
loginViewModel: viewModel,
|
||||||
pendingNavigation: pendingNavigationBinding,
|
|
||||||
searchRevealProgress: $chatSearchRevealProgress,
|
searchRevealProgress: $chatSearchRevealProgress,
|
||||||
searchText: $chatSearchText
|
searchText: $chatSearchText
|
||||||
)
|
)
|
||||||
@ -145,15 +137,6 @@ struct MainView: View {
|
|||||||
menuOffset = presented ? menuWidth : 0
|
menuOffset = presented ? menuWidth : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: messageCenter.pendingNavigation?.id) { _ in
|
|
||||||
guard !AppConfig.PRESENT_CHAT_AS_SHEET,
|
|
||||||
messageCenter.pendingNavigation != nil else { return }
|
|
||||||
withAnimation(.easeInOut) {
|
|
||||||
selectedTab = 2
|
|
||||||
isSideMenuPresented = false
|
|
||||||
menuOffset = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onChange(of: selectedTab) { newValue in
|
.onChange(of: selectedTab) { newValue in
|
||||||
if newValue != 3 {
|
if newValue != 3 {
|
||||||
isSettingsPresented = false
|
isSettingsPresented = false
|
||||||
@ -166,7 +149,6 @@ struct MainView_Previews: PreviewProvider {
|
|||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let mockViewModel = LoginViewModel()
|
let mockViewModel = LoginViewModel()
|
||||||
MainView(viewModel: mockViewModel)
|
MainView(viewModel: mockViewModel)
|
||||||
.environmentObject(IncomingMessageCenter())
|
|
||||||
.environmentObject(ThemeManager())
|
.environmentObject(ThemeManager())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,23 @@ struct yobbleApp: App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.environmentObject(messageCenter)
|
||||||
|
}
|
||||||
|
.fullScreenCover(item: AppConfig.PRESENT_CHAT_AS_SHEET ? .constant(nil) : $messageCenter.presentedChat) { chatItem in
|
||||||
|
NavigationView {
|
||||||
|
PrivateChatView(
|
||||||
|
chat: chatItem,
|
||||||
|
currentUserId: messageCenter.currentUserId
|
||||||
|
)
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button(NSLocalizedString("Закрыть", comment: "")) {
|
||||||
|
messageCenter.presentedChat = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.environmentObject(messageCenter)
|
||||||
}
|
}
|
||||||
.environmentObject(messageCenter)
|
.environmentObject(messageCenter)
|
||||||
.environmentObject(themeManager)
|
.environmentObject(themeManager)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user