diff --git a/README.md b/README.md index 9a26dca..e91b5b1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ then add the latest ComposeCalendar version to your `app/build.gradle` file depe ```groovy dependencies { - implementation 'com.squaredem:composecalendar:1.0.3' + implementation 'com.squaredem:composecalendar:1.0.4' } ``` diff --git a/build.gradle b/build.gradle index b9704cc..2e8cae6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { compose_version = '1.3.0-alpha01' material3_version = '1.0.0-alpha14' corektx_version = '1.8.0' - accompanist_version = '0.23.1' + accompanist_version = '0.25.1' } } diff --git a/composecalendar/build.gradle b/composecalendar/build.gradle index c487de6..e490743 100644 --- a/composecalendar/build.gradle +++ b/composecalendar/build.gradle @@ -75,7 +75,7 @@ dependencies { ext { PUBLISH_GROUP_ID = 'com.squaredem' PUBLISH_ARTIFACT_ID = 'composecalendar' - PUBLISH_VERSION = '1.0.3' + PUBLISH_VERSION = '1.0.4' } apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" diff --git a/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarContent.kt b/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarContent.kt index 45515af..afffcd2 100644 --- a/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarContent.kt +++ b/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarContent.kt @@ -16,7 +16,6 @@ package com.squaredem.composecalendar.composable -import android.util.Log import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -86,7 +85,7 @@ internal fun CalendarContent( if (!LocalInspectionMode.current) { LaunchedEffect(pagerState) { - snapshotFlow { pagerState.targetPage }.collect { page -> + snapshotFlow { pagerState.currentPage }.collect { page -> val currentDate = getDateFromCurrentPage(page, dateRange) currentPagerDate.value = currentDate } @@ -105,7 +104,8 @@ internal fun CalendarContent( onNextMonth = { coroutineScope.launch { try { - pagerState.animateScrollToPage(pagerState.currentPage + 1) + val newPage = pagerState.currentPage + 1 + pagerState.animateScrollToPage(newPage) } catch (e: Exception) { // avoid IndexOutOfBounds and animation crashes } @@ -114,7 +114,8 @@ internal fun CalendarContent( onPreviousMonth = { coroutineScope.launch { try { - pagerState.animateScrollToPage(pagerState.currentPage - 1) + val newPage = pagerState.currentPage - 1 + pagerState.animateScrollToPage(newPage) } catch (e: Exception) { // avoid IndexOutOfBounds and animation crashes } @@ -129,12 +130,8 @@ internal fun CalendarContent( ) { DayOfWeek.values().forEach { Text( - modifier = Modifier - .weight(1f), - text = it.getDisplayName( - TextStyle.NARROW, - Locale.getDefault() - ), + modifier = Modifier.weight(1f), + text = it.getDisplayName(TextStyle.NARROW, Locale.getDefault()), textAlign = TextAlign.Center, fontWeight = FontWeight.SemiBold ) @@ -146,7 +143,6 @@ internal fun CalendarContent( state = pagerState ) { page -> val currentDate = getDateFromCurrentPage(page, dateRange) - currentDate?.let { // grid CalendarGrid( @@ -193,7 +189,9 @@ private fun getStartPage( if (startDate >= dateRange.endInclusive) { return pageCount } - val indexOfRange = dateRange.indexOf(startDate.withDayOfMonth(1)) + val indexOfRange = dateRange.indexOfFirst { + it.year == startDate.year && it.monthValue == startDate.monthValue + } return if (indexOfRange != -1) indexOfRange else pageCount / 2 } diff --git a/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarMonthYearSelector.kt b/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarMonthYearSelector.kt index 0c61971..e894a4f 100644 --- a/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarMonthYearSelector.kt +++ b/composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarMonthYearSelector.kt @@ -31,10 +31,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import com.google.accompanist.pager.ExperimentalPagerApi -import com.google.accompanist.pager.PagerState import com.squaredem.composecalendar.utils.LogCompositions -import kotlinx.coroutines.CoroutineScope import java.text.SimpleDateFormat import java.time.LocalDate import java.time.OffsetTime @@ -46,7 +43,7 @@ internal fun CalendarMonthYearSelector( pagerDate: LocalDate, onChipClicked: () -> Unit, onNextMonth: () -> Unit, - onPreviousMonth: () -> Unit + onPreviousMonth: () -> Unit, ) { LogCompositions("CalendarMonthYearSelector")