diff --git a/Schedule ICTIS/Main/Views/ScheduleView.swift b/Schedule ICTIS/Main/Views/ScheduleView.swift index 4873664..6de3952 100644 --- a/Schedule ICTIS/Main/Views/ScheduleView.swift +++ b/Schedule ICTIS/Main/Views/ScheduleView.swift @@ -8,6 +8,7 @@ import SwiftUI struct ScheduleView: View { + @State private var isShowingSheet: Bool = false @ObservedObject var vm: ViewModel var body: some View { if vm.isLoading { @@ -15,54 +16,60 @@ struct ScheduleView: View { } else { if vm.errorInNetwork != .invalidResponse { - ZStack (alignment: .top) { - ScrollView(.vertical, showsIndicators: false) { - VStack (spacing: 20) { - ForEach(vm.classes.indices, id: \.self) { index in - if index != 0 && index != 1 && index == vm.selectedIndex { - let daySchedule = vm.classes[index] // Это массив строк для дня - ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in - let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары - if !lesson.isEmpty { - HStack(spacing: 10) { - VStack { - Text(convertTimeString(vm.classes[1][lessonIndex])[0]) - .font(.system(size: 15, weight: .regular)) - Text(convertTimeString(vm.classes[1][lessonIndex])[1]) - .font(.system(size: 15, weight: .regular)) + ZStack (alignment: .top) { + ScrollView(.vertical, showsIndicators: false) { + VStack (spacing: 20) { + ForEach(vm.classes.indices, id: \.self) { index in + if index != 0 && index != 1 && index == vm.selectedIndex { + let daySchedule = vm.classes[index] // Это массив строк для дня + ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in + let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары + if !lesson.isEmpty { + HStack(spacing: 10) { + VStack { + Text(convertTimeString(vm.classes[1][lessonIndex])[0]) + .font(.system(size: 15, weight: .regular)) + Text(convertTimeString(vm.classes[1][lessonIndex])[1]) + .font(.system(size: 15, weight: .regular)) + } + .padding(.top, 7) + .padding(.bottom, 7) + .padding(.leading, 10) + Rectangle() + .frame(width: 2) + .frame(maxHeight: UIScreen.main.bounds.height - 18) + .padding(.top, 7) + .padding(.bottom, 7) + .foregroundColor(getColorForClass(lesson)) + Text(lesson) + .font(.system(size: 18, weight: .regular)) + .padding(.top, 7) + .padding(.bottom, 7) + Spacer() + } + .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) + .background(Color.white) + .cornerRadius(20) + .shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2) + .onTapGesture { + isShowingSheet = true } - .padding(.top, 7) - .padding(.bottom, 7) - .padding(.leading, 10) - Rectangle() - .frame(width: 2) - .frame(maxHeight: UIScreen.main.bounds.height - 18) - .padding(.top, 7) - .padding(.bottom, 7) - .foregroundColor(getColorForClass(lesson)) - Text(lesson) - .font(.system(size: 18, weight: .regular)) - .padding(.top, 7) - .padding(.bottom, 7) - Spacer() } - .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) - .background(Color.white) - .cornerRadius(20) - .shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2) } } } } + .frame(width: UIScreen.main.bounds.width) + .padding(.bottom, 100) + .padding(.top, 30) } - .frame(width: UIScreen.main.bounds.width) - .padding(.bottom, 100) - .padding(.top, 30) + VStack { + LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom) } - VStack { - LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom) + .frame(width: UIScreen.main.bounds.width, height: 15) } - .frame(width: UIScreen.main.bounds.width, height: 15) + .sheet(isPresented: $isShowingSheet) { + SheetChangeClassView(isShowingSheet: $isShowingSheet) } } else { diff --git a/Schedule ICTIS/Main/Views/SearchBarView.swift b/Schedule ICTIS/Main/Views/SearchBarView.swift index e998365..d58b265 100644 --- a/Schedule ICTIS/Main/Views/SearchBarView.swift +++ b/Schedule ICTIS/Main/Views/SearchBarView.swift @@ -10,6 +10,7 @@ import SwiftUI struct SearchBarView: View { @Binding var text: String @State private var isEditing = false + @State private var isShowingSheet: Bool = false @ObservedObject var vm: ViewModel var body: some View { @@ -56,6 +57,7 @@ struct SearchBarView: View { ) if (!vm.isFirstStartOffApp) { Button { + isShowingSheet = true } label: { ZStack { Rectangle() @@ -75,6 +77,9 @@ struct SearchBarView: View { .padding(.top, 5) .frame(height: 40) .accentColor(.blue) + .sheet(isPresented: $isShowingSheet) { + SheetCreateClassView(isShowingSheet: $isShowingSheet) + } } } diff --git a/Schedule ICTIS/Main/Views/SheetChangeClassView.swift b/Schedule ICTIS/Main/Views/SheetChangeClassView.swift new file mode 100644 index 0000000..05998ef --- /dev/null +++ b/Schedule ICTIS/Main/Views/SheetChangeClassView.swift @@ -0,0 +1,37 @@ +// +// SheetView.swift +// Schedule ICTIS +// +// Created by G412 on 12.12.2024. +// + +import SwiftUI + +struct SheetChangeClassView: View { + @Binding var isShowingSheet: Bool + var body: some View { + NavigationView { + VStack { + Spacer() + Text("Создание новой пары") + Spacer() + } + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + Button("Отменить") { + isShowingSheet = false + } + } + ToolbarItem(placement: .navigationBarTrailing) { + Button("Сохранить") { + isShowingSheet = false + } + } + } + } + } +} + +#Preview { + SheetChangeClassView(isShowingSheet: .constant(true)) +} diff --git a/Schedule ICTIS/Main/Views/SheetCreateClassView.swift b/Schedule ICTIS/Main/Views/SheetCreateClassView.swift new file mode 100644 index 0000000..213370b --- /dev/null +++ b/Schedule ICTIS/Main/Views/SheetCreateClassView.swift @@ -0,0 +1,89 @@ +// +// SheetCreateClassView.swift +// Schedule ICTIS +// +// Created by G412 on 12.12.2024. +// + +import SwiftUI + +struct SheetCreateClassView: View { + @Binding var isShowingSheet: Bool + @State private var isEditingClass: Bool = false + @State private var isEditingAuditory: Bool = false + @State private var isEditingProfessor: Bool = false + @State private var textForNameOfClass = "" + @State private var textForNameOfAuditory = "" + @State private var textForNameOfProfessor = "" + + + var body: some View { + NavigationView { + VStack { + FieldView(isEditing: $isEditingClass, text: $textForNameOfClass, nameOfImage: "book", labelForField: "Предмет") + .padding(.bottom, 10) + FieldView(isEditing: $isEditingAuditory, text: $textForNameOfAuditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория") + .padding(.bottom, 10) + FieldView(isEditing: $isEditingProfessor, text: $textForNameOfProfessor, nameOfImage: "book", labelForField: "Преподаватель") + Spacer() + } + .padding() + .background(Color("background")) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + Button("Отменить") { + isShowingSheet = false + } + } + ToolbarItem(placement: .navigationBarTrailing) { + Button("Сохранить") { + isShowingSheet = false + } + } + } + } + .background(Color("background")) // Фон для всего sheet + } +} + +#Preview { + SheetCreateClassView(isShowingSheet: .constant(true)) +} + +struct FieldView: View { + @Binding var isEditing: Bool + @Binding var text: String + var nameOfImage: String + var labelForField: String + var body: some View { + HStack(spacing: 0) { + Image(systemName: nameOfImage) + .foregroundColor(Color.gray) + .padding(.leading, 12) + .padding(.trailing, 7) + TextField(labelForField, text: $text) + .disableAutocorrection(true) + .onTapGesture { + self.isEditing = true + } + .submitLabel(.search) + if isEditing { + Button { + self.text = "" + self.isEditing = false + UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) + } label: { + Image(systemName: "xmark.circle.fill") + .padding(.trailing, 20) + .offset(x: 10) + .foregroundColor(.gray) + } + } + } + .frame(height: 40) + .background( + RoundedRectangle(cornerRadius: 10) + .fill(.white) + ) + } +}