diff --git a/CalendarExampleView/CalendarExampleView/ContentView.swift b/CalendarExampleView/CalendarExampleView/ContentView.swift index fca855d..a92e84b 100644 --- a/CalendarExampleView/CalendarExampleView/ContentView.swift +++ b/CalendarExampleView/CalendarExampleView/ContentView.swift @@ -29,13 +29,29 @@ struct ContentView: View { case .year(let yearDisplayMode): switch yearDisplayMode { case .compact: - return .system(size: 10, weight: .regular) + return .system(size: 8, weight: .regular) case .full: return .footnote.weight(.semibold) } } } + var heightCellCalendar: CGFloat { + switch viewMode { + case .month, + .week, + .single: + return 30.0 + case .year(let yearDisplayMode): + switch yearDisplayMode { + case .compact: + return 20.0 + case .full: + return 30.0 + } + } + } + var body: some View { VStack { ScrollView { @@ -51,7 +67,7 @@ struct ContentView: View { ) } .frameInfinity() - .frame(height: 30) + .frame(height: heightCellCalendar) .background(listSelectedDate.contains(date) ? .cyan : .clear) }, headerView: { date in HStack { @@ -73,7 +89,7 @@ struct ContentView: View { ) } .frameInfinity() - .frame(height: 30) + .frame(height: heightCellCalendar) .background(listSelectedDate.contains(date) ? .cyan : .clear) } ) @@ -81,7 +97,6 @@ struct ContentView: View { .enableDateOut(isShowDateOut) .firstWeekDay(firstWeekDate) .calendarLocate(locale: Locales.vietnamese.toLocale()) - .enablePinedView([.sectionHeaders, .sectionFooters]) .setViewMode(viewMode) .rowsSpacing(8) .columnSpacing(8) diff --git a/Sources/CalendarView/CalendarView.swift b/Sources/CalendarView/CalendarView.swift index 705d62c..a33ff41 100644 --- a/Sources/CalendarView/CalendarView.swift +++ b/Sources/CalendarView/CalendarView.swift @@ -160,6 +160,7 @@ public struct CalendarView< .highPriorityGesture(swipeGesture) .marginDefault() .background(backgroundCalendar) + .animation(calendarOptions.swapAnimation, value: calendarOptions.viewMode) } } @@ -186,17 +187,22 @@ extension CalendarView { switch calendarOptions.viewMode { case .month: monthContentView() + .transition(calendarOptions.swapRight) case .year(let displayMode): switch displayMode { case .compact: yearContentCompactView() + .transition(calendarOptions.swapRight) case .full: yearContentView() + .transition(calendarOptions.swapLeft) } case .week: calendarWeekView() + .transition(calendarOptions.swapLeft) case .single: singleDayContentView() + .transition(calendarOptions.swapLeft) } } @@ -212,14 +218,7 @@ extension CalendarView { Section( header: LazyVStack(alignment: .leading) { - HStack { - Spacer() - Text(month.monthName(.defaultStandalone) + " \(month.year)") - .font(.footnote) - .fontWeight(.bold) - Spacer() - } - .allowVisibleWith(calendarOptions.isShowHeader) + monthTitle(for: month) Divider() .allowVisibleWith(calendarOptions.isShowDivider) .padding(.bottom, 4) @@ -247,20 +246,17 @@ extension CalendarView { fileprivate func yearContentCompactView() -> some View { ForEach(yearData.keys.sorted(), id: \.self) { month in LazyVStack(alignment: .leading, spacing: .zero) { - HStack { - Text(month.monthName(.short)) - .font(.system(size: 10)) - .fontWeight(.regular) - Spacer() - } - .allowVisibleWith(calendarOptions.isShowHeader) + monthTitle(for: month) Divider() .allowVisibleWith(calendarOptions.isShowDivider) .padding(.bottom, 2) - LazyVGrid(columns: Array( + LazyVGrid( + columns: Array( repeating: GridItem(.flexible(), spacing: 0, alignment: .top), count: CalendarDefine.kWeekDays - ), alignment: .leading, spacing: .zero + ), + alignment: .leading, + spacing: .zero ) { ForEach( yearData[month, default: []], @@ -290,9 +286,13 @@ extension CalendarView { fileprivate func monthTitle(for month: Date) -> some View { HStack { Spacer() - Text(month.monthName(.defaultStandalone) + " \(month.year)") - .font(.footnote) - .fontWeight(.bold) + Text( + month.toFormat( + "MMM", + locale: calendarOptions.calendar.locale + ) + .uppercased() + ).font(fontTitle) Spacer() } .allowVisibleWith(calendarOptions.isShowHeader) diff --git a/Sources/CalendarView/Common/CalendarViewOption.swift b/Sources/CalendarView/Common/CalendarViewOption.swift index 20a6ad2..5f3892c 100644 --- a/Sources/CalendarView/Common/CalendarViewOption.swift +++ b/Sources/CalendarView/Common/CalendarViewOption.swift @@ -6,6 +6,8 @@ // import Foundation +import SwiftDate +import SwiftUI /// A struct that represents the options for a calendar view. public struct CalendarViewOption { @@ -18,6 +20,17 @@ public struct CalendarViewOption { public var spacingBetweenDay: CGFloat public var viewMode: CalendarViewMode public var spaceBetweenColumns: CGFloat + public var compactMonthCount = 3 + public var locateForCalendar: Locale + public let swapAnimation: Animation = .easeInOut(duration: 0.3) + public let swapRight = AnyTransition.asymmetric( + insertion: .scale(scale: 1.5, anchor: .center), + removal: .opacity + ) + public let swapLeft = AnyTransition.asymmetric( + insertion: .scale(scale: 1.5, anchor: .center), + removal: .opacity + ) /// Initializes a new instance of `CalendarViewOption` with default values. init() { @@ -30,12 +43,13 @@ public struct CalendarViewOption { self.spacingBetweenDay = 8.0 self.viewMode = .year(.full) self.spaceBetweenColumns = 8.0 + self.locateForCalendar = Locale.vietnam.toLocale() } } -public extension CalendarViewOption { +extension CalendarViewOption { /// The default `CalendarViewOption` instance. - static var defaultOption: CalendarViewOption { + public static var defaultOption: CalendarViewOption { var options = CalendarViewOption() options.backgroundStatus = .hidden options.calendar = .gregorian @@ -46,6 +60,8 @@ public extension CalendarViewOption { options.spacingBetweenDay = 8.0 options.viewMode = .year(.full) options.isShowDivider = true + options.compactMonthCount = 3 + options.locateForCalendar = Locale.vietnam.toLocale() return options } } diff --git a/Sources/CalendarView/Components/CalendarView+MakeData.swift b/Sources/CalendarView/Components/CalendarView+MakeData.swift index 22cde9a..3d42d2f 100644 --- a/Sources/CalendarView/Components/CalendarView+MakeData.swift +++ b/Sources/CalendarView/Components/CalendarView+MakeData.swift @@ -74,18 +74,18 @@ extension CalendarView { switch mode { case .compact: return Array( - repeating: GridItem(.flexible(), alignment: .top), - count: 2 + repeating: GridItem(.flexible(), spacing: calendarOptions.spaceBetweenColumns, alignment: .top), + count: calendarOptions.compactMonthCount ) case .full: return Array( - repeating: GridItem(.flexible(), spacing: calendarOptions.spaceBetweenColumns), + repeating: GridItem(.flexible(), spacing: calendarOptions.spaceBetweenColumns, alignment: .top), count: CalendarDefine.kWeekDays ) } default: return Array( - repeating: GridItem(.flexible(), spacing: calendarOptions.spaceBetweenColumns), + repeating: GridItem(.flexible(), spacing: calendarOptions.spaceBetweenColumns, alignment: .top), count: CalendarDefine.kWeekDays ) } @@ -122,4 +122,16 @@ extension CalendarView { return [date] } } + + var fontTitle: Font { + switch calendarOptions.viewMode { + case .month, + .single, + .year(.full): + return .footnote.bold() + case .year(.compact): + return .system(size: 10, weight: .semibold) + default: return .footnote.bold() + } + } } diff --git a/Sources/CalendarView/Components/CalendarViewMode.swift b/Sources/CalendarView/Components/CalendarViewMode.swift index c4a7937..d3978e9 100644 --- a/Sources/CalendarView/Components/CalendarViewMode.swift +++ b/Sources/CalendarView/Components/CalendarViewMode.swift @@ -12,7 +12,13 @@ import SwiftDate /// Represents the different modes of the calendar view. public enum CalendarViewMode: CaseIterable, Hashable { public static var allCases: [CalendarViewMode] { - [CalendarViewMode.year(.full), CalendarViewMode.year(.compact), CalendarViewMode.month, CalendarViewMode.single] + [ + CalendarViewMode.year(.full), + CalendarViewMode.year(.compact), + CalendarViewMode.month, + CalendarViewMode.week, + CalendarViewMode.single + ] } case month diff --git a/SwiftUICalendarView.podspec b/SwiftUICalendarView.podspec index 4eb3f17..1af99c7 100644 --- a/SwiftUICalendarView.podspec +++ b/SwiftUICalendarView.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| SwiftUICalendarView is a free and open-source library in SwiftUI to make calendar. DESC - s.version = '1.4.10' + s.version = '1.4.11' s.platform = :ios s.ios.deployment_target = '16.0' # Updated deployment target to a valid iOS version s.swift_version = '5.9'