Skip to content

Commit

Permalink
Fixes from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cara Hurtle committed Feb 3, 2021
1 parent f99cce5 commit 9001181
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.kizitonwose.calendarview.CalendarView
import com.kizitonwose.calendarview.model.*
import com.kizitonwose.calendarview.utils.NO_INDEX
import com.kizitonwose.calendarview.utils.getVerticalMargins
import com.kizitonwose.calendarview.utils.inflate
import com.kizitonwose.calendarview.utils.orZero
import java.time.LocalDate
Expand Down Expand Up @@ -217,13 +218,13 @@ internal class CalendarAdapter(
val visibleVH =
calView.findViewHolderForAdapterPosition(visibleItemPos) as? MonthViewHolder ?: return
val newHeight = visibleVH.headerView?.height.orZero() +
visibleVH.headerView?.getMarginHeight().orZero() +
visibleVH.headerView?.getVerticalMargins().orZero() +
// visibleVH.bodyLayout.height` won't not give us the right height as it differs
// depending on row count in the month. So we calculate the appropriate height
// by checking the number of visible(non-empty) rows.
visibleMonth.weekDays.size * calView.daySize.height +
visibleVH.footerView?.height.orZero() +
visibleVH.footerView?.getMarginHeight().orZero()
visibleVH.footerView?.getVerticalMargins().orZero()
if (calView.height != newHeight) {
ValueAnimator.ofInt(calView.height, newHeight).apply {
// Don't animate when the view is shown initially.
Expand Down Expand Up @@ -283,11 +284,6 @@ internal class CalendarAdapter(

fun findLastVisibleDay(): CalendarDay? = findVisibleDay(false)

private fun View.getMarginHeight(): Int {
val marginParams = layoutParams as? ViewGroup.MarginLayoutParams
return marginParams?.topMargin.orZero() + marginParams?.bottomMargin.orZero()
}

private fun findFirstVisibleMonthPosition(): Int = findVisibleMonthPosition(true)

private fun findLastVisibleMonthPosition(): Int = findVisibleMonthPosition(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ internal val Rect.namedString: String

internal val CoroutineScope.job: Job
get() = requireNotNull(coroutineContext[Job])

internal fun View.getVerticalMargins(): Int {
val marginParams = layoutParams as? ViewGroup.MarginLayoutParams
return marginParams?.topMargin.orZero() + marginParams?.bottomMargin.orZero()
}

0 comments on commit 9001181

Please sign in to comment.