ios_app/Shared/Views/Tab/MainView.swift
2025-07-25 01:50:56 +03:00

99 lines
3.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MainView.swift
// VolnahubApp
//
// Created by cheykrym on 09/06/2025.
//
import SwiftUI
struct MainView: View {
@ObservedObject var viewModel: LoginViewModel
@State private var selectedTab: Int = 0
// Состояния для TopBarView, когда активна вкладка Profile
@State private var selectedAccount = "@user1"
@State private var accounts = ["@user1", "@user2", "@user3"]
@State private var sheetType: ProfileTab.SheetType? = nil
private var tabTitle: String {
switch selectedTab {
case 0:
return "Home"
case 1:
return "Search"
case 2:
return "Chats"
case 3:
return "Profile"
default:
return "Home"
}
}
var body: some View {
NavigationView { // NavigationView нужен здесь для NavigationLink в TopBarView
VStack(spacing: 0) {
TopBarView(
title: tabTitle,
selectedAccount: $selectedAccount,
sheetType: $sheetType,
accounts: accounts,
viewModel: viewModel
)
ZStack {
switch selectedTab {
case 0:
HomeTab()
case 1:
SearchTab()
case 2:
ChatsTab()
case 3:
// Передаем состояния в ProfileTab
ProfileTab(
viewModel: viewModel,
sheetType: $sheetType,
selectedAccount: $selectedAccount,
accounts: $accounts
)
default:
HomeTab()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
CustomTabBar(selectedTab: $selectedTab) {
// Действие для кнопки "Создать"
print("Create button tapped")
}
}
.ignoresSafeArea(edges: .bottom)
.navigationBarHidden(true) // Скрываем стандартный NavigationBar
.sheet(item: $sheetType) { type in
// Обработка sheet, перенесенная из ProfileTab
switch type {
case .accountShare:
AccountShareSheet(
isPresented: Binding(
get: { sheetType != nil },
set: { if !$0 { sheetType = nil } }
),
selectedAccount: $selectedAccount,
accounts: accounts
)
}
}
}
.navigationViewStyle(StackNavigationViewStyle()) // Важно для корректной работы
}
}
struct MainView_Previews: PreviewProvider {
static var previews: some View {
let mockViewModel = LoginViewModel()
MainView(viewModel: mockViewModel)
}
}