From 4f46f715aaf40a92a2d52fa7467c7c405befcd5d Mon Sep 17 00:00:00 2001 From: cheykrym Date: Fri, 25 Jul 2025 00:20:25 +0300 Subject: [PATCH] tab bar update --- Shared/Views/Tab/CustomTabBar.swift | 84 +++++++++++++++++++++++++++++ Shared/Views/Tab/MainView.swift | 61 ++++++++++----------- yobble.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 Shared/Views/Tab/CustomTabBar.swift diff --git a/Shared/Views/Tab/CustomTabBar.swift b/Shared/Views/Tab/CustomTabBar.swift new file mode 100644 index 0000000..63f2eea --- /dev/null +++ b/Shared/Views/Tab/CustomTabBar.swift @@ -0,0 +1,84 @@ +import SwiftUI + +struct CustomTabBar: View { + @Binding var selectedTab: Int + var onCreate: () -> Void + + var body: some View { + HStack { + // Tab 1: Feed + TabBarButton(systemName: "list.bullet.rectangle", text: "Лента", isSelected: selectedTab == 0) { + selectedTab = 0 + } + + // Tab 2: Search + TabBarButton(systemName: "magnifyingglass", text: "Поиск", isSelected: selectedTab == 1) { + selectedTab = 1 + } + + // Create Button + CreateButton { + onCreate() + } + + // Tab 3: Chats + TabBarButton(systemName: "bubble.left.and.bubble.right.fill", text: "Чаты", isSelected: selectedTab == 2) { + selectedTab = 2 + } + + // Tab 4: Profile + TabBarButton(systemName: "person.crop.square", text: "Лицо", isSelected: selectedTab == 3) { + selectedTab = 3 + } + } + .padding(.horizontal) + .padding(.top, 1) + .padding(.bottom, 18) // Добавляем отступ снизу + .background(Color(.systemGray6)) + } +} + +struct TabBarButton: View { + let systemName: String + let text: String + let isSelected: Bool + let action: () -> Void + + var body: some View { + Button(action: action) { + VStack(spacing: 4) { + Image(systemName: systemName) + .font(.system(size: 22)) + Text(text) +// .font(.caption) + .font(.system(size: 12)) + } + .foregroundColor(isSelected ? .accentColor : .gray) + } + .frame(maxWidth: .infinity) + } +} + +struct CreateButton: View { + let action: () -> Void + + var body: some View { + Button(action: action) { + Image(systemName: "plus") + .font(.system(size: 24, weight: .bold)) + .foregroundColor(.white) + .padding(16) +// .background(Color.accentColor) + .background( + LinearGradient( + gradient: Gradient(colors: [.blue, .white]), + startPoint: .top, + endPoint: .bottom + ) + ) + .clipShape(Circle()) + .shadow(radius: 4) + } + .offset(y: -3) + } +} diff --git a/Shared/Views/Tab/MainView.swift b/Shared/Views/Tab/MainView.swift index aea2b29..19263ab 100644 --- a/Shared/Views/Tab/MainView.swift +++ b/Shared/Views/Tab/MainView.swift @@ -12,42 +12,35 @@ struct MainView: View { @State private var selectedTab: Int = 0 var body: some View { - TabView(selection: $selectedTab) { - HomeTab() - .tabItem { - Image(systemName: "list.bullet.rectangle") - Text("Лента") + VStack(spacing: 0) { + ZStack { + switch selectedTab { + case 0: + HomeTab() + case 1: + SearchTab() + case 2: + ChatsTab() + case 3: + ProfileTab(viewModel: viewModel) + default: + HomeTab() } - .tag(0) - - SearchTab() - .tabItem { - Image(systemName: "magnifyingglass") - Text("Поиск") - } - .tag(1) - -// PublicsTab() -// .tabItem { -// Image(systemName: "") -// Text("Свайп") -// } -// .tag(1) - - ChatsTab() - .tabItem { - Image(systemName: "bubble.left.and.bubble.right.fill") - Text("Чаты") - } - .tag(2) - - ProfileTab(viewModel: viewModel) - .tabItem { - Image(systemName: "person.crop.square") - Text("Лицо") - } - .tag(3) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + + CustomTabBar(selectedTab: $selectedTab) { + // Действие для кнопки "Создать" + print("Create button tapped") + } } + .ignoresSafeArea(edges: .bottom) } } +struct MainView_Previews: PreviewProvider { + static var previews: some View { + let mockViewModel = LoginViewModel() + MainView(viewModel: mockViewModel) + } +} diff --git a/yobble.xcodeproj/project.pbxproj b/yobble.xcodeproj/project.pbxproj index 200fa38..6dbee37 100644 --- a/yobble.xcodeproj/project.pbxproj +++ b/yobble.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 1A0276032DF909F900D8BC53 /* refreshtokenex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0276022DF909F900D8BC53 /* refreshtokenex.swift */; }; 1A0276112DF9247000D8BC53 /* CustomTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0276102DF9247000D8BC53 /* CustomTextField.swift */; }; 1A2302112E3050C60067BF4F /* SearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2302102E3050C60067BF4F /* SearchViewModel.swift */; }; + 1A6FB9552E32D2B200E89EBE /* CustomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A6FB9542E32D2B200E89EBE /* CustomTabBar.swift */; }; 1A79408D2DF77BC3002569DA /* yobbleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A79407A2DF77BC2002569DA /* yobbleApp.swift */; }; 1A79408F2DF77BC3002569DA /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A79407B2DF77BC2002569DA /* ContentView.swift */; }; 1A7940902DF77BC3002569DA /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A79407B2DF77BC2002569DA /* ContentView.swift */; }; @@ -51,6 +52,7 @@ 1A0276022DF909F900D8BC53 /* refreshtokenex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = refreshtokenex.swift; sourceTree = ""; }; 1A0276102DF9247000D8BC53 /* CustomTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextField.swift; sourceTree = ""; }; 1A2302102E3050C60067BF4F /* SearchViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchViewModel.swift; sourceTree = ""; }; + 1A6FB9542E32D2B200E89EBE /* CustomTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomTabBar.swift; sourceTree = ""; }; 1A79407A2DF77BC2002569DA /* yobbleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = yobbleApp.swift; sourceTree = ""; }; 1A79407B2DF77BC2002569DA /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 1A79407C2DF77BC3002569DA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -250,6 +252,7 @@ 1AEE5EA92E21A4FC00A3DCA3 /* Tab */ = { isa = PBXGroup; children = ( + 1A6FB9542E32D2B200E89EBE /* CustomTabBar.swift */, 1A7940B52DF77F21002569DA /* MainView.swift */, 1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */, 1AEE5EB22E21A85800A3DCA3 /* SearchTab.swift */, @@ -392,6 +395,7 @@ 1A7940DE2DF7B0D7002569DA /* config.swift in Sources */, 1A2302112E3050C60067BF4F /* SearchViewModel.swift in Sources */, 1AE587252E23337000254F06 /* ProfileContentGrid.swift in Sources */, + 1A6FB9552E32D2B200E89EBE /* CustomTabBar.swift in Sources */, 1A0276032DF909F900D8BC53 /* refreshtokenex.swift in Sources */, 1A7940B62DF77F21002569DA /* MainView.swift in Sources */, 1A7940E22DF7B1C5002569DA /* KeychainService.swift in Sources */,