Commit
This commit is contained in:
@ -22,15 +22,11 @@ struct MainView: View {
|
||||
isFocusedSearchBar = false
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.isFirstStartOffApp && vm.isLoading) {
|
||||
CurrentDateView()
|
||||
if vm.isLoading {
|
||||
LoadingView(isLoading: $vm.isLoading)
|
||||
}
|
||||
else if (vm.isFirstStartOffApp) {
|
||||
FirstLaunchScheduleView()
|
||||
}
|
||||
else {
|
||||
CurrentDateView()
|
||||
ScheduleView(vm: vm, isScrolling: $isScrolling)
|
||||
}
|
||||
}
|
||||
@ -43,6 +39,12 @@ struct MainView: View {
|
||||
.onTapGesture {
|
||||
isFocusedSearchBar = false
|
||||
}
|
||||
.onAppear {
|
||||
vm.group = UserDefaults.standard.string(forKey: "group") ?? "notSeted"
|
||||
if vm.group != "notSeted" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
@ -11,6 +11,8 @@ struct ScheduleView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@FetchRequest(fetchRequest: ClassModel.all()) private var classes //Делаем запрос в CoreData и получаем список сохраненных пар
|
||||
@State private var selectedClass: ClassModel? = nil
|
||||
@State private var lastOffset: CGFloat = 0
|
||||
@State private var scrollTimer: Timer? = nil
|
||||
@Binding var isScrolling: Bool
|
||||
var provider = ClassProvider.shared
|
||||
var body: some View {
|
||||
@ -73,17 +75,28 @@ struct ScheduleView: View {
|
||||
.frame(width: UIScreen.main.bounds.width)
|
||||
.padding(.bottom, 100)
|
||||
.padding(.top, 30)
|
||||
.background(GeometryReader { geometry in
|
||||
Color.clear.preference(key: ViewOffsetKey.self, value: geometry.frame(in: .global).minY)
|
||||
})
|
||||
}
|
||||
.onPreferenceChange(ViewOffsetKey.self) { offset in
|
||||
if offset > 0 {
|
||||
if offset != lastOffset {
|
||||
// Скролл происходит
|
||||
isScrolling = true
|
||||
print("Сейчас скролл")
|
||||
} else {
|
||||
isScrolling = false
|
||||
print("Scrolling ended")
|
||||
|
||||
// Останавливаем предыдущий таймер
|
||||
scrollTimer?.invalidate()
|
||||
// Запускаем новый таймер
|
||||
scrollTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in
|
||||
// Скролл остановился
|
||||
isScrolling = false
|
||||
}
|
||||
}
|
||||
lastOffset = offset
|
||||
}
|
||||
.onDisappear {
|
||||
scrollTimer?.invalidate()
|
||||
}
|
||||
.coordinateSpace(name: "scroll")
|
||||
VStack {
|
||||
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom)
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ struct SearchBarView: View {
|
||||
Button {
|
||||
self.text = ""
|
||||
self.isFocused = false
|
||||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.padding(.trailing, 20)
|
||||
|
@ -1,64 +0,0 @@
|
||||
//
|
||||
// CustomTabBarView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by Egor Mironov on 13.11.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct TabBarView: View {
|
||||
@Binding var selectedTab: TabBarModel
|
||||
// @NameSpace private var animation
|
||||
var body: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
HStack(spacing: 15) {
|
||||
content
|
||||
}
|
||||
.animation(.smooth(duration: 0.3, extraBounce: 0), value: selectedTab)
|
||||
.padding(6)
|
||||
.background(.white)
|
||||
.mask(RoundedRectangle(cornerRadius: 24, style: .continuous))
|
||||
.shadow(color: .black.opacity(0.2), radius: 8, x: 4, y: 4)
|
||||
|
||||
// .background(
|
||||
// background
|
||||
// .shadow(.drop(color: .black.opacity(0.08), radius: 5, x: 5, y: 5))
|
||||
// .shadow(.drop(color: .black.opacity(0.08), radius: 5, x: 5, y: -5)),
|
||||
// in: .capsule
|
||||
// )
|
||||
}
|
||||
.ignoresSafeArea(.keyboard, edges: .bottom) // Фиксаци таб-бара, при появлении клавиатуры
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
ForEach(TabBarModel.allCases, id: \.rawValue) { tab in
|
||||
Button {
|
||||
selectedTab = tab
|
||||
} label: {
|
||||
VStack (alignment: .center) {
|
||||
Image(systemName: tab.rawValue)
|
||||
.font(.title3)
|
||||
}
|
||||
.frame(width: 70, height: 28)
|
||||
.foregroundStyle(selectedTab == tab ? Color.white : Color("blueColor"))
|
||||
.padding(.vertical, 7)
|
||||
.padding(.leading, 13)
|
||||
.padding(.trailing, 13)
|
||||
.background {
|
||||
if selectedTab == tab {
|
||||
Capsule()
|
||||
.fill(Color("blueColor"))
|
||||
// .matchedGeometryEffect(id: "ACTIVETAB", in: animation)
|
||||
}
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ContentView()
|
||||
}
|
@ -8,8 +8,8 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MonthTabView: View {
|
||||
@State private var currentMonthIndex: Int = 1
|
||||
@State private var monthSlider: [[Date.MonthWeek]] = []
|
||||
@State var currentMonthIndex: Int = 1
|
||||
@State var monthSlider: [[Date.MonthWeek]] = []
|
||||
@State private var createMonth: Bool = false
|
||||
@State private var currentWeekIndex: Int = 0
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@ -79,53 +79,8 @@ struct MonthTabView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func paginateMonth(_ indexOfWeek: Int = 0) {
|
||||
let calendar = Calendar.current
|
||||
if monthSlider.indices.contains(currentMonthIndex) {
|
||||
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||
currentMonthIndex == 0 {
|
||||
monthSlider.insert(firstDate.createPreviousMonth(), at: 0)
|
||||
monthSlider.removeLast()
|
||||
currentMonthIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week -= 5
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
|
||||
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||
currentMonthIndex == (monthSlider.count - 1) {
|
||||
monthSlider.append(lastDate.createNextMonth())
|
||||
monthSlider.removeFirst()
|
||||
currentMonthIndex = monthSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week += 5
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MonthTabView {
|
||||
func updateMonthScreenViewForNewGroup() {
|
||||
vm.updateSelectedDayIndex()
|
||||
if monthSlider.isEmpty {
|
||||
let currentMonth = Date().fetchMonth(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentMonth.first?.week[0].date {
|
||||
monthSlider.append(firstDate.createPreviousMonth())
|
||||
}
|
||||
|
||||
monthSlider.append(currentMonth)
|
||||
|
||||
if let lastDate = currentMonth.last?.week[6].date {
|
||||
monthSlider.append(lastDate.createNextMonth())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ContentView()
|
||||
|
@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct WeekTabView: View {
|
||||
@State private var currentWeekIndex: Int = 1
|
||||
@State private var weekSlider: [[Date.WeekDay]] = []
|
||||
@State var weekSlider: [[Date.WeekDay]] = []
|
||||
@State private var createWeek: Bool = false
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var body: some View {
|
||||
@ -45,25 +45,6 @@ struct WeekTabView: View {
|
||||
}
|
||||
}
|
||||
|
||||
extension WeekTabView {
|
||||
func updateWeekScreenViewForNewGroup() {
|
||||
vm.updateSelectedDayIndex()
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentWeek.first?.date {
|
||||
weekSlider.append(firstDate.createPrevioustWeek())
|
||||
}
|
||||
|
||||
weekSlider.append(currentWeek)
|
||||
|
||||
if let lastDate = currentWeek.last?.date {
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ContentView()
|
||||
}
|
||||
|
@ -29,42 +29,4 @@ struct WeekViewForMonth: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func getForegroundColor(day: Date.WeekDay) -> Color {
|
||||
if isDateInCurrentMonth(day.date) {
|
||||
return isSameDate(day.date, vm.selectedDay) ? .white : .black
|
||||
} else {
|
||||
return isSameDate(day.date, vm.selectedDay) ? .white : Color("greyForDaysInMonthTabView")
|
||||
}
|
||||
}
|
||||
|
||||
private func getBackgroundColor(day: Date.WeekDay) -> Color {
|
||||
return isSameDate(day.date, vm.selectedDay) ? Color("blueColor") : Color("background")
|
||||
}
|
||||
|
||||
private func overlay(day: Date.WeekDay) -> some View {
|
||||
Group {
|
||||
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||
RoundedRectangle(cornerRadius: 100)
|
||||
.stroke(Color("blueColor"), lineWidth: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleTap(day: Date.WeekDay) {
|
||||
if isSameWeek(day.date, vm.selectedDay) {
|
||||
print("На одной неделе")
|
||||
}
|
||||
else {
|
||||
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
||||
if day.date < vm.selectedDay {
|
||||
difBetweenWeeks = difBetweenWeeks * -1
|
||||
}
|
||||
print(difBetweenWeeks)
|
||||
vm.week += difBetweenWeeks
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
vm.selectedDay = day.date
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
}
|
||||
|
@ -73,30 +73,4 @@ struct WeekViewForWeek: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
func paginateWeek() {
|
||||
let calendar = Calendar.current
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.week -= 1
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.week += 1
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user