From 137cf68f2787ff94c8cf08ac92864e470dedeb7f Mon Sep 17 00:00:00 2001 From: Kizito Nwose Date: Sat, 4 Nov 2023 08:32:04 +0100 Subject: [PATCH] Support compose 1.6.0 --- .../kizitonwose/calendar/buildsrc/Dependencies.kt | 2 +- .../calendar/compose/CalendarDefaults.kt | 12 +++++++----- docs/Compose.md | 13 +++++++------ gradle.properties | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt b/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt index 6901f89f..afc5b30b 100644 --- a/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt +++ b/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt @@ -64,7 +64,7 @@ object Libs { } object Compose { - private const val composeVersion = "1.5.2" + private const val composeVersion = "1.6.0-alpha08" const val ui = "androidx.compose.ui:ui:$composeVersion" const val foundation = "androidx.compose.foundation:foundation:$composeVersion" const val tooling = "androidx.compose.ui:ui-tooling:$composeVersion" diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarDefaults.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarDefaults.kt index df380a56..3856d891 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarDefaults.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarDefaults.kt @@ -4,14 +4,13 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.gestures.FlingBehavior import androidx.compose.foundation.gestures.ScrollableDefaults import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider +import androidx.compose.foundation.gestures.snapping.SnapPositionInLayout import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.remember -import androidx.compose.ui.unit.Density internal object CalendarDefaults { - /** * The default implementation in [rememberSnapFlingBehavior] snaps to the center of the layout * but we want to snap to the start. For example, in a vertical calendar, when the layout size @@ -23,7 +22,7 @@ internal object CalendarDefaults { @Composable private fun pagedFlingBehavior(state: LazyListState): FlingBehavior { val snappingLayout = remember(state) { - val provider = SnapLayoutInfoProvider(state) { _, _, _ -> 0 } + val provider = SnapLayoutInfoProvider(state, CalendarSnapPositionInLayout()) CalendarSnapLayoutInfoProvider(provider) } return rememberSnapFlingBehavior(snappingLayout) @@ -43,10 +42,13 @@ internal object CalendarDefaults { private fun CalendarSnapLayoutInfoProvider( snapLayoutInfoProvider: SnapLayoutInfoProvider, ): SnapLayoutInfoProvider = object : SnapLayoutInfoProvider by snapLayoutInfoProvider { - /** * In compose 1.3, the default was single page snapping (zero), but this changed * in compose 1.4 to decayed page snapping which is not great for calendar usage. */ - override fun Density.calculateApproachOffset(initialVelocity: Float): Float = 0f + override fun calculateApproachOffset(initialVelocity: Float): Float = 0f } + +@OptIn(ExperimentalFoundationApi::class) +@Suppress("FunctionName") +private fun CalendarSnapPositionInLayout() = SnapPositionInLayout { _, _, _, _, _ -> 0 } diff --git a/docs/Compose.md b/docs/Compose.md index eabbd825..8310306a 100644 --- a/docs/Compose.md +++ b/docs/Compose.md @@ -35,12 +35,13 @@ Add the library to your project [here](https://github.com/kizitonwose/Calendar#s Ensure that you are using the library version that matches with the Compose UI version in your project. If you use a version of the library that has a higher version of Compose UI than the one in your project, gradle will upgrade the Compose UI version in your project via transitive dependency. -|Compose UI|Calendar Library| -| :-: | :-: | -| 1.2.x | 2.0.x | -| 1.3.x | 2.1.x - 2.2.x | -| 1.4.x | 2.3.x | -| 1.5.x | 2.4.x | +| Compose UI | Calendar Library | +|:----------:|:----------------:| +| 1.2.x | 2.0.x | +| 1.3.x | 2.1.x - 2.2.x | +| 1.4.x | 2.3.x | +| 1.5.x | 2.4.x | +| 1.6.x | 2.5.x | ## Calendar Composables diff --git a/gradle.properties b/gradle.properties index 81d29bc4..848b8517 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ SONATYPE_HOST=S01 RELEASE_SIGNING_ENABLED=true GROUP=com.kizitonwose.calendar -VERSION_NAME=2.4.1-SNAPSHOT +VERSION_NAME=2.5.0-alpha01 POM_NAME=Calendar