Skip to content

Commit

Permalink
DON-1089: Fix scroll issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Yura Reutskiy committed Feb 3, 2025
1 parent 85bf902 commit feed267
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Backpack-SwiftUI/Calendar/Classes/Core/CalendarMonthGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct CalendarMonthGrid<

LazyVGrid(
columns: Array(repeating: GridItem(spacing: BPKSpacing.none.value), count: daysInAWeek),
spacing: BPKSpacing.lg.value
spacing: BPKSpacing.md.value
) {
// Create cells for the days from the previous month that are shown in the first week of the current month.
previousEmptyCells(daysFromPreviousMonth: daysFromPreviousMonth)
Expand All @@ -72,8 +72,11 @@ struct CalendarMonthGrid<
ForEach(preEmptyCells) { _ in
VStack(spacing: emptyCellSpacing) {
emptyLeadingDayCell()
.frame(height: dayCellHeight)
Spacer(minLength: BPKSpacing.none)
.frame(height: accessoryViewHeight)
}
.frame(height: dayCellHeight)
.frame(height: totalCellHeight)
}
}

Expand All @@ -87,20 +90,28 @@ struct CalendarMonthGrid<
ForEach(remainingEmptyCells) { _ in
VStack(spacing: emptyCellSpacing) {
emptyTrailingDayCell()
.frame(height: dayCellHeight)
Spacer(minLength: BPKSpacing.none)
.frame(height: accessoryViewHeight)
}
.frame(height: dayCellHeight)
.frame(height: totalCellHeight)
}
}
}

var emptyCellSpacing: BPKSpacing {
if accessoryViewHeight == nil {
return .none
} else {
if let accessoryViewHeight, accessoryViewHeight > 0 {
return .sm
} else {
return .none
}
}

var totalCellHeight: CGFloat? {
guard let dayCellHeight, let accessoryViewHeight else { return nil }
return dayCellHeight + accessoryViewHeight + BPKSpacing.sm.value
}

private struct DayCellIdentifiable: Identifiable {
let id: String
let index: Int
Expand All @@ -127,17 +138,14 @@ struct CalendarMonthGrid<
} else {
VStack(spacing: BPKSpacing.sm) {
dayCell(dayDate)
}
.modifier(ReadSizeModifier {
dayCellHeight = max($0.height, dayCellHeight ?? 0)
})
.frame(height: dayCellHeight)
.overlay {
.modifier(ReadSizeModifier {
dayCellHeight = max($0.height, dayCellHeight ?? 0)
})
.frame(height: dayCellHeight)
dayAccessoryView(dayDate)
.modifier(ReadSizeModifier {
accessoryViewHeight = max($0.height, accessoryViewHeight ?? 0)
})
.offset(y: (accessoryViewHeight ?? 0)*2 - BPKSpacing.md.value)
}
}
}
Expand Down

0 comments on commit feed267

Please sign in to comment.