diff --git a/KisaniCal/Views/CalendarView.swift b/KisaniCal/Views/CalendarView.swift index b9d58c1..bf80844 100644 --- a/KisaniCal/Views/CalendarView.swift +++ b/KisaniCal/Views/CalendarView.swift @@ -673,41 +673,44 @@ struct CalendarView: View { // MARK: - Year - private var yearView: some View { - let year = cal.component(.year, from: displayMonth) - let months: [Date] = (1...12).compactMap { cal.date(from: DateComponents(year: year, month: $0, day: 1)) } - return VStack(spacing: 0) { - // Year header with navigation (unbounded — go as far forward/back as you like). - HStack { - Button { navigateYear(-1) } label: { - Image(systemName: "chevron.left").font(.system(size: 14, weight: .semibold)) - .foregroundColor(AppColors.text(cs)).frame(width: 40, height: 40) - } - Spacer() - Text(String(year)) - .font(AppFonts.sans(20, weight: .bold)).foregroundColor(AppColors.text(cs)) - Spacer() - Button { navigateYear(1) } label: { - Image(systemName: "chevron.right").font(.system(size: 14, weight: .semibold)) - .foregroundColor(AppColors.text(cs)).frame(width: 40, height: 40) - } - } - .padding(.horizontal, 16).padding(.top, 4) + // Continuous, TickTick-style: years flow one after another in an infinite + // scroll. Opens anchored on the current year; scroll up for past years, + // down for future ones — no paging, no dead space below December. + private var yearRange: [Int] { + let now = cal.component(.year, from: Date()) + return Array((now - 8)...(now + 20)) + } + private var yearView: some View { + let currentYear = cal.component(.year, from: Date()) + return ScrollViewReader { proxy in ScrollView(showsIndicators: false) { - LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], spacing: 24) { - ForEach(months, id: \.self) { m in - cvMiniMonth(m) + LazyVStack(alignment: .leading, spacing: 28) { + ForEach(yearRange, id: \.self) { yr in + yearBlock(yr).id(yr) } } - .padding(16) + .padding(.top, 8) + .padding(.bottom, 96) // clear the floating tab bar / + button } + .onAppear { proxy.scrollTo(currentYear, anchor: .top) } } } - private func navigateYear(_ offset: Int) { - withAnimation(KisaniSpring.snappy) { - displayMonth = cal.date(byAdding: .year, value: offset, to: displayMonth) ?? displayMonth + private func yearBlock(_ year: Int) -> some View { + let months: [Date] = (1...12).compactMap { cal.date(from: DateComponents(year: year, month: $0, day: 1)) } + let isCurrent = year == cal.component(.year, from: Date()) + return VStack(alignment: .leading, spacing: 14) { + Text(String(year)) + .font(AppFonts.sans(26, weight: .bold)) + .foregroundColor(isCurrent ? AppColors.accent : AppColors.text(cs)) + .padding(.horizontal, 16) + LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], spacing: 24) { + ForEach(months, id: \.self) { m in + cvMiniMonth(m) + } + } + .padding(.horizontal, 16) } }