From 2204bb9fe077db055f8c5c4f9482ae9b4d8335da Mon Sep 17 00:00:00 2001 From: Vladimir Dubovik Date: Thu, 22 May 2025 16:16:33 +0300 Subject: [PATCH] Commit --- Schedule-ICTIS/ContentView.swift | 3 ++- Schedule-ICTIS/Settings/FavGroupsView.swift | 12 +++++++++++- Schedule-ICTIS/Settings/FavVPKView.swift | 11 ++++++++++- Schedule-ICTIS/Settings/SelectingGroupView.swift | 10 ++++++++++ Schedule-ICTIS/Settings/SelectingVPKView.swift | 7 +++++++ Schedule-ICTIS/TabBar/TabBarView.swift | 5 +++++ Schedule-ICTIS/ViewModel/NavigationManager.swift | 16 ++++++++++++++++ 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 Schedule-ICTIS/ViewModel/NavigationManager.swift diff --git a/Schedule-ICTIS/ContentView.swift b/Schedule-ICTIS/ContentView.swift index 0a28402..0f1239c 100644 --- a/Schedule-ICTIS/ContentView.swift +++ b/Schedule-ICTIS/ContentView.swift @@ -12,6 +12,7 @@ struct ContentView: View { @State private var isTabBarHidden = false @ObservedObject var vm: ScheduleViewModel @ObservedObject var networkMonitor: NetworkMonitor + @StateObject private var navigationManager = NavigationManager() var body: some View { ZStack (alignment: .bottom) { TabView(selection: $selectedTab) { @@ -32,7 +33,7 @@ struct ContentView: View { SettingsView(vm: vm, networkMonitor: networkMonitor) .tag(TabBarModel.settings) } - TabBarView(selectedTab: $selectedTab) + TabBarView(selectedTab: $selectedTab, navigationManager: navigationManager) } .alert(isPresented: $vm.isShowingAlertForIncorrectSingleGroup, error: vm.errorInNetworkForSingleGroup) { error in Button("ОК") { diff --git a/Schedule-ICTIS/Settings/FavGroupsView.swift b/Schedule-ICTIS/Settings/FavGroupsView.swift index b7af5cd..7ea3a82 100644 --- a/Schedule-ICTIS/Settings/FavGroupsView.swift +++ b/Schedule-ICTIS/Settings/FavGroupsView.swift @@ -41,8 +41,18 @@ struct FavGroupsView: View { } } } - .navigationBarBackButtonHidden(true) // Скрываем стандартную кнопку "Назад" + .navigationBarBackButtonHidden(true) .background(Color("background")) + // Жест для возврата на страницу настроек + .simultaneousGesture( + DragGesture(minimumDistance: 20, coordinateSpace: .local) + .onEnded { value in + // Проверяем, что свайп начинается у левого края и идёт вправо + if value.startLocation.x < 20 && value.translation.width > 80 { + dismiss() + } + } + ) .toolbar { ToolbarItem(placement: .topBarLeading) { Button(action: { diff --git a/Schedule-ICTIS/Settings/FavVPKView.swift b/Schedule-ICTIS/Settings/FavVPKView.swift index 66083fd..29b3c49 100644 --- a/Schedule-ICTIS/Settings/FavVPKView.swift +++ b/Schedule-ICTIS/Settings/FavVPKView.swift @@ -40,8 +40,17 @@ struct FavVPKView: View { } } } - .navigationBarBackButtonHidden(true) // Скрываем стандартную кнопку "Назад" + .navigationBarBackButtonHidden(true) .background(Color("background")) + .simultaneousGesture( + DragGesture(minimumDistance: 20, coordinateSpace: .local) + .onEnded { value in + // Проверяем, что свайп начинается у левого края и идёт вправо + if value.startLocation.x < 20 && value.translation.width > 80 { + dismiss() + } + } + ) .toolbar { ToolbarItem(placement: .topBarLeading) { Button(action: { diff --git a/Schedule-ICTIS/Settings/SelectingGroupView.swift b/Schedule-ICTIS/Settings/SelectingGroupView.swift index 4ff7f91..e36406d 100644 --- a/Schedule-ICTIS/Settings/SelectingGroupView.swift +++ b/Schedule-ICTIS/Settings/SelectingGroupView.swift @@ -121,6 +121,9 @@ struct SelectingGroupView: View { saveScheduleForGroupToMemory(withName: item.name) vm.nameToHtml[item.name] = "" vm.addGroupToFilteringArray(group: item.name) + if vm.filteringGroups.count == 2 { + vm.showOnlyChoosenGroup = vm.filteringGroups[1] + } vm.fetchWeekSchedule() self.isLoading = false self.text = "" @@ -158,6 +161,13 @@ struct SelectingGroupView: View { } } .navigationBarTitleDisplayMode(.inline) + .gesture( + DragGesture().onEnded { value in + if value.startLocation.x < 50 && value.translation.width > 80 { + dismiss() + } + } + ) } } diff --git a/Schedule-ICTIS/Settings/SelectingVPKView.swift b/Schedule-ICTIS/Settings/SelectingVPKView.swift index a13358e..28e86fd 100644 --- a/Schedule-ICTIS/Settings/SelectingVPKView.swift +++ b/Schedule-ICTIS/Settings/SelectingVPKView.swift @@ -121,6 +121,13 @@ struct SelectingVPKView: View { } } .navigationBarTitleDisplayMode(.inline) + .gesture( + DragGesture().onEnded { value in + if value.startLocation.x < 50 && value.translation.width > 80 { + dismiss() + } + } + ) } } diff --git a/Schedule-ICTIS/TabBar/TabBarView.swift b/Schedule-ICTIS/TabBar/TabBarView.swift index 9420489..b935561 100644 --- a/Schedule-ICTIS/TabBar/TabBarView.swift +++ b/Schedule-ICTIS/TabBar/TabBarView.swift @@ -9,6 +9,7 @@ import SwiftUI struct TabBarView: View { @Binding var selectedTab: TabBarModel + @ObservedObject var navigationManager: NavigationManager @Namespace private var animation var body: some View { VStack { @@ -36,6 +37,10 @@ struct TabBarView: View { var content: some View { ForEach(TabBarModel.allCases, id: \.rawValue) { tab in Button { + if selectedTab == tab { + // Если таб уже выбран, сбрасываем навигацию + navigationManager.popToRoot() + } selectedTab = tab } label: { VStack (alignment: .center) { diff --git a/Schedule-ICTIS/ViewModel/NavigationManager.swift b/Schedule-ICTIS/ViewModel/NavigationManager.swift new file mode 100644 index 0000000..d8ac885 --- /dev/null +++ b/Schedule-ICTIS/ViewModel/NavigationManager.swift @@ -0,0 +1,16 @@ +// +// NavigationManager.swift +// Schedule-ICTIS +// +// Created by Mironov Egor on 21.05.2025. +// + +import SwiftUI + +class NavigationManager: ObservableObject { + @Published var path = NavigationPath() + + func popToRoot() { + path.removeLast(path.count) + } +}