diff --git a/CalendarExampleView/CalendarExampleView/ContentView.swift b/CalendarExampleView/CalendarExampleView/ContentView.swift index dd17ca3..224a454 100644 --- a/CalendarExampleView/CalendarExampleView/ContentView.swift +++ b/CalendarExampleView/CalendarExampleView/ContentView.swift @@ -21,76 +21,82 @@ struct ContentView: View { @State var isHightLightToDay = true var body: some View { VStack { - CalendarView( - date: selectedDate - , dateView: { date in - VStack { - Text(date.dayName) - .font(.footnote) - .fontWeight(.semibold) - .foregroundColor( - Calendar.current.isDateInWeekend(date) ? .red : .black - ) - } - .frameInfinity() - .frame(height: 30) - .background(listSelectedDate.contains(date) ? .cyan : .clear) - }, headerView: { date in - HStack { - ForEach(date, id: \.self) { - Text($0.weekDayShortName.uppercased()) - .font(.footnote) - .fontWeight(.bold) - .foregroundColor( - Calendar.current.isDateInWeekend($0) ? .red : .black - ) - .frame(maxWidth: .infinity) + ScrollView { + VStack { + CalendarView( + date: selectedDate + , dateView: { date in + VStack { + Text(date.dayName) + .font(.footnote) + .fontWeight(.semibold) + .foregroundColor( + Calendar.current.isDateInWeekend(date) ? .red : .black + ) + } + .frameInfinity() + .frame(height: 30) + .background(listSelectedDate.contains(date) ? .cyan : .clear) + }, headerView: { date in + HStack { + ForEach(date, id: \.self) { + Text($0.weekDayShortName.uppercased()) + .font(.footnote) + .fontWeight(.bold) + .foregroundColor( + Calendar.current.isDateInWeekend($0) ? .red : .black + ) + .frame(maxWidth: .infinity) + } + } + }, dateOutView: { date in + VStack { + Text(date.dayName) + .font(.footnote) + .fontWeight(.semibold) + .foregroundColor( + Calendar.current.isDateInWeekend(date) ? .red.opacity(0.4) : .gray + ) + } + .frameInfinity() + .frame(height: 30) + .background(listSelectedDate.contains(date) ? .cyan : .clear) + } + ) + .enableHeader(isShowHeader) + .enableDateOut(isShowDateOut) + .firstWeekDay(firstWeekDate) + .calendarLocate(locale: Locales.vietnamese.toLocale()) + .enablePinedView([.sectionHeaders, .sectionFooters]) + .setViewMode(viewMode) + .rowsSpacing(8) + .columnSpacing(8) + .background(.visible(12, .gray.opacity(0.1))) + .onDraggingEnded { direction, viewMode in + if direction == .forward { + withAnimation(.easeInOut) { + selectedDate = selectedDate.dateAt( + viewMode == .month ? .nextMonth : .nextWeek + ).date + } + } else { + withAnimation(.easeInOut) { + selectedDate = selectedDate.dateAt( + viewMode == .month ? .prevMonth : .prevWeek + ).date + } } } - }, dateOutView: { date in - VStack { - Text(date.dayName) - .font(.footnote) - .fontWeight(.semibold) - .foregroundColor( - Calendar.current.isDateInWeekend(date) ? .red.opacity(0.4) : .gray - ) - } - .frameInfinity() - .frame(height: 30) - .background(listSelectedDate.contains(date) ? .cyan : .clear) - } - ) - .enableHeader(isShowHeader) - .enableDateOut(isShowDateOut) - .firstWeekDay(firstWeekDate) - .calendarLocate(locale: Locales.vietnamese.toLocale()) - .enablePinedView([.sectionHeaders, .sectionFooters]) - .setViewMode(viewMode) - .rowsSpacing(8) - .columnSpacing(8) - .background(.visible(12, .gray.opacity(0.1))) - .onDraggingEnded { direction, viewMode in - if direction == .forward { - withAnimation(.easeInOut) { - selectedDate = selectedDate.dateAt( - viewMode == .month ? .nextMonth : .nextWeek - ).date - } - } else { - withAnimation(.easeInOut) { - selectedDate = selectedDate.dateAt( - viewMode == .month ? .prevMonth : .prevWeek - ).date - } + .onSelectDate(onSelectedDate) + .enableDivider(isShowDivider) + .enableHighlightToDay(isHightLightToDay) + .marginDefault() + .allowsTightening(true) + Spacer() + } + .frame(maxWidth: .infinity) } - .onSelectDate(onSelectedDate) - .enableDivider(isShowDivider) - .enableHighlightToDay(isHightLightToDay) - .marginDefault() - .allowsTightening(true) - Spacer() VStack { listButtonDemo .padding() @@ -103,9 +109,7 @@ struct ContentView: View { .frame(width: 300) .padding() } - } - .frame(maxWidth: .infinity) } var listButtonDemo: some View { diff --git a/Sources/CalendarView/CalendarView.swift b/Sources/CalendarView/CalendarView.swift index ad273db..925273d 100644 --- a/Sources/CalendarView/CalendarView.swift +++ b/Sources/CalendarView/CalendarView.swift @@ -150,21 +150,16 @@ public struct CalendarView< // MARK: - Main Body View public var body: some View { - ScrollView { - LazyVGrid( - columns: columnGridLayout, - spacing: calendarOptions.spacingBetweenDay, - pinnedViews: pinedHeaderView - ) { - bodyContentView - } - .marginDefault() - .background(backgroundCalendar) - .simultaneousGesture(swipeGesture) + LazyVGrid( + columns: columnGridLayout, + spacing: calendarOptions.spacingBetweenDay, + pinnedViews: pinedHeaderView + ) { + bodyContentView } - .scrollIndicators(calendarOptions.viewMode.enableScrollIndicator) - .scrollDisabled(calendarOptions.viewMode.isDisableScroll) - .frameInfinity() + .highPriorityGesture(swipeGesture) + .marginDefault() + .background(backgroundCalendar) } } @@ -211,7 +206,7 @@ extension CalendarView { ForEach(yearData.keys.sorted(), id: \.self) { month in Section( header: - LazyVStack(alignment: .center) { + LazyVStack(alignment: .leading) { HStack { Spacer() Text(month.monthName(.defaultStandalone) + " \(month.year)")