This commit is contained in:
Vladimir Dubovik 2024-11-15 18:36:51 +03:00
parent b65b061d95
commit 3670a0b01f
10 changed files with 279 additions and 35 deletions

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xD9",
"green" : "0xD9",
"red" : "0xD9"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xD9",
"green" : "0xD9",
"red" : "0xD9"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7D",
"green" : "0x7D",
"red" : "0x7D"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7D",
"green" : "0x7D",
"red" : "0x7D"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7D",
"green" : "0x7D",
"red" : "0x7D"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7D",
"green" : "0x7D",
"red" : "0x7D"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7A",
"green" : "0x7A",
"red" : "0x7A"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x7A",
"green" : "0x7A",
"red" : "0x7A"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -19,7 +19,7 @@ struct ContentView: View {
case .settings: case .settings:
Text("Settings") Text("Settings")
} }
CustomTabBarView(selectedTab: $selectedTab) TabBarView(selectedTab: $selectedTab)
} }
.background(.secondary.opacity(0.15)) .background(.secondary.opacity(0.15))
} }

View File

@ -10,12 +10,28 @@ import SwiftUI
extension Date { extension Date {
func format(_ format: String, locale: Locale = Locale(identifier: "ru_RU")) -> String { func format(_ format: String, locale: Locale = Locale(identifier: "ru_RU")) -> String {
let formatter = DateFormatter() let formatter = DateFormatter()
formatter.dateFormat = format formatter.dateFormat = format
formatter.locale = locale formatter.locale = locale
return formatter.string(from: self) let formattedString = formatter.string(from: self)
if format == "EEEE" {
return formattedString.prefix(1).capitalized + formattedString.dropFirst()
}
return formattedString
}
var isToday: Bool {
return Calendar.current.isDateInToday(self)
} }
private func isSameDate(_ date1: Date?, _ date2: Date?) -> Bool {
guard let date1 = date1, let date2 = date2 else { return false }
let calendar = Calendar.current
return calendar.isDate(date1, inSameDayAs: date2)
}
func fetchWeek(_ date: Date = .init()) -> [WeekDay] { func fetchWeek(_ date: Date = .init()) -> [WeekDay] {
let calendar = Calendar.current let calendar = Calendar.current
let startOfDate = calendar.startOfDay(for: date) let startOfDate = calendar.startOfDay(for: date)
@ -36,6 +52,24 @@ extension Date {
return week return week
} }
func createNextWeek() -> [WeekDay] {
let calendar = Calendar.current
let startOfLastDate = calendar.startOfDay(for: self)
guard let nextDate = calendar.date(byAdding: .day, value: 1, to: startOfLastDate) else {
return []
}
return fetchWeek(nextDate)
}
func createPrevioustWeek() -> [WeekDay] {
let calendar = Calendar.current
let startOfFirstDate = calendar.startOfDay(for: self)
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: startOfFirstDate) else {
return []
}
return fetchWeek(previousDate)
}
struct WeekDay: Identifiable { struct WeekDay: Identifiable {
var id: UUID = .init() var id: UUID = .init()
var date: Date var date: Date

View File

@ -0,0 +1,14 @@
//
// View+Extensions.swift
// Schedule ICTIS
//
// Created by G412 on 15.11.2024.
//
import SwiftUI
extension View {
func isSameDate(_ date1: Date, _ date2: Date) -> Bool {
return Calendar.current.isDate(date1, inSameDayAs: date2)
}
}

View File

@ -11,7 +11,7 @@ struct ScheduleView: View {
@State private var searchText: String = "" @State private var searchText: String = ""
@State private var currentDate: Date = .init() @State private var currentDate: Date = .init()
@State private var weekSlider: [[Date.WeekDay]] = [] @State private var weekSlider: [[Date.WeekDay]] = []
@State private var currentWeekIndex: Int = 0 @State private var currentWeekIndex: Int = 1
var body: some View { var body: some View {
VStack { VStack {
SearchBarView(text: $searchText) SearchBarView(text: $searchText)
@ -22,7 +22,16 @@ struct ScheduleView: View {
.onAppear(perform: { .onAppear(perform: {
if weekSlider.isEmpty { if weekSlider.isEmpty {
let currentWeek = Date().fetchWeek() let currentWeek = Date().fetchWeek()
if let firstDate = currentWeek.first?.date {
weekSlider.append(firstDate.createPrevioustWeek())
}
weekSlider.append(currentWeek) weekSlider.append(currentWeek)
if let lastDate = currentWeek.last?.date {
weekSlider.append(lastDate.createNextWeek())
}
} }
}) })
@ -31,15 +40,28 @@ struct ScheduleView: View {
@ViewBuilder @ViewBuilder
func HeaderView() -> some View { func HeaderView() -> some View {
VStack (alignment: .leading, spacing: 6) { VStack (alignment: .leading, spacing: 6) {
HStack (spacing: 5) { HStack {
Text(currentDate.format("YYYY")) VStack (alignment: .leading, spacing: 0) {
.foregroundStyle(.blue) Text(currentDate.format("EEEE"))
Text(currentDate.format("MMMM")) .font(.system(size: 40, weight: .semibold))
.foregroundStyle(.blue) .foregroundStyle(.black)
// .background(Color.green)
HStack (spacing: 5) {
Text(currentDate.format("dd"))
.font(.system(size: 20, weight: .bold))
.foregroundStyle(Color("grayForDate"))
Text(currentDate.format("MMMM"))
.font(.system(size: 20, weight: .bold))
.foregroundStyle(Color("grayForDate"))
}
// .background(.red)
}
.padding(.top, 8)
.padding(.leading, 20)
// .background(Color.brown)
Spacer()
} }
.font(.title.bold()) .frame(maxWidth: .infinity)
// Text(currentDate.formatted(date: .complete, time: .omitted))
// .font(.title.bold())
TabView(selection: $currentWeekIndex) { TabView(selection: $currentWeekIndex) {
ForEach(weekSlider.indices, id: \.self) { index in ForEach(weekSlider.indices, id: \.self) { index in
@ -55,24 +77,46 @@ struct ScheduleView: View {
@ViewBuilder @ViewBuilder
func WeekView(_ week: [Date.WeekDay]) -> some View { func WeekView(_ week: [Date.WeekDay]) -> some View {
HStack (spacing: 14) { HStack (spacing: 10) {
ForEach(week) { day in ForEach(week) { day in
VStack (spacing: 4) { VStack (spacing: 1) {
Text(day.date.format("E")) Text(day.date.format("E"))
.font(.callout) .font(.system(size: 15, weight: .semibold))
.fontWeight(.medium) .foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, currentDate) ? Color("customGray1") : Color("customGray3"))
.textScale(.secondary) .padding(.top, 13)
.padding(.top, 6)
.foregroundColor(.gray) .foregroundColor(.gray)
Text(day.date.format("dd")) Text(day.date.format("dd"))
.font(.callout) .font(.system(size: 15, weight: .bold))
.fontWeight(.bold) .foregroundStyle(isSameDate(day.date, currentDate) ? .white : .black)
.textScale(.secondary) .padding(.bottom, 13)
.padding(.bottom, 6) }
.frame(width: 43, height: 55, alignment: .center)
.background( content: {
Group {
if isSameDate(day.date, currentDate) {
Color("blueColor")
}
else {
Color(.white)
}
if day.date.isToday && isSameDate(day.date, currentDate) {
Color("blueColor")
}
}
}
)
.overlay (
Group {
if day.date.isToday && !isSameDate(day.date, currentDate) {
RoundedRectangle(cornerRadius: 15)
.stroke(Color("blueColor"), lineWidth: 2)
}
}
)
.cornerRadius(15)
.onTapGesture {
currentDate = day.date
} }
.frame(maxWidth: 40, maxHeight: 55, alignment: .center)
.background(Color.white)
.cornerRadius(10)
} }
} }
} }

View File

@ -10,7 +10,7 @@ struct SearchBarView: View {
Image(systemName: "magnifyingglass") Image(systemName: "magnifyingglass")
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
.padding(.leading, 10) .padding(.leading, 10)
TextField("Ввести номер группы", text: $text) TextField("Поиск группы", text: $text)
.disableAutocorrection(true) .disableAutocorrection(true)
.frame(width: 270, height: 45) .frame(width: 270, height: 45)
.overlay( .overlay(
@ -22,7 +22,7 @@ struct SearchBarView: View {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
} label: { } label: {
Image(systemName: "xmark.circle.fill") Image(systemName: "xmark.circle.fill")
.padding(.trailing, 30) .padding(.trailing, 20)
.offset(x: 10) .offset(x: 10)
.foregroundColor(.gray) .foregroundColor(.gray)
} }
@ -46,7 +46,7 @@ struct SearchBarView: View {
} label: { } label: {
ZStack { ZStack {
Rectangle() Rectangle()
.frame(width: 35, height: 35) .frame(width: 40, height: 40)
.foregroundStyle(Color("blueColor")) .foregroundStyle(Color("blueColor"))
.cornerRadius(10) .cornerRadius(10)
Image(systemName: "plus") Image(systemName: "plus")

View File

@ -7,7 +7,7 @@
import SwiftUI import SwiftUI
struct CustomTabBarView: View { struct TabBarView: View {
var isActiveForeground: Color = .white var isActiveForeground: Color = .white
var isActiveBackground: Color = Color("blueColor") var isActiveBackground: Color = Color("blueColor")
@Binding var selectedTab: TabModel @Binding var selectedTab: TabModel
@ -20,7 +20,7 @@ struct CustomTabBarView: View {
} }
.animation(.smooth(duration: 0.3, extraBounce: 0), value: selectedTab) .animation(.smooth(duration: 0.3, extraBounce: 0), value: selectedTab)
.padding(6) .padding(6)
.background(.clear) .background(.white)
.mask(RoundedRectangle(cornerRadius: 24, style: .continuous)) .mask(RoundedRectangle(cornerRadius: 24, style: .continuous))
// .background( // .background(
@ -41,12 +41,12 @@ struct CustomTabBarView: View {
VStack { VStack {
Image(systemName: tab.rawValue) Image(systemName: tab.rawValue)
.font(.title) .font(.title)
.frame(width: 80, height: 35) .frame(width: 70, height: 30)
} }
.foregroundStyle(selectedTab == tab ? isActiveForeground : Color("blueColor")) .foregroundStyle(selectedTab == tab ? isActiveForeground : Color("blueColor"))
.padding(.vertical, 7) .padding(.vertical, 7)
.padding(.leading, 15) .padding(.leading, 13)
.padding(.trailing, 15) .padding(.trailing, 13)
.background { .background {
if selectedTab == tab { if selectedTab == tab {
Capsule() Capsule()