boguszpawlowski / ComposeCalendar

A Jetpack Compose library for handling calendar component rendering.
Apache License 2.0
330 stars 40 forks source link

Inconsistent padding/height #63

Open CmdrSharp opened 2 years ago

CmdrSharp commented 2 years ago

Hi! Thanks for a great composable :)

I've found that the padding seems a tad inconsistent. Below are three screenshots. The text at the bottom is positioned the same across all three, but note how the calendar has padding on some months, and none on others. From my testing, it seems that some months in each year (different for different years) get padded.

See the screenshots, where you can notice this clearly on the month April.

The following months have padding added in 2022

In 2023 the following months have padding:

And in 2024, the following:

..And so on. I find no good reason for this behaviour when looking through the source.

Here's an example to reproduce:

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import io.github.boguszpawlowski.composecalendar.SelectableCalendar
import io.github.boguszpawlowski.composecalendar.rememberSelectableCalendarState
import java.time.DayOfWeek

@Composable
fun SplashScreen(navController: NavController) {
    val state = rememberSelectableCalendarState()

    Column {
        SelectableCalendar(
            calendarState = state,
            showAdjacentMonths = true,
            firstDayOfWeek = DayOfWeek.MONDAY,
        )

        Text(text = "Test")
    }
}

image image image

CmdrSharp commented 2 years ago

Some further debugging: This only occurs with horizontalSwipeEnabled set to true.

boguszpawlowski commented 2 years ago

Hi @CmdrSharp Thank you for submitting the issue. Unfortunately, the bug is caused by Horizontal Pager, which calculates its height eagerly, thus setting it to a height of a month with 5 rows. So right now I don't think its fixable from my side, but I will check if its an expected behaviour of the pager over the weekend.

CmdrSharp commented 2 years ago

I understand. A possible workaround is mentioned here: https://github.com/google/accompanist/issues/1050

CmdrSharp commented 2 years ago

Another interesting note @boguszpawlowski: Note how June and April have the same amount of row, yet one has padding, and one does not.

boguszpawlowski commented 2 years ago

@CmdrSharp Thanks for the workaround! I will see if it's fixing the problem in this case.

boguszpawlowski commented 2 years ago

@CmdrSharp Sorry for a late reply, I was able to try the workaround, but the results were pretty laggy and inconsistent. So, until a better workaround comes, or this will be fixed from the Accompanist side, I will leave mark this issue as blocked.