Skip to content

Commit

Permalink
Support compose 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Nov 4, 2023
1 parent 3e01171 commit 137cf68
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 }
13 changes: 7 additions & 6 deletions docs/Compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 137cf68

Please sign in to comment.