Skip to content

Commit

Permalink
Fix calendar measuring logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Oct 11, 2020
1 parent e510955 commit 8d21d76
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ open class CalendarView : RecyclerView {
private var firstDayOfWeek: DayOfWeek? = null

private var autoSize = true
private var autoSizeHeight = DAY_SIZE_SQUARE
private var sizedInternally = false

internal val isVertical: Boolean
Expand Down Expand Up @@ -290,12 +291,8 @@ open class CalendarView : RecyclerView {
// +0.5 => round to the nearest pixel
val size = (((widthSize - (monthPaddingStart + monthPaddingEnd)) / 7f) + 0.5).toInt()

val computedSize = when {
daySize == SIZE_SQUARE -> daySize.copy(width = size, height = size)
daySize.width == DAY_SIZE_SQUARE -> daySize.copy(width = size)
else -> daySize
}

val height = if (autoSizeHeight == DAY_SIZE_SQUARE) size else autoSizeHeight
val computedSize = daySize.copy(width = size, height = height)
if (daySize != computedSize) {
sizedInternally = true
daySize = computedSize
Expand Down Expand Up @@ -356,6 +353,7 @@ open class CalendarView : RecyclerView {
field = value
if (!sizedInternally) {
autoSize = value == SIZE_SQUARE || value.width == DAY_SIZE_SQUARE
autoSizeHeight = value.height
invalidateViewHolders()
}
}
Expand Down

0 comments on commit 8d21d76

Please sign in to comment.